Check this code out
Thread t1 = new Thread(new Runnable() {
@Override
public void run()
{
try
{
System.out.println("STARTING SERVER...");
ServerSocket s = new ServerSocket(2544);
System.out.println("SERVER BLOCKED ON ACCEPT");
Socket ss = s.accept();
System.out.println("SERVER NOT BLOCKED ANYMORE");
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
});
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run()
{
try
{
while(true)
{
Thread.sleep(1000);
System.out.println("Hello");
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
});
t2.start();
Outputs:
STARTING SERVER...
SERVER BLOCKED ON ACCEPT
Hello
Hello
Hello
Hello
Hello
Hello
Hello
...
Java threads should be user space threads, right? So one blocked thread should block the entire process...thats not what happened. What is happening them?