慕仰4084179
2015-11-11 17:37
public class ActorCopy extends Thread
{
public void run()
{
System.out.println(getName()+"是一个演员!");
boolean keepRunning=true;
int count=0;
while(keepRunning)
{
System.out.println(getName()+"第"+(count+1)+"登台演出");
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()+"结束演出!");
}
public static void main(String [] args)
{
Thread Actor=new ActorCopy();
Actor.setName("刘德华");
Actor.start();
Thread actressThread=new Thread(new Actress(),"汤唯");
actressThread.start();
}
class Actress implements Runnable
{
@Override
public void run() {
System.out.println(Thread.currentThread().getName()+"是一个女演员!");
Boolean keepRunning=true;
int count =0;
while(keepRunning)
{
System.out.println(Thread.currentThread().getName()+"第"+(count+1)+"次登台演出!");
count++;
if(count%10==0)
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(count ==100)
keepRunning=false;
}
System.out.println(Thread.currentThread().getName()+"结束演出!");
}
}
}
为什么我的代码和老师的一样就是报错!!!!!为什么
这里不一样的呀!public class ActorCopy extends Thread
class Actress implements Runnable
深入浅出Java多线程
186088 学习 · 464 问题
相似问题
回答 2
回答 1
回答 2
回答 4
回答 1