When you are at public class A and you want to notify an event from a second public class B here is what you do:
1) Create an lock object at class B and a getter of the object
2) Situate a notify() on that specific lock at class B
3) Create a waitloop thread at class A with the content lock.wait(), so that the thread goes to sleep until notified from class B
1) private Object whateverLock = new Object(); // for common use
public Object getwhateverLock(){ // share the app lock
return whateverLock;
}
2) synchronized (getwhateverLock()){
getwhateverLock().notify(); // notify the wait thread at class A
}
3) class whateverThread extends Thread
Of course you have to create an object of class B (b) at class A and you have to create an object for the whateverThread (w) and start it w.start() at class ACode:public whateverThread () { // the constructor
}
public void run() {
System.out.println(" enter in whatever thread");
do { /
synchronized (b. getwhateverLock()){
try{
b.getwhateverLock().wait();
}
catch(InterruptedException e){
System.out.println(e);
}
}
}
}
}

