Thread t1 = new Thread(); long id = t1.getId(); System.out.println("Thread ID: " + id );
Thread t1 = new Thread(); Thread t2 = new Thread(); Thread t3= new Thread(); System.out.println("Thread t1 ID: " + t1.getId()); System.out.println("Thread t2 ID: " + t2.getId()); System.out.println("Thread t3 ID: " + t3.getId());In the above example, we have created three threads and obtained the IDs for each using the getId() method. These IDs will be unique for each thread. Package Library: The Java Thread class is part of the Java.lang package, and so is the getId() method.