package itat;
public class Example9_7 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ComputerSum1 sum=new ComputerSum1();
sum.computer1.start();
}
}
class ComputerSum1 implements Runnable{
Thread computer1,computer2;
int i=1,sum=0;
ComputerSum1(){
computer1=new Thread(this);
computer2=new Thread(this);
}
public void run() {
// TODO Auto-generated method stub
while(i<=10){
sum=sum+i;
System.out.println(sum);
i++;
if(i==6&Thread.currentThread()==computer1){
System.out.println(computer1.getName()+"完成任务了!");
computer2.start();
return;
}
}
}
}