Methods that Clear the Thread.interrupt() flag

后端 未结 3 1760
伪装坚强ぢ
伪装坚强ぢ 2020-12-01 06:03

I have recently inherited a large Java Application that has almost no Thread safety in it. What I\'m currently working on is getting all of the Threads to correctly handle b

3条回答
  •  眼角桃花
    2020-12-01 06:19

    Common convention is the following: any method that throws InterruptedException (+ Thread.interrupted()) clears the interrupt flag.

    So, in order to make your threads interruptable you need to find all places where InterruptedException gets caught without retrowing it or restoring the interrupt flag. Since InterruptedException is a checked exception it's not hard to do.

提交回复
热议问题