Results 1 to 3 of 3
  1. #1
    johnmerlino is offline Member
    Join Date
    May 2014
    Rep Power

    Default Losing control of the console

    I have a multithreaded java program. I have a few worker threads which process data over a udp server. Then I have another thread for console input. The problem is when there is an error with one of the worker threads, and it prints to the console, my console thread loses "focus", that is, the while loop seems to no longer run. Here is the console thread:

    Java Code:
    	public void run() {
    		Console c = System.console();
    		if (c == null) {
    		    Logger.writeError("No console.");
    			String login = c.readLine(">>>: ");
    			System.out.println("You entered: " + login);
    When an exception is raised, it prints it to the console, and suddenly the program no longer shows the >>> prompt from above. Any idea what I might be doing wrong?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power

    Default Re: Losing control of the console

    The Console.readLine( ... ) method might throw an Exception that kills your loop; wrap it up in a try ... catch clause so you can know when something is wrong.

    kind regards,

    Build a wall around Donald Trump; I'll pay for it.

  3. #3
    pbj is offline Member
    Join Date
    Jun 2014
    Rep Power

    Default Re: Losing control of the console

    Is there any specific reason that you are using Console instead of Scanner? this might change your mind about Console.

Similar Threads

  1. Losing sleep over this
    By MW130 in forum New To Java
    Replies: 6
    Last Post: 02-02-2014, 07:44 PM
  2. Replies: 0
    Last Post: 11-22-2013, 06:19 AM
  3. Losing data from array - not sure why
    By neveser in forum New To Java
    Replies: 8
    Last Post: 12-02-2012, 08:19 AM
  4. JTabbedPane losing listener
    By mendescholl in forum AWT / Swing
    Replies: 1
    Last Post: 02-03-2012, 04:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts