若只有My Thread怎么回事?錯在哪了??
package seecen20160820例題;
public class Actor extends Thread{
? ? public void run(){
? ? 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){
? ? e.printStackTrace();
? ? }
? ? }
? ? }
? ? System.out.println(Thread.currentThread().getName()+"演出結(jié)束了!");
? ?
? ? }
? ? public static void main(String[] args) {
Thread actor =new Actor();
actor.setName("Mr.Thread");
actor.start();
?
Thread actressThread =new Thread(new Actress(),"Ms.Runnable");
actressThread.start();
? ?
} ?
}
class Actress implements Runnable{
@Override
public void run() {
}
}
2016-08-20
你只設(shè)置了一個線程,只有My Thread,所以只會顯示My Thread。你的問題不是很清晰,你的意思是想要多個線程?