package www.bit;
/*编写一个程序,启动三个线程,三个线程的名称分别是A,B,C;每个线程将自己的名称在屏幕上打印5遍,打印顺序是ABCABCABC*/
class Print{
private int flag = 1;
private int count = 0;
public int getCount() {
return count;
}
public synchronized void printA(){
while(flag!=1){
try {
wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.print(Thread.currentThread().getName());
count++;
flag = 2;
notifyAll();
}
public synchronized void printB(){
while(flag!=2){
try {
wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.print(Thread.currentThread().getName());
flag = 3;
count++;
notifyAll();
}
public synchronized void printC(
编写一个程序,启动三个线程,三个线程的名称分别是A,B,C;每个线程将自己的名称在屏幕上打印5遍,打印顺序是ABCABCABC.....
最新推荐文章于 2022-11-10 10:50:46 发布