Java ThreadPoolExecutor 一段时间后停止工作

发布于 2024-11-28 17:55:39 字数 198 浏览 2 评论 0 原文

我的 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

娇俏 2024-12-05 17:55:39

查看堆栈转储。这会告诉您是否线程处于某种阻塞操作中,等待永远不会发生的条件、工作或真正死锁。

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.

猥︴琐丶欲为 2024-12-05 17:55:39

我在下载网页时执行 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.

忆伤 2024-12-05 17:55:39

您可能在某处存在内存泄漏,这导致几个小时后锁定

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

泛泛之交 2024-12-05 17:55:39

它可能与 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文