package day01; public class MyThread extends Thread{ public void run() { for(int i =0;i<20;i++) { Thread t = Thread.currentThread(); t.setName("Thread-0"); System.out.println("你好,来自线程"+t.getName()); } } }
package day01; public class MyThread2 extends Thread{ public void run() { for(int i =0;i<20;i++) { Thread t = Thread.currentThread(); t.setName("Thread-1"); System.out.println("你好,来自线程"+t.getName()); } } }
package day01; public class Test { public static void main(String[] args) { MyThread th =new MyThread(); MyThread2 th2 =new MyThread2(); th.start(); th2.start(); } }