JDK-6450036 : PrintStream.flush() clears thread interrupt flag (sol)
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 5.0u9
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_2.5.1
  • CPU: sparc
  • Submitted: 2006-07-18
  • Updated: 2012-01-11
  • Resolved: 2006-12-15
Related Reports
Duplicate :  
Relates :  
Description
Problem :

System.out.flush() sets the thread's interrupted status flag from true to false on Solaris.
Other io methods like println() do not change threads interrupted status.

Test Case:

public class InterruptTest extends Thread {

    public InterruptTest() {
    }

    public void run() {
        System.out.println("The interrupt flag is initially " +
this.isInterrupted() );
        System.out.println("Setting the interrupt flag to true.");
        this.interrupt();
        System.out.println("The interrupt flag is now " +
this.isInterrupted() );
        System.out.flush();
        if (this.isInterrupted() == false) {
            System.out.println("ERROR: After calling flush(), the
interrupt " +
                               "flag is now false, but is should be true.");
        }
        else {
            System.out.println("After calling flush(), the interrupt
flag " +
                               " is still true, which is the correct
result.");
        }
    }

    public static void main(String[] args) {
        InterruptTest test = new InterruptTest();
        test.start();

        try {
            test.join();
        }
        catch (InterruptedException e) {
            System.err.println("ERROR: InterruptTest interrupted during
join");
        }
    }
}


O/P on Windows :
The interrupt flag is initially false
Setting the interrupt flag to true.
The interrupt flag is now true
After calling flush(), the interrupt flag  is still true, which is the correct result.

O/P on Solaris :
The interrupt flag is initially false
Setting the interrupt flag to true.
The interrupt flag is now true
ERROR: After calling flush(), the interrupt flag is now false, but is should be true.

Is this inconsistent behaviour intended?

Comments
EVALUATION 6382902 which introduces the option described in the "Work Around" section has been backported to 5.0u12. Closing this issue as duplicate.
15-12-2006

WORK AROUND Use vm optoin -XX:-UseVMInterruptibleIO. $ uname -a SunOS boing 5.9 Generic_112233-05 sun4u sparc SUNW,Sun-Blade-1000 $ java -XX:-UseVMInterruptibleIO InterruptTest The interrupt flag is initially false Setting the interrupt flag to true. The interrupt flag is now true After calling flush(), the interrupt flag is still true, which is the correct result. *** (#1 of 1): [ UNSAVED ] ###@###.###
19-07-2006

EVALUATION This is is a symptom of the general "VM interuption of I/O" problem which exists for solaris only.
19-07-2006