aspose file tools
The moose likes Threads and Synchronization and the fly likes Daemon and Non Daemon Thread Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Daemon and Non Daemon Thread" Watch "Daemon and Non Daemon Thread" New topic
Author

Daemon and Non Daemon Thread

Radhika Gokhale
Ranch Hand

Joined: Dec 12, 2002
Posts: 40
Hi,

This is really urgent. I am looking for some info on Daemon and Non Daemon Threads.

Any links for details would be really helpful....


TIA

Radhika
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24057
    
  13

There isn't much to know. The difference is just the setting of a flag. By definition, the JVM will exit automatically if the only threads still running are daemon threads. Most of the threads the JVM starts automatically are daemon threads; the AWT/Swing event thread is an exception. User threads are non-daemon threads by default. The thread that calls main() is a non-daemon thread as well.

That's about it.


[Jess in Action][AskingGoodQuestions]
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

By definition, the JVM will exit automatically if the only threads still running are daemon threads.


I read this too.
On linux, you may make a thread a daemon by suffixing it with a ' &'.
i.e.:
I was unsure, whether this would stop every created thread, because MyServer created only background-Threads.
But a java-Daemon is as I have seen, different from an OS-Daemon.
All Threads in background kept running nicely.


http://home.arcor.de/hirnstrom/bewerbung
Anton Golovin
Ranch Hand

Joined: Jul 02, 2004
Posts: 473
Originally posted by Radhika Gokhale:
Hi,

This is really urgent. I am looking for some info on Daemon and Non Daemon Threads.

Any links for details would be really helpful....


TIA

Radhika


You might want to check into how different operating systems treat non-daemon and daemon threads differently priority wise.


Anton Golovin<br /><i>anton.golovin@gmail.com</i><br />SCJP, SCJD, SCBCD, SCWCD
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24057
    
  13

Both Anton and Stefan seem to be confusing foreground and background processes with daemon and non-daemon threads. Other than analogies one might draw, there's no relationship whatsoever between these two pairs of concepts. Furthermore, the latter pair is a Java concept only -- the OS is completely unaware of the "daemon" flag of a thread, and it has no effect whatsoever on thread scheduling. Contrariwise, running a process in the background on Linux has no effect on the scheduling of the threads within the application.
Anton Golovin
Ranch Hand

Joined: Jul 02, 2004
Posts: 473
I learn something new every day.

Respectfully,
[ July 19, 2004: Message edited by: Anton Golovin ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Daemon and Non Daemon Thread
 
Similar Threads
deamon thread
finally code not executed
Daemon threads & non daemon Threads
tomcat don�t release port 8080 when on shot down
Daemon Thread