首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

关于Thread种,为什么Thread没有实例化就可以执行Thread.sleep(10000)

2013-09-07 
关于Thread类,为什么Thread没有实例化就可以执行Thread.sleep(10000)import java.lang.*import java.uti

关于Thread类,为什么Thread没有实例化就可以执行Thread.sleep(10000);


import java.lang.*;
import java.util.Date;

public class test
{
public static void main(String[] args)
{
Runner r=new Runner();
Thread t=new Thread(r);
t.start();
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
t.interrupt();
}
}

class Runner implements Runnable
{
public void run()
{
while(true){
System.out.println("==========" +new Date()+"==========");
try {
Thread.sleep(1000);

} catch (InterruptedException e) {
return ;
}
}
}
}


为什么Thread没有实例化就可以执行Thread.sleep(10000);
[解决办法]
因为是static方法。
[解决办法]
静态方法啊
[解决办法]
   /**
     * Causes the currently executing thread to sleep (temporarily cease 
     * execution) for the specified number of milliseconds, subject to 
     * the precision and accuracy of system timers and schedulers. The thread 
     * does not lose ownership of any monitors.
     *
     * @param      millis   the length of time to sleep in milliseconds.
     * @exception  InterruptedException if any thread has interrupted
     *             the current thread.  The <i>interrupted status</i> of the


     *             current thread is cleared when this exception is thrown.
     * @see        Object#notify()
     */
    public static native void sleep(long millis) throws InterruptedException;



就像String.valueOf

热点排行