I am seeing interesting behavior. I am running this code
public class ThreadsTest {
public static void main(String[] args) {
Runnable mr = new MyRunnable();
Thread t1 = new Thread(mr);
Thread t2 = new Thread(mr);
t1.setName("first");
t2.setName("second");
t1.start();
t2.start();
t1.run();
}
}
class MyRunnable implements Runnable {
public void run() {
for (int i=0; i < 2; i++) {
System.out.println("Running: " + Thread.currentThread().getName());
}
}
}
The output I get is:
Running: first
Running: first
Running: second
Running: second
I am expecting to see something similar to this:
Running: first
Running: first
Running: second
Running: second
Running: main
Running: main
Does anyone knows why I don't see Running: main
somewhere in my output. Thank you.