public class Cx implements Runnable{
public void run(){
String name = Thread。currentThread()。getName();
if(name。
equals("左手程序")){
for(int i=1;i<=3;i++){
System。out。println("我是左手程序");
try{
Thread。sleep(500);
}
catch(InterruptedException e){}
}
}
else if(name。
equals("主程序")){
for(int i=1;i<=2;i++){
System。out。println("我是主程序");
try{
Thread。sleep(500);
}
catch(InterruptedException e){}
}
}
else if(name。
equals("右手程序")){
for(int i=1;i<=3;i++){
System。out。println("我是右手程序");
try{
Thread。sleep(500);
}
catch(InterruptedException e){}
}
}
}
}
public class Test {
public static void main(String args[]){
Cx cx = new Cx();
Thread left,hand,right;
left = new Thread(cx);
hand = new Thread(cx);
right = new Thread(cx);
left。
setName("左手程序");
hand。setName("主程序");
right。setName("右手程序");
left。start();
try{
Thread。sleep(2000);
}
catch(InterruptedException e){}
hand。
start();
try{
Thread。sleep(2000);
}
catch(InterruptedException e){}
right。start();
}
}。
全部