您可以使用Thread 类的sleep()方法将当前线程暂停数毫秒。当前线程处于休眠状态时,它将允许其他线程执行。
package org.nhooo.example.lang;
public class ThreadSleepDemo implements Runnable {
// 启动线程时将调用run()方法。
public void run() {
System.out.println("Start..");
try {
// 等待10秒
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Finish...");
}
public static void main(String[] args) {
Thread thread = new Thread(new ThreadSleepDemo());
thread.start();
}
}