Can anyone give me insight into why the ServerSocket constructor never returns in the new thread? (I never see the "Opened" message printed to the console.) It seems the main thread prevents the server socket thread from running by entering into readLine too quickly:
public class Main
{
public static void main(String[] args) throws IOException
{
new Thread(new SocketOpener()).start();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String inLine = br.readLine();
System.out.println(inLine);
}
}
public class SocketOpener implements Runnable
{
public void run()
{
try
{
System.out.println("Opening...");
ServerSocket socket = new ServerSocket(4444);
System.out.println("Opened");
}
catch (IOException ex)
{
System.out.println("IO Error");
}
}
}