From the course: Parallel and Concurrent Programming with Java 1
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Daemon thread: Java demo - Java Tutorial
From the course: Parallel and Concurrent Programming with Java 1
Daemon thread: Java demo
- [Instructor] In this example program called daemon thread demo, I define a class called KitchenCleaner on line five which represents a periodic background task like garbage collection. The KitchenCleaner uses an infinite while loop on line seven to print a message that Olivia cleaned the kitchen, and will continuously repeat that message once a second. Down in the program's main method, I create and start a new KitchenCleaner thread on lines 19 and 20, then the main thread prints a series of messages that Barren is cooking, which are split up by some sleep statements and then finally a message that Barren is done on line 28. If I run this program, I see those messages displayed but after the main thread reaches the end and prints its final Barren is done message, the program doesn't exit because the KitchenCleaner thread is still going strong and will continue to run forever. So, I'll need to manually stop execution by clicking the little red square. To prevent the program from…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Thread vs. process4m 36s
-
Thread vs. process: Java demo6m 48s
-
Concurrent vs. parallel execution4m 54s
-
Execution scheduling3m 38s
-
Execution scheduling: Java1m 57s
-
Thread lifecycle3m 36s
-
Thread lifecycle: Java demo4m 55s
-
Thread attributes: Java demo2m 22s
-
Runnable vs. thread: Java demo3m 53s
-
Daemon thread2m 49s
-
Daemon thread: Java demo2m 21s
-
-
-
-
-