The Artima Developer Community
Sponsored Link

Java Answers Forum
Stopping Threads

2 replies on 1 page. Most recent reply: Jan 15, 2003 2:59 PM by Anil Philip

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Abhaya Ramaswamy

Posts: 1
Nickname: bujji
Registered: Jan, 2003

Stopping Threads Posted: Jan 14, 2003 12:22 AM
Reply to this message Reply
Advertisement
Hi,
How to stop/suspend/ terminate a thread as stop,suspend & resume methods are deprecated.
Please let me know.

thanks
regards
Abhaya


Sarma K T R B

Posts: 5
Nickname: sarma2312
Registered: Jan, 2003

Re: Stopping Threads Posted: Jan 14, 2003 9:39 PM
Reply to this message Reply
hi,
There is no clear cut mechanism for stopping, resuming and suspending a Thread as these methods can leave your thread objects in an inconsistent state but below I am giving the link that has the code to stop, resume and suspend threads. Hope it will be useful to you.

Sarma

http://java.sun.com/j2se/1.3/docs/api/

Anil Philip

Posts: 19
Nickname: anilphilip
Registered: Nov, 2002

Re: Stopping Threads Posted: Jan 15, 2003 2:59 PM
Reply to this message Reply
terminate: in run(), simply 'break' out of the loop that you probably have when the condition is met, so that control flows out naturally.

suspend: examine a flag and do a wait()
synchronized(flag) {
while(suspended)
wait();
}

revive:
if(!suspended)
notifyAll();

of course, you should synchronize on a flag to communicate with the thread to make it "terminate" or suspend or revive.

Flat View: This topic has 2 replies on 1 page
Topic: What actually is meant by Java - enabled? Previous Topic   Next Topic Topic: javaCOMM API with WindowsXP

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use