Java Thread.getId()
Syntax
Thread.getId() has the following syntax.
public long getId()
Example
In the following code shows how to use Thread.getId() method.
class ThreadDemo implements Runnable {
public void run() {
// returns the identifier of this Thread.
System.out.println("Name = " + Thread.currentThread().getName());
System.out.print("Id = " + Thread.currentThread().getId());
}// www . j a v a 2 s . com
}
public class Main{
public static void main(String args[]) {
// thread created
Thread t = new Thread("java2s.com thread");
// set thread priority
t.setPriority(1);
// prints thread created
System.out.println("thread = " + t);
// this will call run() function
t.start();
}
}