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);

解决方案 »

  1.   

       /**
         * 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