Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Threads and Synchronization and the fly likes Daemon thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Daemon thread" Watch "Daemon thread" New topic

Daemon thread

Sivasubramaniam.N Natarajan.P

Joined: Mar 14, 2007
Posts: 1
what you mean by a Daemon? give an example , anybody is there to share this question?
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Hi, welcome to the ranch!

Read through the JavaDoc for Thread and see what it says about Daemon. It's kind of confusing, so come back and tell us what you think it said or where it left you confused.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
pradeep boora

Joined: Oct 16, 2006
Posts: 1
daemon thread are threads which keep on running in background.
For example main thread( for main method ) is daemon thread. It initiates another user threads
saikrishna cinux
Ranch Hand

Joined: Apr 16, 2005
Posts: 689
deamon threads are low priority threads they run internally when JVM starts

SCJP 1.4
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
deamon threads are low priority threads they run internally when JVM starts

No. While there are daemon threads that are low priority, and which are started when the JVM starts, any thread can be a daemon. Its priority and how it got started have nothing to do with whether or not it's a daemon.
[ March 16, 2007: Message edited by: Ulf Dittmer ]
Henry Wong

Joined: Sep 28, 2004
Posts: 20532

Since the original poster doesn't seem to want to take a guess at what a Daemon thread is, let's clarify this...

For the most part, there is no real difference between a daemon thread and a user thread. They both are started with the start() method, they both terminate when the run() method terminates, they both can use synchronization, condition variables, and other threading features, you may set a priority with either, you may deadlock them, etc. etc.

The difference is in how the JVM behaves with daemon threads. A daemon thread is assumed to support user threads. So when there are no more user threads running in the JVM -- meaning only daemon threads are running -- then the JVM terminates. That's it !!

Also... the main thread (thread that calls the main method) is definitely not a daemon thread.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
I agree. Here's the link:
subject: Daemon thread
It's not a secret anymore!