线程名称-您何时需要知道它们? [英] Thread names--when do you need to know them?

查看:93
本文介绍了线程名称-您何时需要知道它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不久前,我创建了一个有关线程命名约定的问题.问题是,您应该如何命名线程?"

I created a SO question about naming conventions for threads a while ago. The question was something like, "How should you name a thread?"

回顾一下,只有在必须读取线程名称的情况下,线程名称才重要.

Looking back, a thread name only matters if you have to read a thread's name.

您能否提供实际示例,说明何时必须检查线程并依靠它们的名称来识别它们之间的区别?这与平台/框架无关.

Can you provide real-world examples of when you've had to examine threads and discern between them, relying on their names? This is platform/framework agnostic.

如何(在什么环境中)执行此操作?

How (in what environment), did you do this?

以另一种方式,您在什么情况下必须解决问题并必须按名称检查线程 ,您是如何做到的?

Put another way, in what scenarios have you had to solve a problem and had to examine threads by name, and how did you accomplish this?

推荐答案

在Java中寻找连接泄漏时,有时追溯对象以查看其创建于哪个线程是有用的.在我们的例子中,它是终结器线程.这导致我们得出的结论是,事物正在被垃圾收集,但是没有足够快地完成.即一堆东西正在等待定稿,这些工作都在一个线程中完成.

When looking for connection leaks in java, it is sometimes useful to trace an object back to see which thread it was created by. In our case, it was the Finalizer thread. This led us to the conclusion that things were getting garbage collected, but not being Finalized fast enough. i.e. a bunch of stuff was waiting to be finalized, which was all done in one thread.

结果,我们吸取了关于不依赖于Finalize的教训.

As a result, we learnt a lesson about not relying on Finalize.

这篇关于线程名称-您何时需要知道它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆