A DESCRIPTION OF THE REGRESSION :
The interrupted status of the current thread is no longer cleared when the InterruptedException is thrown during a put or take from the SynchronousQueue. Even though the interruption behavior is not specified in the documentation, the behavior should be consistent across the methods of the class (or better yet the entire JDK).
REPRODUCIBLE TESTCASE OR STEPS TO REPRODUCE:
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeUnit;
public class ExchangeTest {
public static void main(final String[] args) throws InterruptedException {
final SynchronousQueue meeting = new SynchronousQueue();
Thread other = new Thread() {
public void run() {
try {
meeting.put(args);
}
catch(InterruptedException IE) {
System.out.println("Interrupt status for put set? "+ Thread.interrupted());
}
try {
meeting.take();
}
catch(InterruptedException IE) {
System.out.println("Interrupt status for take set? "+ Thread.interrupted());
}
try {
meeting.offer(args, 60, TimeUnit.SECONDS);
}
catch(InterruptedException IE) {
System.out.println("Interrupt status for offer set? "+ Thread.interrupted());
}
try {
meeting.poll(60, TimeUnit.SECONDS);
}
catch(InterruptedException IE) {
System.out.println("Interrupt status for poll set? "+ Thread.interrupted());
}
}
};
other.start();
other.join(1000);
other.interrupt();
other.join(1000);
other.interrupt();
other.join(1000);
other.interrupt();
other.join(1000);
other.interrupt();
other.join();
}
}
RELEASE LAST WORKED:
5.0 Update 6
RELEASE TEST FAILS:
mustang-b70
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Interrupt status for put set? false
Interrupt status for take set? false
Interrupt status for offer set? false
Interrupt status for poll set? false
ACTUAL -
Interrupt status for put set? true
Interrupt status for take set? true
Interrupt status for offer set? false
Interrupt status for poll set? false
OBSERVED APPLICATION IMPACT:
Most of my applications only expect the interrupted status to be set inside the InterruptedException catch block when a user request the application to be shutdown. For example, the running task is interrupted via Future.cancel(true) followed by ExecutorService.shutdownNow() when the exit signal is received. Since the program is in shutdown, the user interface is not updated to allow the application thread to exit sooner.
If the interrupted status remains after the InterruptedException is thrown, the program has no way to tell the difference between a user canceling a task vs. the user requesting a shutdown.
Release Regression From : 5.0
The above release value was the last known release where this
bug was known to work. Since then there has been a regression.