我有2個類。一個POJO和主。ExecutorService.awaitTermination(超時,單位)即使在超時後仍繼續運行
POJO類
public class Processor implements Runnable{
private int id;
public Processor(int id)
{
this.id = id;
}
@Override
public void run() {
System.out.println("Started ...."+ id);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Stoped ..." + id);
}
}
主類
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
ExecutorService executor = Executors.newFixedThreadPool(2);
for(int i = 0; i < 5;i++)
{
executor.submit(new Processor(i));
}
executor.shutdown();
System.out.println("All tasks Submits");
try {
executor.awaitTermination(1, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("Intrupted or Timeout");
}
System.out.println("all Tasks completed");
}
}
當我運行這段代碼我得到的
Started ....0
All tasks Submits
Started ....1
all Tasks completed
Stoped ...1
Started ....2
Stoped ...0
Started ....3
Stoped ...2
Started ....4
Stoped ...3
Stoped ...4
的輸出,但按我的理解一次一次發生它應該引發中斷的異常並返回。但是爲什麼它在TRY塊退出後仍然繼續運行。