Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Stopped threads?

 
Ashish Chopra
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a scenario where my application has ~12000 threads that are being displayed as stopped in my profiler. However, the memory usage figures shown are very high, and they go on increasing as more threads go in stopped state.

My question is, when a thread goes into stopped state, does it release all resources held by it, or does it hold on to them?

If it holds on, is there a way to free these resources?

Thanks in advance
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would the resources be freed? The thread is still alive, and could be woken up at any time. The better question is: Why is there a need to keep 12000 of them around even if though there're stopped? Maybe there's a way that allows the threads to be discarded when they're not used.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the many threads have finished executing, then the JVM should release the associated Thread objects. If the threads are suspended (naughty), in wait(), waiting for a monitor or something like that, but still alive, then they cannot be released, because they might come back to life at any time.

The Thread objects won't be released if something in your code is holding a reference to them. Perhaps you're storing them all in a collection, or something like that.
 
Ashish Chopra
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, actually all these threads are transient threads that are created for notification purposes in the application.

Also, the profiler is displaying all these threads as stopped, not waiting.

Is it possible for me to free the resources that are held up in these stopped threads?
[ March 29, 2006: Message edited by: Ashish Chopra ]
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try reading the previous responses.
 
Ashish Chopra
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter, as I said, these threads are not in waiting state, they are clearly shown as being in stopped state.

And in case the Garbage collector would have reclaimed memory & resources from these threads, they wouldn't be in stopped state, but killed already.

This is why I ask, is there a way I can force removal of these stopped threads?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you holding a reference to the Thread objects in a collection or something? If it's stopped it should be eligible for GC unless other code does something to prevent it.
 
Ashish Chopra
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, these threads are transient threads that are launched, they perform some functionality, and then exit. I am not maintaining any collection where these references are stored.

And I am using the runnable interface based implementation of threads...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic