• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to suspend thread using thread's id?

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Code which I am trying



How can we suspend/pause thread based on its id
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Happy S Singh wrote:Code which I am trying



How can we suspend/pause thread based on its id



First, suspend() is a deprecated method. And it is deprecated because under really rare situations, it was possible to suspend a thread that is owning one of the JVMs internal locks. This will effectively "break" the JVM.

But to answer your question.... You will need to have a collection of Thread objects to search through -- just enumerate through the list to find it. If your application didn't maintain the list, then one option would be to .... (1) start with the current thread, (2) get the thread group and check all the threads own by that thread group, (3) thread groups also own thread groups, so you can also (3a) move up to the parent threadgroup of the current threadgroup and repeat and/or (3b) enumerate the threadgroups own by current threadgroup and repeat (recursively).

Henry
 
You don't like waffles? Well, do you like this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic