Grokking Java Interview Questions
0% completed
Threads and the Thread Lifecycle
Thread worker = new Thread(() -> System.out.println("order 1001 packed")); worker.start(); System.out.println("order 1002 packed");
These three lines can print their two messages in either order, and the order can differ between two runs of the same program. The thread main runs the last line, a new thread runs the first message, and nothing in the code makes one of them wait for the other.
The questions in this lesson explain how a thread starts, which states it passes through, how one thread waits for another to end, and which threads keep a program running.
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%