What kind of behaviour causes an interrupted exception?

后端 未结 7 761
说谎
说谎 2020-12-24 13:15

I\'m relatively new to Threading in Java and I\'ve noticed that everytime I use Thread.sleep() I have to catch InterrupetdException.

What kind of behaviour causes th

7条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-24 13:48

    The primary case is when someone calls Thread.interrupt() on your thread.

    It may be safer to throw a RuntimeException if it happens when you're really not expecting it, but for very simple cases you can probably ignore it.

提交回复
热议问题