JDK-4514257 : Thread.interrupt() on InputStream.read() fails
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 1.3.1
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: linux
  • CPU: x86
  • Submitted: 2001-10-12
  • Updated: 2017-12-08
  • Resolved: 2017-12-08
Related Reports
Relates :  
Description
Name: gm110360			Date: 10/12/2001


java version "1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)


uname -a
Linux <HOSTNAME> 2.4.3-20mdk #1 Sun Apr 15 23:03:10 CEST 2001 i686 unknown


Thread.interrupt doesn't work for InputStream.read(). This is related to bug
#4344135, but doesn't involve closing of an underlying socket.
The program below shows that the thread cannot be interrupted.

The program works fine under Solaris 8 Update 5 with JDK 1.3.1.



import java.net.*;

/** Tests Thread.interrupt() against InputStream.read() */
public class test2 {

    static class SleeperThread extends Thread {
	public void run() {
	    int c;
	    try {
		c=System.in.read();
	    }
	    catch(Exception ex) {
		System.err.println("test2.SleeperThread.run(): " + ex);
	    }
	}
    }

    
    public static void main(String[] args) {
	Thread     thread;
	final long TIMEOUT=3000;

	thread=new SleeperThread();
	thread.start();
	System.out.println("test2.main(): sleeping for " + TIMEOUT + " msecs");
	try {thread.sleep(TIMEOUT);} catch(Exception e) {}
	System.out.println("test2.main(): sleeping -- done");
	
	System.out.println("test2.main(): interrupting thread");
	thread.interrupt();
	System.out.println("test2.main(): interrupting thread -- done");
	
	System.out.println("test2.main(): joining thread (timeout=" + TIMEOUT + "
msecs)");
	try {thread.join(TIMEOUT);} catch(Exception e) {}
	System.out.println("test2.main(): joining thread -- done");

	System.out.println("test2.main(): thread.isAlive()=" + thread.isAlive());
	if(thread.isAlive()) {
	    System.out.println("test2.main(): thread was interrupted but is still
running !");
	}
    }
}
(Review ID: 133623) 
======================================================================

Comments
This seems to be ancient request to bring back interruptible I/O.
08-12-2017

EVALUATION An approximately equal number of people are annoyed by thread interruption having a side effect on I/O as are annoyed by lack of thread interrupts interrupting I/O. Please see the 4385444 evaluation for additional information about the disposition of this and related problems stemming from nonuniform support for thread interruption causing I/O interruption.
27-10-2006

EVALUATION This is the opposite of 4329256 "interrupted thread no longer produces output (sol)" and demonstrates more problems raised with behavior that isn't uniformly available. See the notes, especially the "workarounds" for 4329256 for more details.
28-02-2006

WORK AROUND Name: gm110360 Date: 10/12/2001 NONE: we cannot close System.in ======================================================================
11-06-2004