This week's book giveaway is in the Web Services forum.
We're giving away four copies of Microservices in Action and have Morgan Bruce & Paulo A. Pereira on-line!
See this thread for details.
Win a copy of Microservices in Action this week in the Web Services forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Need to stop a thread(possibly)  RSS feed

 
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!