@Slf4j
public class MyThread implements Runnable{
private String name;
public MyThread(String name){
this.name = name;
}
@Override
public void run() {
for (int i=0;i<3;i++) {
log.info("current thread:{},paramName:{}",Thread.currentThread().getName(),name);
}
}
}
public static void main(String[] args) throws InterruptedException {
log.info("first thread:{}",Thread.currentThread().getName());
Thread t1 = new Thread(new MyThread("11"));
Thread t2 = new Thread(new MyThread("22"));
Thread t3 = new Thread(new MyThread("33"));
t1.start();
t1.join();
t2.start();
t2.join();
t3.start();
t3.join();
log.info("end");
}
结果
2021-02-06 10:13:13,928 INFO [com.zlzgy.tetralogy.util.ChineseCharacterUtil] - first thread:main
2021-02-06 10:13:13,929 INFO [com.zlzgy.tetralogy.util.MyThread] - current thread:Thread-0,paramName:11
2021-02-06 10:13:13,929 INFO [com.zlzgy.tetralogy.util.MyThread] - current thread:Thread-0,paramName:11
2021-02-06 10:13:13,929 INFO [com.zlzgy.tetralogy.util.MyThread] - current thread:Thread-0,paramName:11
2021-02-06 10:13:13,929 INFO [com.zlzgy.tetralogy.util.MyThread] - current thread:Thread-1,paramName:22
2021-02-06 10:13:13,929 INFO [com.zlzgy.tetralogy.util.MyThread] - current thread:Thread-1,paramName:22
2021-02-06 10:13:13,929 INFO [com.zlzgy.tetralogy.util.MyThread] - current thread:Thread-1,paramName:22
2021-02-06 10:13:13,930 INFO [com.zlzgy.tetralogy.util.MyThread] - current thread:Thread-2,paramName:33
2021-02-06 10:13:13,930 INFO [com.zlzgy.tetralogy.util.MyThread] - current thread:Thread-2,paramName:33
2021-02-06 10:13:13,930 INFO [com.zlzgy.tetralogy.util.MyThread] - current thread:Thread-2,paramName:33
2021-02-06 10:13:13,930 INFO [com.zlzgy.tetralogy.util.ChineseCharacterUtil] - end