[concurrency-interest] Thread.getId()

Jerome Lacoste jerome@coffeebreaks.org
Mon, 26 Jan 2004 22:26:55 +0100

On Mon, 2004-01-26 at 21:30, Kasper Nielsen wrote:
> Hi,
> After having read the javadoc for Thread.getId()
> --------------------------
> public long getId()
> Returns the identifier of this Thread. The thread ID is a positive long 
> number generated when this thread was created. The thread ID is unique 
> and remains unchanged during its lifetime. When a thread is terminated, 
> this thread ID may be reused.
> --------------------------
> I think it should be prohibited for the jvm to reuse a thread id, I 
> simply can't see any reason why it should be allowed. If people are 
> using the id in anyway across of thread initialization/termination it 
> could potentially lead to confusion and/or errors.

This clause seems to exist in order to handle the potential theoretical exhaustion of IDs. 
Otherwise one would have to specify error handling and force the implementations to be more complex than they need to be, especially for problems that will never be reached in real life.
As a consequence this less strict specification is a price to pay in order to make the API clean, and clients should find a different way to refer to the threads than by uniquely using their ids.

Correct me if I am wrong...