public class Id {
public static void main(String[] args) {
Thread thread = new Thread();
System.out.println("主线程的ID —— " + Thread.currentThread().getId());
System.out.println("子线程的ID —— " + thread.getId());
}
}
主线程的ID —— 1
子线程的ID —— 13
/**
* Allocates a new {@code Thread} object. This constructor has the same
* effect as {@linkplain #Thread(ThreadGroup,Runnable,String) Thread}
* {@code (null, null, gname)}, where {@code gname} is a newly generated
* name. Automatically generated names are of the form
* {@code "Thread-"+}<i>n</i>, where <i>n</i> is an integer.
*/
public Thread() {
init(null, null, "Thread-" + nextThreadNum(), 0);
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |