简体   繁体   English

如何在Java中唯一地标识线程?

[英]How to identify a thread uniquely in Java?

Is there any way, in Java, to identify uniquely a thread? 在Java中,有没有办法唯一地识别线程? Using only Thread.getCurrent().getId() isn't enough since a thread may die and the next one might get its ID. 仅使用Thread.getCurrent().getId()是不够的,因为线程可能会死并且下一个可能获得其ID。 For me, those aren't the same threads so I need a way to identify them. 对我来说,那些线程不一样,所以我需要一种方法来识别它们。

The thread creation time stamp would be useful, if I can get it. 如果我能得到它,线程创建时间戳将是有用的。

What's wrong with using == ? 使用==什么问题? Or if you need an actual number, System.identityHashCode is probably a safe bet. 或者,如果您需要实际数字, System.identityHashCode可能是一个安全的赌注。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM