aspose file tools
The moose likes Threads and Synchronization and the fly likes Need to stop a thread(possibly) Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Need to stop a thread(possibly)" Watch "Need to stop a thread(possibly)" New topic
Author

Need to stop a thread(possibly)

colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 712
Hi,

I have a javax.swing.Timer object, and also a method which I want it's execution to stop when the timer reaches 1 minute.

I thought about putting this method into a Thread, then stopping the thread inside the timers actionPerformed method from its ActionListener which used in the Timer constructor to create the Timer object.

But I can't just stop a thread with .stop() since that is deprecated,
perhaps Thread.destroy() will do the job, I will test it now in a little test program.

Is there any other way to stop execution of the method, without using while or if statements in the method.

Hope that makes sense.

Thanks
[ May 11, 2006: Message edited by: colin shuker ]
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
Not without using deprecated and dangerous methods like Thread.stop(). You don't really want to do what you're suggesting. A loop that checks for the condition on which it should stop is the appropriate idiom.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need to stop a thread(possibly)
 
Similar Threads
Stopping Thread
Timer keeps program from exiting
How to limit the execution time of a 3rd party method?
What is the Linux command to find the created timer daemon
Exam on monday please reply