Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions src/java.base/share/classes/java/util/concurrent/ForkJoinTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -418,19 +418,15 @@ else if (((a = aux) == null || a.ex == null) &&
for (;;) {
if ((s = status) < 0)
break;
else if (interrupts < 0) {
s = ABNORMAL; // interrupted and not done
break;
}
else if (Thread.interrupted()) {
if (!ForkJoinPool.poolIsStopping(pool))
interrupts = interruptible ? -1 : 1;
else {
interrupts = 1; // re-assert if cleared
if (ForkJoinPool.poolIsStopping(pool)) {
try {
cancel(true);
} catch (Throwable ignore) {
}
} catch (Throwable ignore) { }
}
if ((interrupts = interruptible ? -1 : 1) < 0) {
s = ABNORMAL;
break;
}
}
else if (deadline != 0L) {
Expand Down
17 changes: 17 additions & 0 deletions test/jdk/java/util/concurrent/tck/ForkJoinPoolTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,23 @@ public void realRun() throws Exception {
}
}

public void testCallerInterruptedDuringSubmit() throws InterruptedException, ExecutionException {
final Thread submitter = Thread.currentThread();
final ExecutorService p = new ForkJoinPool(1);
try (PoolCleaner cleaner = cleaner(p)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As ExecutorService extends AutoCloseable then I assume PoolCleaner is not needed here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for (int i = 0; i < 512; ++i) { // Enough repetitions such that any race condition is bound to materialize
try {
p.submit(submitter::interrupt).get();
// If we don't get an InterruptedException, then the current thread should be interrupted
assertTrue(Thread.interrupted());
} catch (InterruptedException e) {
// If we do get an InterruptedException, then the current thread should not be interrupted
assertTrue(!Thread.interrupted());
}
}
}
}

/**
* get of submit(callable) throws ExecutionException if callable
* throws exception
Expand Down