我的 ThreadPoolExecutor 有问题。它可以正常工作几个小时,但有时(随机时间,有时在 2 分钟或 3 小时后)它会停止执行提交的任务并且程序挂起。
队列已满,此时所有核心线程都处于活动状态。
我根本不知道这是从哪里来的。特别是因为它有时会工作 3 个小时,而所有核心线程都一直在工作。
如果有人对我有建议,我会很高兴。
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.
发布评论
评论(4)
查看堆栈转储。这会告诉您是否线程处于某种阻塞操作中,等待永远不会发生的条件、工作或真正死锁。
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/O 操作的代码也遇到了类似的问题。有时,在几分钟或几小时内的某个时刻,线程会挂起执行某些 I/O 操作并停止工作。
如果是这种情况,请设定堕胎时间。
在调试器中运行代码,当应用程序停止时,查看线程最后执行的方法是什么。
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
它可能与 https://bugs.java.com/bugdatabase/view_bug?bug_id 有关=6822370(如果您使用的是旧版本的 JVM)。该问题已在 6u18 中修复。请参阅 http://www.oracle.com/technetwork/java/javase /6u18-142093.html
It might be related to https://bugs.java.com/bugdatabase/view_bug?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