試試看
public static void main(String[] args)
{
// Create three threads
Thread first = new TryThread(
Thread second = new TryThread(
Thread third = new TryThread(
System
first
second
third
try
{
System
System
}
catch (IOException e) // Handle IO exception
{
System
}
System
return;
}
現在程序將產生如下輸出
Press Enter when you have had enough…
Slim Hopalong Marilyn Caxsidy
Hopalong Monrog
Marily Cassidy
Hopalong Pickens
Slim Cassidy
Hopalong Monroe
Marilyn
Enter prossed…
Ending main()
Marilyn Monroe java
如何工作
由於當你鍵入回車鍵後main()方法對每個線程調用了interrupt()方法
通過對線程調用isInterrupted()方法你可以檢查一個線程是否被中斷
if (first
sydtem
注意
實例方法Interrupted()對線程的中斷標志沒有什麼影響
當拋出一個InterruptedException異常時
[
From:http://tw.wingwit.com/Article/program/Java/gj/201311/27758.html