Demonic and non-demonic threads
It must be noted that the thread is invoked from the main program and the main program will not exit (by default) until the thread is executed completely. The reason is that the main program invokes the thread by default in non-demonic mode, which makes the thread run in the foreground rather than wait for it to run in the background. Thus, a non-demonic thread is one that runs in the foreground, causing the main program to wait for the running threads to finish their execution. A demonic thread, on the other hand, is one that runs in the background, therefore not causing the main program to wait for it to finish its execution. Take a look at the following example:
As can be seen from the preceding code snippet, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access