Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 140838 - [console] reading from System.in using a FileChannel doesn't interrupt
Summary: [console] reading from System.in using a FileChannel doesn't interrupt
Status: RESOLVED DUPLICATE of bug 40066
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Debug (show other bugs)
Version: 3.1.2   Edit
Hardware: PC Windows XP
: P3 minor (vote)
Target Milestone: ---   Edit
Assignee: JDT-Debug-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-05-09 12:43 EDT by Ben Grommes CLA
Modified: 2007-02-08 09:37 EST (History)
0 users

See Also:


Attachments
Example program to reproduce bug (1.22 KB, text/plain)
2006-05-09 12:45 EDT, Ben Grommes CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ben Grommes CLA 2006-05-09 12:43:31 EDT
System.in provided by Eclipse doesn't respond to Thread.interrupt unlike if I run the program from a shell window.
Comment 1 Ben Grommes CLA 2006-05-09 12:45:26 EDT
Created attachment 40756 [details]
Example program to reproduce bug

This program if run from a windows shell will interrupt the CommandReader thread after 3 seconds even though it is in a blocking call to System.in.read.  If the program is run from Eclipse the CommandReader thread does not unblock until you enter a key.
Comment 2 Olivier Thomann CLA 2006-05-09 12:46:21 EDT
Moving to JDT/Debug.
Comment 3 Darin Wright CLA 2007-02-08 09:37:03 EST
This is a dup of bug 40066, which is caused by:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4809647

If I change the code in the run() method to the following, it works:

    public void run() {
        InputStream stdin = Channels.newInputStream(new FileInputStream(FileDescriptor.in).getChannel());
        BufferedReader reader = new BufferedReader(new InputStreamReader(stdin));
        String line = null;
        try {
			while (!reader.ready()) {
				Thread.sleep(100);
			}
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (InterruptedException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		System.out.println("READY");
        try {
            while ((line = reader.readLine()) != null) {
                System.out.println(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

*** This bug has been marked as a duplicate of bug 40066 ***