java – Thread. Getid() global uniqueness problem

If multiple Java applications are running on the system, each thread ID is unique relative to all other Java threads, no matter what application they are running?

Java applications should be sandboxed relative to other Java applications, so I think thread IDs may conflict

If the thread ID is unique in all applications, will the information of other applications on the system not be leaked (although very small)? For example, how many threads are started in other applications, or even other Java applications running?

Solution

Well, let me have a look

In the init method of thread (called by each constructor):

/* Set thread ID */
tid = nextThreadID();

In nextthreadid():

private static synchronized long nextThreadID() {
    return ++threadSeqNumber;
}

And:

/* For generating thread ID */
private static long threadSeqNumber;

It will never be set, so it defaults to 0

So obviously, the thread ID number always starts at 0 and increments by 1 In other words, the answer to your question is that they are not globally unique

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>