Sample Outputs

The sample outputs show each task’s name and sleep time as the thread goes to sleep. The thread with the shortest sleep time in most cases awakens first, indicates that it’s done sleeping and terminates. In Section 23.8, we discuss multithreading issues that could prevent the thread with the shortest sleep time from awakening first. In the first output, the main thread terminates before any of the PrintTasks output their names and sleep times. This shows that the main thread runs to completion before any of the PrintTasks gets a chance to run. In the second output, all of the PrintTasks output their names and sleep times before the main thread terminates. This shows that the PrintTasks started executing before the main thread ...

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.