Menu

Java Thread Synchronized

When we us java Thread,Sometimes we nedd concurrent visit some resources, in this way,we have to use synchronized.

today what we will talk about is wait and notify.

first have a look at this fragment.

public Class A {
public static void main(String[]args) {
ThreadB b = new ThreadB();
b.start();
synchronized(b) {
System.out.println("waiting......");
b.wait();
}
System.out.println("result:"+b.getResult());
}
}

------------------------ThreadB-------------------------
public Class ThreadB extends Thread {
public void run() {
synchronized(this) {
......
notify();
}
}
}

Posted by chanser 2012-06-12

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.