public static void main(String[] args) throws InterruptedException {
new TeacherThread("张老师").start();
new TeacherThread("林老师").start();
new TeacherThread("李老师").start();
}
class TeacherThread extends Thread{
private static int num = 1;
public TeacherThread(String name) {
super(name);
}
@Override
public void run() {
while (true) {
synchronized (TeacherThread.class) {
if (num == 81) {
break;
}
if (num == 80) {
if (!("李老师").equals(getName())) {
continue;
}
}
System.out.println(getName() + "正在发" + num + "份笔记");
num++;
}
}
}
}