我是一個線程初學者。我不知道線程對象稱爲睡眠方法的三種不同方式之間的區別。還可以請你澄清在案件類型上有使用睡眠方法被調用線程中調用睡眠方法的不同方法
方式下面
// implementing thread by extending THREAD class//
class Logic1 extends Thread
{
public void run()
{
for(int i=0;i<10;i++)
{
Thread s = Thread.currentThread();
System.out.println("Child :"+i);
try{
s.sleep(1000); // these are the three types of way i called sleep method
Thread.sleep(1000); //
this.sleep(1000); //
} catch(Exception e){
}
}
}
}
class ThreadDemo1
{
public static void main(String[] args)
{
Logic1 l1=new Logic1();
l1.start();
}
}
'sleep()'是一個總是引用當前正在執行的線程的靜態方法。 –
沒有三種方法可以調用sleep方法,Thread#sleep是static方式,所以你可以直接從'Thread'類或從當前'Thread'對象引用中調用它。 –
都是一樣的。 :D – gumuruh