dcsimg
How to stop a thread by synchronized an!_NEWLINE_!object in a other threads?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Michele_Bottaro
Posted On:   Tuesday, October 23, 2001 06:06 AM

Hallo, I want to use a thread: 'timeControlThread' to stop at specific date an other thread (NB I don't want to kill the thread so it can restart). I have used an object timer that at specific date call the task: class DelayTaskStop extends TimerTask{ public void run(){ synchronized (stop){ while(true){ try{ stop.wait(); } catch(InterruptedException e){ e.printStackTrace(); } } } timerStop.cancel(); } } Why this code don't stop the other thread: if (timeControlThread!=null){ synchronized (timeControlThread.stop){} } Looks like that the wait()take no effects.    More>>

Hallo,
I want to use a thread: 'timeControlThread' to stop at specific date an other thread (NB I don't want to kill the thread so it can restart). I have used an object timer that at specific date call the task:

			
class DelayTaskStop extends TimerTask{
public void run(){
synchronized (stop){
while(true){
try{
stop.wait();
}
catch(InterruptedException e){
e.printStackTrace();
}
}
}
timerStop.cancel();
}
}

Why this code don't stop the other thread:
			
if (timeControlThread!=null){
synchronized (timeControlThread.stop){}
}


Looks like that the wait()take no effects.
Thanks.
Michele    <<Less

Re: How to stop a thread by synchronized an!_NEWLINE_!object in a other threads?

Posted By:   Michael_Lueders  
Posted On:   Tuesday, October 30, 2001 09:58 AM

synchronizing only acquires the monitor; you still need to notify the waiting thread to wake. try the following code...

if (timeControlThread!=null){
synchronized (timeControlThread.stop){
timeControlThread.stop.notify();
}
}
About | Sitemap | Contact