public class Taest extends Thread{
public void run(){
for(int i=0;i<50;i++)
System.out.println(i);
}
public static void main(String[] agrs){
Taest a=new Taest();
Taest b=new Taest();
a.start();
try{
Thread.sleep(10);
b.start();
}catch(InterruptedException e){
}
}
}
請問sleep(),休眠的是哪個線程?是main線程還是線程a?
main線程
Thread.sleep(1000);
System.out.println(Thread.currentThread().getName());
這樣寫你就能看出來了