简体   繁体   中英

Java ThreadPoolExecutor stops working after a while

I have a problem with the ThreadPoolExecutor. It works fine for hours, but sometimes (at a random time, sometimes after 2 minutes or 3 hours) it stops executing the submitted tasks and the program hangs.

The queue is full and all corethreads are active at this time.

I simply don't know where this is coming from. Especially because it sometimes works for 3 hours while all corethreads are working all the time.

If there is anybody who has a suggestion for me, I would be very happy.

Take a look at the stack dump. This will tell you if the threads are in some blocking operation, waiting for a condition that never happens, working, or truly deadlocked.

I had a similar problem with a code that do I/O operations downloading web pages. At some point, sometimes, in minutes or hours, a thread hangs doing some I/O operation and stop to work.

If this is your case, set an abortion time.

Run your code in a debugger and when your application stop, see what were the last methods that your threads executed.

You could have a memory leak somewhere and that is causing the lock after a few hours

It might be related to http://bugs.sun.com/view_bug.do?bug_id=6822370 if you were using an older version of the JVM. This was fixed in 6u18. See http://www.oracle.com/technetwork/java/javase/6u18-142093.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM