提交 2e9e1b20 编写于 作者: A alanb

7043425: (fc) ClosedByInterruptException thrown but interrupt status not set

Reviewed-by: dholmes, chegar
上级 481c8af5
...@@ -96,11 +96,16 @@ class NativeThreadSet { ...@@ -96,11 +96,16 @@ class NativeThreadSet {
break; break;
} }
waitingToEmpty = true; waitingToEmpty = true;
boolean interrupted = false;
while (used > 0) { while (used > 0) {
try { try {
wait(); wait();
} catch (InterruptedException ignore) { } } catch (InterruptedException e) {
interrupted = true;
} }
} }
if (interrupted)
Thread.currentThread().interrupt();
}
} }
} }
...@@ -52,13 +52,16 @@ public class ClosedByInterrupt { ...@@ -52,13 +52,16 @@ public class ClosedByInterrupt {
fc.write(bb); fc.write(bb);
} }
// test with 1-8 concurrent threads // test with 1-16 concurrent threads
for (int i=1; i<=8; i++) { for (int i=1; i<=16; i++) {
System.out.format("%d thread(s)%n", i); System.out.format("%d thread(s)%n", i);
test(f, i); test(f, i);
if (failed) if (failed)
break; break;
} }
if (failed)
throw new RuntimeException("Test failed");
} }
/** /**
...@@ -132,12 +135,14 @@ public class ClosedByInterrupt { ...@@ -132,12 +135,14 @@ public class ClosedByInterrupt {
// give the interruptible thread a chance // give the interruptible thread a chance
try { try {
Thread.sleep(rand.nextInt(50)); Thread.sleep(rand.nextInt(50));
} catch (InterruptedException ignore) { } } catch (InterruptedException e) {
unexpected(e);
}
} }
} }
} catch (ClosedByInterruptException e) { } catch (ClosedByInterruptException e) {
if (interruptible) { if (interruptible) {
if (Thread.currentThread().isInterrupted()) { if (Thread.interrupted()) {
expected(e + " thrown and interrupt status set"); expected(e + " thrown and interrupt status set");
} else { } else {
unexpected(e + " thrown but interrupt status not set"); unexpected(e + " thrown but interrupt status not set");
...@@ -158,7 +163,7 @@ public class ClosedByInterrupt { ...@@ -158,7 +163,7 @@ public class ClosedByInterrupt {
} }
static void expected(Exception e) { static void expected(Exception e) {
System.out.format("%s (not expected)%n", e); System.out.format("%s (expected)%n", e);
} }
static void expected(String msg) { static void expected(String msg) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册