简体   繁体   English

Java ThreadPoolExecutor 一段时间后停止工作

[英]Java ThreadPoolExecutor stops working after a while

I have a problem with the ThreadPoolExecutor.我的 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.它可以正常工作几个小时,但有时(在随机时间,有时在 2 分钟或 3 小时后)它会停止执行提交的任务并且程序挂起。

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.特别是因为它有时会工作 3 个小时,而所有核心线程一直在工作。

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.我在执行 I/O 操作下载 web 页面的代码时遇到了类似的问题。 At some point, sometimes, in minutes or hours, a thread hangs doing some I/O operation and stop to work.在某些时候,有时,在几分钟或几小时内,一个线程挂起执行一些 I/O 操作并停止工作。

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您可能在某处发生 memory 泄漏,这会在几个小时后导致锁定

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.如果您使用的是旧版本的 JVM,它可能与http://bugs.sun.com/view_bug.do?bug_id=6822370有关。 This was fixed in 6u18.这已在 6u18 中修复。 See http://www.oracle.com/technetwork/java/javase/6u18-142093.htmlhttp://www.oracle.com/technetwork/java/javase/6u18-142093.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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