亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

Thread actor=new Thread(new Actor(),"Mr.Thread");

為什么如題的代碼運行結果不對 編譯器也不報錯呢

正在回答

3 回答

package com.imooc.concurrent;


public class Actor extends Thread {


public void run() {

System.out.println(getName() + "is an actor");

int count = 0;

boolean a=true;

while (a){

System.out.println(getName() + "show begins" + (++count));

if (count==100)

{

a=false;

}

if(count%10==0){

try {

Thread.sleep(1000);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

// System.out.println(getName() + "show begins" + (++count));

System.out.println(getName() + "show is over");

}


public static void main(String[] args) {

// Thread actor = new Actor();

//

// actor.setName("Mr.Thread");

Thread actor=new Thread(new Actor(),"Mr.Thread");

actor.start();

Thread actressThread= new Thread(new Actress(),"Ms.Runnable");

actressThread.start();

}


}


?class Actress implements Runnable{

public void run() {

System.out.println(Thread.currentThread().getName() + "is an actor");

int count = 0;

boolean a=true;

while (a){

System.out.println(Thread.currentThread().getName() + "show begins" + (++count));

if (count==100)

{

a=false;

}

if(count%10==0){

try {

Thread.sleep(1000);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

// System.out.println(getName() + "show begins" + (++count));

System.out.println(Thread.currentThread().getName() + "show is over");

}

?}


0 回復 有任何疑惑可以回復我~

Actor是否實現了Runable或繼承了Thread,run方法是否有問題

0 回復 有任何疑惑可以回復我~
#1

慕神1905738 提問者

代碼加進來了 請看看是哪里的問題 謝謝
2016-10-25 回復 有任何疑惑可以回復我~

查看下 Actor類 是否實現了 runable接口

0 回復 有任何疑惑可以回復我~
#1

慕神1905738 提問者

代碼加進來了 請幫忙看看是哪里的問題 謝謝
2016-10-25 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

Thread actor=new Thread(new Actor(),"Mr.Thread");

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號