Thread getId() method in Java

Method declaration – public Long getId().

This method returns long value as thread’s id.

Output is – 1

Every thread in java has a unique id. Even we define custom thread JVM allocates a thread id for that thread.

Output is –

Thread id is :- 8
Thread id is :- 9

 

 

Top