Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Java non-blocking I/O operations....?

Options
  • 15-11-2007 4:29pm
    #1
    Registered Users Posts: 2,835 ✭✭✭


    Folks,

    I'm trying to close a thread in my program, but it wont let me as there is an I/O call in the thread that is blocking and waiting for input

    this is the run method inside my thread class
    
    class myThreadName extends Thread
    {
    public void run() 
    	{
    			
    			Scanner in = new Scanner(System.in);
    			int input = in.nextInt();
    			if (input >= myObject.nextPrice())
    			{
    				// print to the console
    				// call some method
    			}
    			
    			
    	}
    }
    

    I'm instantiaing a new thread in the main program and using mythreadname.start() to get it going. mythreadname.stop() wont stop it and neither will suspend(), interrupt() etc...

    Does Java have any non-blocking I/O operations in its API? even some sort of I/O timeout might work if its there but i cant find anything helpful in google

    Cheers Lads... any ideas appreciated


Comments

  • Registered Users Posts: 1,996 ✭✭✭lynchie


    Most of the java nio packages allow you to interrupt blocked IO as does the Socket code.. AFAIK, reading from the console cannot be interrupted. Your code will block indefinitely until somebody hits enter on the keyboard.


  • Registered Users Posts: 2,835 ✭✭✭StickyMcGinty


    cheers lynchie, i managed to get it in the end by setting the thread as a Daemon thread, useful for anyone with the same problem


Advertisement