Java 进程产生了数千个线程...为什么?

发布于 2024-10-30 20:26:34 字数 835 浏览 0 评论 0原文

最近,我的客户在运行 Java 进程时迁移到 Linux(64 位)时遇到了问题。

该进程正在生成数千个线程,其中大多数线程的标识符为 futex。我查了一下 futex(快速用户空间互斥体),它是一个用于实现基本锁定的 Linux 结构。

代码最近已更改为实现 BlockingQueue 和 ExecutorService 来生成子线程,但子线程的数量由配置设置控制,我可以证明这种特定机制并未失控。我只能假设 JVM 内部的某些东西由于 BlockingQueue 和一些锁而产生了所有这些线程?

那么谁能告诉我如何找出这些线程实际上是什么以及我可以做什么来控制/停止它们?

下面是进程列表的几行;进程被终止之前的实际列表超过 13000 行。

0 - 54321 447 446 1 - - - 5953085 - ? 00:15:50 java
0 S 54321 - - 0 82 2 - - futex_ - 00:00:00 -
1 S 54321 - - 0 82 2 - - futex_ - 00:00:00 -
1 S 54321 - - 0 82 2 - - futex_ - 00:00:00 -
1 S 54321 - - 0 82 2 - - futex_ - 00:00:00 -
1 S 54321 - - 0 82 2 - - futex_ - 00:00:00 -
1 S 54321 - - 0 82 2 - - futex_ - 00:00:00 -
1 S 54321 - - 0 82 2 - - futex_ - 00:00:00 -
1 S 54321 - - 0 82 2 - - futex_ - 00:00:00 -

感谢接受任何建议。

I have a problem with a recent customer migration to Linux (64-bit) when running a Java process.

The process is spawning thousands of threads most with an identifier of futex. I've looked up futex (fast userspace mutex) and it's a Linux construct to implement basic locking.

The code has recently changed to implement a BlockingQueue and an ExecutorService to spawn child threads but the number of child threads is controlled by a config setting and I can prove that this specific mechanism is not running out of control. I can only assume that something internal to the JVM is spawning all these threads due to the BlockingQueue and some lock?

So can anyone tell me how to find out what these threads actually are and what I might do to control/stop them?

Below is a few lines of the process list; the actual list before the process had to be killed was over 13000 lines long.

0 - 54321 447 446 1 - - - 5953085 - ? 00:15:50 java
0 S 54321 - - 0 82 2 - - futex_ - 00:00:00 -
1 S 54321 - - 0 82 2 - - futex_ - 00:00:00 -
1 S 54321 - - 0 82 2 - - futex_ - 00:00:00 -
1 S 54321 - - 0 82 2 - - futex_ - 00:00:00 -
1 S 54321 - - 0 82 2 - - futex_ - 00:00:00 -
1 S 54321 - - 0 82 2 - - futex_ - 00:00:00 -
1 S 54321 - - 0 82 2 - - futex_ - 00:00:00 -
1 S 54321 - - 0 82 2 - - futex_ - 00:00:00 -

Any suggestions gratefully accepted.

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

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

发布评论

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

评论(1

奢华的一滴泪 2024-11-06 20:26:34

如果无法在 IDE 的调试器中加载应用程序,您可能需要使用 VisualVM 加载应用程序以查看线程实际执行的操作:

http://download.oracle.com/javase/6/docs/technotes/guides/visualvm/threads.html

确保您可以终止该应用程序,因为它可能会因为线程数量过多而耗尽资源(即在 Linux 中,准备好 shell)。

If you cannot load the application in the debugger of an IDE, you might want to load the application with VisualVM to look at what the threads are actually doing:

http://download.oracle.com/javase/6/docs/technotes/guides/visualvm/threads.html

Make sure you can kill the app, as it might run out of resources because of the high number of threads (i.e. in linux, have a shell ready).

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