• 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

ThreadPoolExecutor getting stuck

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm working on some application and using ThreadPoolExecutor for handling various tasks. ThreadPoolExecutor is getting stuck after some duration. To simulate this in a simpler environment, I've written a simple code where I'm able to simulate the issue.



Try executing this code a few times. It normally print outs the number on console and when all threads end, it exists. But at times, it finished all task and then is not getting terminated. The thread dump is as follows:


In my actual application,ThreadPoolExecutor threads go in this state and then it stops responding.

PS: I'm new to JavaRanch. Please let me know if I've not followed any rules.

Regards,
Ravi Rao
 
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you need to shutdown the pool sometime. Try adding this code at the end of your main method:

 
Ravi K Rao
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Peter,

First of all, Thank you for quick response.

This is not the actual program. It is just a simple code which I've written to simulate a similar condition in my actual code. I wont be able to post the actual code here.

The problem is once it gets into this condition, it keeps on waiting and after some point new tasks are not executed at all.

Regards,
Ravi Rao
 
Peter Taucher
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And does that change the need to shutdown the pool at some time? At least take look into the API docs (especially under 'Finalization').
 
Master Rancher
Posts: 4806
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Peter Taucher wrote:I think you need to shutdown the pool sometime. Try adding this code at the end of your main method:


That seems unnecessarily complex - shutdown() will already wait until all current tasks are completed, so I'd just call it directly.

The problem is, it sounds like Ravi wants to keep this pool around awhile to await future tasks, and sometimes all the threads get suspended somehow.

I can't seem to recreate the problem on my machine using the code shown. I'm running a Mac, so the different JVM internals may be why I can't recreate it.

When I do a thread dump, I get virtually the same results as Ravi - with the critical difference that all his threads say "(Suspended)", while mine do not. So the question is, what causes the threads to become suspended?

One thing to try is to run this in an IDE, and set a break point on the suspend() method in the Thread class. If something in the system is calling suspend(), this should let you know what it is.

Anyone else got any ideas on what might cause the threads to become suspended?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic