public class PrintThread implements Runnable{
private String name;
public PrintThread(){
}
public PrintThread(String name){
super();
this.name=name;
}
public void run(){
print();
}
private void print() {
// TODO Auto-generated method stub
System.out.println(name+"开始打印");
}
}
public class TestThread {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
PrintThread p1=new PrintThread("打印机1");
p1.start();
Thread t=new PrintThread("打印机2");
t.start();
}
}
为什么我创建的线程开起不了呢?总是报错,求解。 |
|