為什么和老師講的代碼是一樣的卻運行不了
package com.imooc.concurrent;
public class Actor extends Thread {
public void fun() {
System.out.println(getName() +"is an actor");
int count = 0;
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");
actor.start();
}
}
2016-10-21
你寫的fun()而不是run(),程序肯定跑不起來啊,你的方法只能執(zhí)行一次++count在你的程序里無意義
2016-10-22
要寫成 Run 才行啊。