answersLogoWhite

0

What is a daemon thread?

Updated: 12/15/2022
User Avatar

Wiki User

14y ago

Best Answer

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

14y ago
This answer is:
User Avatar

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 &".

Related questions

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 are the features of daemon thread in java?

Any Java thread can be a daemon thread. Daemon threads are service providers for other threads running in the same process as the daemon thread. For example, the HotJava browser uses up to four daemon threads named "Image Fetcher" to fetch images from the file system or network for any thread that needs one. The run() method for a daemon thread is typically an infinite loop that waits for a service request. When the only remaining threads in a process are daemon threads, the interpreter exits. This makes sense because when only daemon threads remain, there is no other thread for which a daemon thread can provide a service. To specify that a thread is a daemon thread, call the setDaemon() method with the argument true. To determine if a thread is a daemon thread, use the accessor method isDaemon().


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.


Where can you purchase Daemon tools?

Daemon Tools can be purchased at Daemon's official website.


What is Will's daemon called?

Will's daemon is named Kirjava.


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


When was Daemon Records created?

Daemon Records was created in 1990.


What is the weapon for a daemon in astroflux?

the weapon of daemon is corrosive teeth


Is a very secure FTP daemon a stand-alone daemon?

Yes


What does daemon stand for?

Daemon is the Latin version of the English word demon.


When was Daemon Viam Invenient created?

Daemon Viam Invenient was created in 2007.