还是我自己来吧,是这样的。。。。
public class ABCThread implements Runnable{
String id;
static String stu="A";
public ABCThread(String id){
this.id=id;
}
@Override
public void run() {
// TODO Auto-generated method stub
for(int i=0;i<10;i++){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
synchronized (stu) {
System.out.println(Thread.currentThread().getName()+"="+stu);
if(stu.equals("A")){
stu="B";
}
else if(stu.equals("B")){
stu="C";
}
else if(stu.equals("C")){
stu="A";
}
}
}
}
public static void main(String[] args) {
new Thread(new ABCThread("A")).start();
new Thread(new ABCThread("B")).start();
new Thread(new ABCThread("C")).start();
}
}