一、getId() 方法
getId() 方法的作用是取得线程的唯一标识。
@Test
public void testGetId() {
Thread currentThread = Thread.currentThread();
System.out.println("当前线程为[" + currentThread.getName() + "], id:[" + currentThread.getId() + "]");
GetIdThread getIdThread = new GetIdThread();
getIdThread.setName("getIdThread");
getIdThread.start();
}
执行结果:
当前线程为[main], id:[1]
当前线程为[getIdThread], id:[12]