重命名Java中的线程 [英] Renaming Threads in Java

查看:238
本文介绍了重命名Java中的线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个项目上,这个项目正在变得越来越大,并且许多不同进程所使用的活动线程的数量正在增加.最近,我一直在仔细查看调试器中正在运行的线程,并且我注意到很多第三方库的线程名称都很差-Timer-0,qtp0等.我希望其他开发人员不熟悉用名称不佳的线程可以立即知道正在运行什么.

I am working on a project that is slowly getting larger and larger and the number of active threads used by many different processes is increasing. Lately, I have been taking a closer look at the running threads in the debugger and I have noticed that a lot of my third party libraries have given very poor names to their threads - Timer-0, qtp0, etc. I want other devs unfamiliar with the poorly named threads to know instantly what is running.

没有人为我们正在使用的库编写补丁程序,没有人知道如何重命名正在运行的线程吗?还是这是个好主意?任何建议,将不胜感激.

Rather than write patches for the libs we are using, does anyone know how to rename the running threads? Or if this is even a good idea? Any suggestions would be appreciated.

推荐答案

如果问题出在开放源代码库中,那么最好的解决方案是为这些产品提供补丁,以实现更好的线程命名.除非安全管理器正在运行,否则您可以通过枚举线程(如其他线程所述)并对每个线程应用任意名称来重命名任何线程,但这是一种命名不是您自己的线程的脆弱方法.如果第三方库更改了其命名,则必须更改代码.

If the problem is in open source libraries, then the best solution is to supply patches to those products for better thread naming. Barring a security manager running, you can rename any thread by enumerating threads (as others have mentioned) and applying an arbitrary name to each, but this is a fragile way of naming threads that are not your own. If the 3rd party library changes their naming, you'll have to change your code.

我同意,线程名称不佳的第三方库会使理解您的应用程序中发生的事情变得更加困难.但是从第三方库重命名线程是有风险的.如果他们的下一个版本改变了他们命名线程的方式,会发生什么?以及如何处理完全不命名线程的第3方库?

I agree that 3rd party libraries with poorly-named threads make more difficult understanding what is going on in your application. But renaming threads from a 3rd party library is risky. What happens if their next release changes the way they name threads? And how do you handle a 3rd party library that makes no attempt at all to name threads?

添加回以某种方式从结尾消失的文本

Add back text that somehow disappeared from the end

这篇关于重命名Java中的线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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