public class Actor extends Thread {
public void run(){
System.out.println(getName()+"是一个演员");
int count=0;
boolean keeprunning=true;
while(keeprunning){
System.out.println(getName()+"登台演出"+(++count)+"次");
if(count==100){
keeprunning=false;
}
if(count%10==0){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
System.out.println(getName()+"演出结束了");
}
class Actress implements Runnable{
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println(Thread.currentThread().getName()+"是一个演员");
int count=0;
boolean keeprunning=true;
while(keeprunning){
System.out.println(Thread.currentThread().getName()+"登台演出"+(++count)+"次");
if(count==100){
keeprunning=false;
}
if(count%10==0){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
System.out.println(Thread.currentThread().getName()+"演出结束了");
}
}
public static void main(String[] args) {
Thread actor=new Actor();
actor.setName("MESSI");
actor.start();
Thread actressThread=new Thread(new Actress(),"C.Ronaldo");
actressThread.start();
}
}