System.out.println(Thread.currentThread().getName() + " is Started");
Thread aThread = new Thread() {
public void run() {
try {
System.out.println("aThread is Started");
Thread.sleep(2000);
System.out.println("aThread is Completed");
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
};
aThread.start();
System.out.println(Thread.currentThread().getName() + " is Completed");
例如上面的情況,由於 aThread 需要兩秒,所以 main 先完成。