7043425: (fc) ClosedByInterruptException thrown but interrupt status not set
Reviewed-by: dholmes, chegar
--- a/jdk/src/share/classes/sun/nio/ch/NativeThreadSet.java Tue May 10 12:14:07 2011 -0700
+++ b/jdk/src/share/classes/sun/nio/ch/NativeThreadSet.java Wed May 11 14:57:17 2011 +0100
@@ -96,11 +96,16 @@
break;
}
waitingToEmpty = true;
+ boolean interrupted = false;
while (used > 0) {
try {
wait();
- } catch (InterruptedException ignore) { }
+ } catch (InterruptedException e) {
+ interrupted = true;
+ }
}
+ if (interrupted)
+ Thread.currentThread().interrupt();
}
}
}
--- a/jdk/test/java/nio/channels/FileChannel/ClosedByInterrupt.java Tue May 10 12:14:07 2011 -0700
+++ b/jdk/test/java/nio/channels/FileChannel/ClosedByInterrupt.java Wed May 11 14:57:17 2011 +0100
@@ -52,13 +52,16 @@
fc.write(bb);
}
- // test with 1-8 concurrent threads
- for (int i=1; i<=8; i++) {
+ // test with 1-16 concurrent threads
+ for (int i=1; i<=16; i++) {
System.out.format("%d thread(s)%n", i);
test(f, i);
if (failed)
break;
}
+
+ if (failed)
+ throw new RuntimeException("Test failed");
}
/**
@@ -132,12 +135,14 @@
// give the interruptible thread a chance
try {
Thread.sleep(rand.nextInt(50));
- } catch (InterruptedException ignore) { }
+ } catch (InterruptedException e) {
+ unexpected(e);
+ }
}
}
} catch (ClosedByInterruptException e) {
if (interruptible) {
- if (Thread.currentThread().isInterrupted()) {
+ if (Thread.interrupted()) {
expected(e + " thrown and interrupt status set");
} else {
unexpected(e + " thrown but interrupt status not set");
@@ -158,7 +163,7 @@
}
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) {