oneat
oneat

Reputation: 10994

Can thread sleep when it got interrupted?

In waitComplete I have a synchronized block with waiting on the lock. My concern is that scheduled interrupt will fire before it gets to wait. Will main thread be allowed to wait when interrupted flag is on?

try {
    executor.schedule(currentThread::interrupt,100, TimeUnit.MILLISECONDS);
    completor.waitComplete();
    fail();
} catch (InterruptedException e) {}

Upvotes: 0

Views: 72

Answers (1)

JB Nizet
JB Nizet

Reputation: 692131

Javadoc:

Throws: InterruptedException - if any thread interrupted the current thread before or while the current thread was waiting for a notification.

(emphasis mine)

Upvotes: 4

Related Questions