Win a copy of Spring Boot in Practice this week in the Spring 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Problem in stop the thread

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,
I am working on webappliction , i started one thread in one jsp bean class, when i started i get the thread name and save it in database .
The problem is ,when i wanted to stop that thread from some other page by getting this thread name from database.Because the thread is running and i wanted to stop that by the name.

My question is, Is there any way to get the reference of that theard that i started earlier by enter the name and then stop it.

Please help me ,if any body have solution for that.

Regard's
Jyotisree Dhar
 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can make use of Singleton design pattern to keep the references to these threads.

For example use a class ThreadController as the controller to keep track of references to these threads. Get the reference to a thread by

ThreadController.getInstance().getThread(String threadName)
 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jyotisree,
you shouldn't be trying to stop a thread anyway. All the stop() methods in the Thread class are deprecated now. This means the stop() methods should no longer be called, from any thread. Ever!
[
Stopping a thread could cause an indeterminate state in the resource guarded by your thread, because a stopped thread immediately releases all of its locks and this means another thread could jump in and grab the locks, and there is no repeatable way for you to tell in advance which thread grabs the lock. Leading to an indeterminate state for the resource.
]
Suggest you go away and think about your design. Each thread should be written to stop itself when a certain condition is met, and thus gracefully exit by ending the run() method. I admit, at first designing your threads like this will seem hard, but you'll get used to it.
Jeff Walker
 
reply
    Bookmark Topic Watch Topic
  • New Topic