我是线程的初学者。我不知道线程对象调用睡眠方法的三种不同类型的方式有什么区别。另外,您能否澄清在哪种类型的情况下,使用调用 sleep 方法的方式存在限制
代码如下
// 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();
}
}