• Post Reply Bookmark Topic Watch Topic
  • New Topic

How Get Inactive Threads of a ThreadGroup?

 
Robert Paris
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ThreadGroup has a way to get all active threads of that thread group (enumerate). I can also get a list of the names of all active AND inactive threads (list). Does anyone know how I can actually get a reference to the inactive threads?
With enumerate, I can get actual references to the thread objects:
<ThreadGroup>.enumerate(Thread[] list, boolean recurse);
And I know the ThreadGroup has a reference to the inactive threads as well, because list will show the inactive threads too:
<ThreadGroup>.list();
Thanks!
 
Robert Paris
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anyone? I can't find the answer anywhere, but really need to be able to do this! help!
 
Robert Paris
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, here's how you do it:

A couple things:
1. You need to set the field accessible even without a security manager
2. If you have security on, you'll need the runtime permission "suppressAccessChecks" even though I know most people run with no security or "AllPermission".
3. That check for null is important! I believe it keeps more room than it needs, so it doesn't have to expand all the time, so you don't want to hit a null pointer.
Have fun!
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great! Now I think that I will move this to the Threads forum .
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!