转自:http://www.tutorialspoint.com/java/lang/thread_sleep_millis.htm
Description
The java.lang.Thread.sleep(long millis)method causes the currently executing thread to sleep for the specified number of milliseconds, subject to the precision and accuracy of system timers and schedulers.
Declaration
Following is the declaration for java.lang.Thread.sleep()method
publicstaticvoidsleep(longmillis)throwsInterruptedException
Parameters
millis -- This is the length of time to sleep in milliseconds.
Return Value
This method does not return any value.
Exception
InterruptedException -- if any thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown.
Example
The following example shows the usage of java.lang.Thread.sleep() method.
packagecom.tutorialspoint;importjava.lang.Thread;publicclassThreadDemoimplementsRunnable{Threadt;publicvoidrun(){for(inti=10;i<13;i++){System.out.println(Thread.currentThread().getName()+" "+i);try{// thread to sleep for 1000 millisecondsThread.sleep(1000);}catch(Exceptione){System.out.println(e);}}}publicstaticvoidmain(String[]args)throwsException{Threadt=newThread(newThreadDemo());// this will call run() functiont.start();Threadt2=newThread(newThreadDemo());// this will call run() functiont2.start();}}
Let us compile and run the above program, this will produce the following result:
Thread-010Thread-110Thread-011Thread-111Thread-012Thread-112