Java: Difference in usage between Thread.interrupted() and Thread.isInterrupted()?

后端 未结 9 719
南旧
南旧 2020-12-12 16:28

Java question: As far as I know, there are two ways to check inside a thread whether the thread received an interrupt signal, Thread.interrupted() and Thr

9条回答
  •  南笙
    南笙 (楼主)
    2020-12-12 16:43

    The interrupted() method is a class method that always checks the current thread and clears the interruption "flag". In other words, a second call to interrupted() will return false.

    The isInterrupted() method is an instance method; it reports the status of the thread on which it is invoked. Also, it does not clear the interruption flag. If the flag is set, it will remain set after calling this method.

提交回复
热议问题