Here is some sample code. Class MyRunnable
simply prints "Thread x started", and has a Thread.sleep(4000). The rest is not important for my question. The following code is in another class :
Thread t1 = new Thread(new MyRunnable, "t1");
Thread t2 = new Thread(new MyRunnable, "t2");
Thread t3 = new Thread(new MyRunnable, "t3");
t1.start(); t2.start(); t3.start();
try {
t1.join();
t2.join();
t3.join();
} catch(InterruptedException e) {
...
I know that join
will force the program to wait until this
thread is done. Thus, when reading the program, I'm expecting t1->t2->t3 to be the order of terminations. However, I'm getting a simultaneous termination of t1,t2 and t3.
QUESTION : What's happening in the code above (in a run-time perspective)? What is the order of execution?
Thank you