This is a piece of code in a SCJP practice question:
public class Threads2 implements Runnable {
public void run() {
System.out.println("run.");
throw new RuntimeException("Problem");
}
public static void main(String[] args) {
Thread t = new Thread(new Threads2());
t.start();
System.out.println("End of method.");
}
}
It was partly mentioned here.
However, my question is not the prior question. As I run the program on a few machines multiple times, I occasionally get RuntimeException
before "run" in the output. This does not make sense to me, as these lines of codes executed in the same thread, so it should have been the reverse order.
Can anyone explain why that happens?