0

I'm creating this program to test getting user input in a thread for a chat server program. This program stops on read = into.readLine();. Why is that and what's happening?

Here is the code:

    import java.io.*;
    import java.net.*;

    public class ThreadClass implements Runnable
    {
        DataInputStream in;
        private boolean checkLoop = false;


    public void run()
    {
        BufferedReader into = new BufferedReader(new        InputStreamReader(System.in));
        String read;
        System.out.println("Welcome...");
        while(!checkLoop)
        {
            try
            {
                System.out.println("running1");
                read = into.readLine();
                System.out.println(read);
                if(read.equals(".bye"))
                {
                    checkLoop = true;
                }
                Thread.sleep(500);
            }
            catch(IOException e)
            {
                System.out.println(e);System.out.println("running2");
            }
            catch (InterruptedException ie)
            {
                System.out.println(ie);System.out.println("running3");
            }
        }
        System.out.println("running4");
    }

    public static void main(String[]args)
    {
        ThreadClass main = new ThreadClass();
        Thread t1 = new Thread(main);
        t1.start();
    }

    }
MWiesner
  • 7,913
  • 11
  • 31
  • 66
Mason0958
  • 39
  • 10

1 Answers1

0

When you use "read = into.readLine();" the program will stop and wait for the user to press the "Enter" key. Your program is working fine from my point of view.

Try to type something in console and you will see the program running correctly.

Lourenco
  • 281
  • 1
  • 5