Waiting for a condition
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Thursday, March 6, 2003 02:48 AM

I have a servlet that starts a thread, and I want that this servlet waits for a condition that the thread has to change.

SERVLET

Thread t1 = new Thread1();
t1.start();
//wait until available = true and then continue


THREAD1 extends Thread
private boolean available = false;
public Thread1(){
}

public void run(){
//...
available = true; //notify to servlet that can continue
//...
}



How can I do this?

Thanks for all.

Re: Waiting for a condition

Posted By:   Hermann_RANGAMANA  
Posted On:   Monday, March 10, 2003 01:47 AM

You can use an object as a basis for your synchronization. In thread 1 (the one that waits until available is true), just at the beginning of its method run, add myObject.wait () (my object an simple instance of object). Then when you change the value of available to true, wake up the first thread by calling myObject.notify() ....

/hermann
About | Sitemap | Contact