public class Main {
public static void main(String[] args) throws Exception {
Thread t = new Thread(new Worker());//Thread-0
t.start();//Thread-0
//Thread.sleep(200);//main线程,与Thread.currentThread().sleep(200);同义
System.out.println("Thread.sleep(200)");
Thread.currentThread().sleep(200);//main线程
t.interrupt();//Thread-0
System.out.println("t.getName():" + t.getName());//Thread-0
System.out.println("2 Thread.currentThread().getName():" + Thread.currentThread().getName());//main线程
System.out.println("Main thread stopped.");
}
public static class Worker implements Runnable {
public void run() {
System.out.println("Worker started.");
java,辨别子线程、主线程
最新推荐文章于 2025-03-01 09:13:00 发布