What kind of behaviour causes an interrupted exception?

后端 未结 7 771
说谎
说谎 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:39

    Well if some other Thread calls thread.interupt(), while the thread is sleeping, you'll get the Exception. And yes, you can probably just put try..catch arround the sleep() and ignore it ;)

提交回复
热议问题