Java – Get unique identifier of a Thread in Java 1.4

javamultithreadinguniqueidentifier

In Java 1.4, is there any better way of getting a Thread's ID than using Thread.getName()?

I mean, getName() in unit tests returns something like "Thread-1", but in WebLogic 10 I get "[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)'.xml".

Best Solution

Thread.getId (it can theoretically overflow, but it is defined not to and in practice will not).

1.5 is going through its End of Service Life period now, but if you are using old dusty-decks 1.4, then you can implement your own with ThreadLocal. (Note, don't follow the Java SE 6 API docs too closely!)