Java 线程创建跟踪
我有一个 Java 应用程序,重点关注并发性和可突发容量。这意味着它使用线程池来排队和执行事件。
所有这些线程池都是固定大小的,但当应用程序部署在 Linux (CentOS 5.5) 服务器上时,我经常发现自己遇到打开文件描述符限制。
据我所知,应用程序在负载下时不应同时创建超过 20 个线程,但我的 ulimit
为 1024。
有什么方法可以跟踪这些线程回到创建它们的代码/池?
I have a java app with a heavy focus on concurrency and on burstable capacity. This means it uses thread pools to queue and execute events.
All these thread pools are fixed-size, but I constantly find myself bumping up against open file descriptor limits when the app is deployed on the Linux (CentOS 5.5) server.
To my count, the app, when under load, shouldn't create more than 20 threads at any one time, but I'm hitting a ulimit
of 1024.
Is there any way I can track these threads back to the code/pool that created them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
健全的线程池应该(至少可选地)允许指定名称。
对于正常的
ThreadPoolExecutor
您需要实现ThreadFactory
适当地命名线程。然后使用setThreadFactory()
使其使用您的实现。您还可以使用 Guava
ThreadFactoryBuilder
并调用setNameFormat()
来预先构建该功能:A sane thread pool should (at least optionally) allow the name to be specified.
For the normal
ThreadPoolExecutor
you need to implement aThreadFactory
that names the threads appropriately. Then usesetThreadFactory()
to make it use your implementation.You can also use the Guava
ThreadFactoryBuilder
and callsetNameFormat()
to get that functionality pre-built: