natsu 積分 0

目前看起來也只有在巢狀 loop 中會有影響... 請看 Why do we have to interrupt the thread again? 小節1

所以其實 Thread.currentThread().interrupt(); 也不是一定要加的?

這是文章的子討論串,你可以回到上層查看所有討論和文章
IngramChen 積分 0

通常 thread 是 library 或 framework 呼叫你的 method 的。所以你也不知道它們是不是 loop 還是怎樣

natsu 積分 0

所以目前的結論是:

  1. 如果可以就把 InterruptedException 往外丟,然後由外層執行例外處理 (e.g. transaction rollback、close resources)。
  2. 若你的 method 有可能會被其他 thread 中斷,但無法丟出 InterruptedException,則執行例外處理時至少要呼叫 Thread.currentThread().interrupt();
  3. 若你的 method 確定不會被其他 thread 中斷,則可自行決定是否要做例外處理。