answersLogoWhite

0

A daemon thread is often called a "service thread" or a "nonessential thread". The other kind of thread is often called a "user thread."

The JVM will exit when all user threads have returned from their run methods. Once all of the user threads have returned, any active daemon threads will be forced to stop running.

Let's look at an abstract example to see the difference... Pretend you have written a client-server GUI-based chat client. You'll typically have at least one thread sitting around and listening for input from the other program (the server will listen for input from the client and the client will listen for input from the server). These threads can be set as daemon threads, because you don't want the JVM to keep executing if those are the only threads left.

Not let's look at the GUI for your programs. These will be run in a user thread, since you want to make sure that the JVM does not exit until the GUI thread finishes running (you will generally stop these threads from running when the user clicks to close the window).

User Avatar

Wiki User

15y ago

Still curious? Ask our experts.

Chat with our AI personalities

EzraEzra
Faith is not about having all the answers, but learning to ask the right questions.
Chat with Ezra
LaoLao
The path is yours to walk; I am only here to hold up a mirror.
Chat with Lao
ReneRene
Change my mind. I dare you.
Chat with Rene

Add your answer:

Earn +20 pts
Q: What is a daemon thread?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Is main method a thread?

No, Main is not a daemon thread in Java. its a non daemon or user thread. Also any thread stem from Main will be non daemon because daemon is derived from parent Thread status.


What is daemon thread in java?

Daemon thread is a kind of thread that does not prevent the JVM from exiting when the thread is still running while the program finishes. A good example of this is the garbage collection.


How to write daemons using threads instead of using fork as there are certain conditions in which a process is called a daemon?

A "daemon" is a general English term for a process that is meant to run forever in the background, without access to a display terminal. Threads are subcomponents of processes. It is not possible to run as an isolated "thread". Every process contains at least one thread, but can contain more if programmed correctly. Threaded programming typically is done so that a master or "manager" thread listens for an indication of incoming work to be done, and then dispatches this work to a new "worker" thread to handle the work, freeing the manager thread to listen for more incoming work.


What happens to child thread when you delete main thread during run-time?

In Java, if the main thread somehow exits then all other threads will stop executing. This generally does not happen, as the main thread will wait for all child threads to terminate before the main thread itself finishes. Interrupting this process is hard to do short of an un-handled exception or a call to System.exit. If the child thread is also a daemon thread, then the child thread will continue to execute. If the child thread is a normal thread then, the moment System.exit is called, the child thread also terminates If you call the join() method from the child thread, then the main thread will wait until the child is over before executing the System.exit


How do you run daemon process?

In Unix, with a C program you can run a quick function to do this. There is an example at:(link moved to link section)AnswerIn Solaris, you need to disconnect your program from your "terminal" ( scripts generally inherit the stdin, stdout, and stderr of your shell when you execute them ). For a shell program you can execute "nohup $program < /dev/null > /dev/null 2>&1 &". Or the shell program can redirect its own stdin, stdout, and stderr -- then you can execute "nohup $program &".