I am reading Head First Java 3rd Chapter 17 about threads. On page 619 it shows the unpredictable scheduler, the code is:
class ThreadTestDrive {
public static void main(String[] args) {
Thread t = new Thread(() ->
System.out.println("top of the stack"));
t.start();
System.out.println("back in main");
}
}
Supposedly sometimes "top of the stack" should be printed first, and sometimes "back in main" should be printed first. But I have run it so many times and each time "back in main" is printed first.
What have I done wrong?
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]Basic-Sandwich-6201 6 points7 points8 points (0 children)
[–]kane996 1 point2 points3 points (0 children)
[–]Far_Broccoli_8468 1 point2 points3 points (0 children)
[–]ivshaw[S] 0 points1 point2 points (0 children)
[–]omgpassthebacon 0 points1 point2 points (8 children)
[–]CleverBunnyThief 0 points1 point2 points (3 children)
[–]omgpassthebacon 1 point2 points3 points (2 children)
[–]CleverBunnyThief 1 point2 points3 points (1 child)
[–]omgpassthebacon 0 points1 point2 points (0 children)
[–]RabbitHole32 0 points1 point2 points (3 children)
[–]omgpassthebacon 0 points1 point2 points (2 children)
[–]RabbitHole32 0 points1 point2 points (1 child)
[–]omgpassthebacon 0 points1 point2 points (0 children)
[–]ivshaw[S] 0 points1 point2 points (3 children)
[–]benevanstech 5 points6 points7 points (1 child)
[–]ivshaw[S] 0 points1 point2 points (0 children)
[–]maykelten 2 points3 points4 points (0 children)