From the course: Parallel and Concurrent Programming with Java 1

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Daemon thread

Daemon thread - Java Tutorial

From the course: Parallel and Concurrent Programming with Java 1

Start my 1-month free trial

Daemon thread

- We often create threads to provide some sort of service, or perform a periodic task in support of the main program. A common example of that is garbage collection. A garbage collector is a form of automatic memory management that runs in the background and attempts to reclaim garbage, or memory that's no longer being used by the program. Many languages include garbage collection as a standard part of their run time environment, but for this demonstration, I'll spawn my own new thread to handle garbage collection. - Man, what a mess. - Olivia is a separate child thread that will execute independently of my main thread. So, I can continue doing what I'm doing here, getting my soup ingredients ready. - While I try to reclaim some memory, or counter space, by clearing out Baron's garbage. - This set-up, with Olivia running as a separate thread to provide that garbage collection service, will work fine until I'm ready to finish executing. Bam, now my soup's spiced and ready, my main…

Contents