java - Does Thread.sleep throw if the thread was already interrupted? -
given thread interrupted while not blocked (i.e. no interruptedexception thrown), thread throw interruptedexception when later attempts sleep?
the documentation not state clearly:
interruptedexception - if thread has interrupted current thread. interrupted status of current thread cleared when exception thrown.
yes, does.
the documentation perhaps isn't crystal clear on point, easy both test (see own answer below, example), , see canonical (hotspot) implementation. thread.sleep shells out os:sleep
checks interruption before staring sleep process can see here (look os:sleep
).
if wasn't case, interrupts more or less impossible use. if happened arrive outside of sleep()
call lost subsequent sleep()
calls ignore them. couldn't re-interrupt thread because interrupted.
Comments
Post a Comment