Meaningless Drivel is fun!*
The moose likes Threads and Synchronization and the fly likes user threads and daemon threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "user threads and daemon threads" Watch "user threads and daemon threads" New topic
Author

user threads and daemon threads

Saral Saxena
Ranch Hand

Joined: Apr 22, 2011
Posts: 202

Hi Folks,

Please tell tell me whats the difference between user threads and daemon threads technically..? What I have discovered that A daemon thread is simply a background thread that is subordinate to the thread that creates it, so when the thread that created it ends, the daemon thread dies with it...!
Saral Saxena
Ranch Hand

Joined: Apr 22, 2011
Posts: 202

Hi fOLKS,

Please advise on that ..!!
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18545
    
  40

Saral Saxena wrote: What I have discovered that A daemon thread is simply a background thread that is subordinate to the thread that creates it, so when the thread that created it ends, the daemon thread dies with it...!


Almost..... It's more like Daemon threads serve User threads, when all the User threads terminates, the JVM exits. It is not possible to have a running program with nothing but Daemon threads.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Saral Saxena
Ranch Hand

Joined: Apr 22, 2011
Posts: 202

As the user threads have some priority do daemon threads also have priority..?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18545
    
  40

Saral Saxena wrote:As the user threads have some priority do daemon threads also have priority..?



User threads and Daemon threads are the same in every other way. The only thing to remember is that the JVM will exit if there is nothing but Daemon threads left.

Henry
Saral Saxena
Ranch Hand

Joined: Apr 22, 2011
Posts: 202

Hi Henry,
Thanks a lot for the explanation in java we can make the user thread to act as a daemon thread through method but is reverse is possible let say Can we make any daemon thread to act as a user thread..?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18545
    
  40

Saral Saxena wrote:
Thanks a lot for the explanation in java we can make the user thread to act as a daemon thread through method but is reverse is possible let say Can we make any daemon thread to act as a user thread..?



Not sure what you mean. There is no "user thread to act as a daemon thread" or "daemon thread to act as a user thread". A thread is either one or the other. It can be set with the setDaemon() method, and it must be done before the thread is started.

Henry
 
 
subject: user threads and daemon threads
 
Similar Threads
Daemon thread
Query about Daemon thread.
What is a daemon thread?
Thread
DAEMON THREAD