public class SaleTicket implements Runnable {
private int num = 200;
@Override
public void run() {
System.out.println(Thread.currentThread().getName());
new Thread (new Runnable(){
public void run(){
while (num > 0) {
System.out.println(Thread.currentThread().getName()
+ ",,,,,,,sale" + (num--));
}
}
}).start();
}
}
突然想到如果在覆盖run()的时候再new一个新的线程会怎样,或者可不可以,代码能运行,这就相当于在线程中又开启了一个线程,Java中这样也可以吗
|
|