示例代码
public class Lesson091 {
public static void main(String[] args) {
//下面创建3个线程:thread1、thread2、thread3
Thread thread1 = new Thread(() -> {
for (int i = 0; i < 50; i++) {
System.out.println(Thread.currentThread() + " " + i);
}
}, "thread1");
Thread thread2 = new Thread(() -> {
for (int i = 0; i < 50; i++) {
System.out.println(Thread.currentThread() + " " + i);
}
}, "thread2");
Thread thread3 = new Thread(() -> {
for (int i = 0; i < 50; i++) {
System.out.println(Thread.currentThread() + " " + i);
}
}, "thread3");
thread1.start();
thread2.start();
thread3.start();
}
}
idea 设置如下
效果如下,点击切换,就单独调试某个线程