Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Daemon Thread  RSS feed

 
Mark Henryson
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Output:
--------
null
null
Tue Aug 30 06:14:49 EDT 2005
Tue Aug 30 06:14:49 EDT 2005
Tue Aug 30 06:14:49 EDT 2005
Tue Aug 30 06:14:49 EDT 2005
Tue Aug 30 06:14:49 EDT 2005
Tue Aug 30 06:14:49 EDT 2005
Tue Aug 30 06:14:49 EDT 2005
Tue Aug 30 06:14:49 EDT 2005

Why the first two value is NULL. What is the use Daemon thread? What is the role of setDaemon(true)? What will happen if setDaemon(false)?
I had tries setDaemon(false), but no differences in the output.
[ August 30, 2005: Message edited by: Mark Henryson ]
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless you have a multi-processor machine, the two threads have to take it in turns to run. The first two values are null because the main thread has the processor and ds will not have been set until the child thread gets the processor.
Even if you have a multiprocessor machine, you may still get some nulls, because there is some initialisation of the child thread to be done before the run method is called.

Check out the API docs for what a daemon thread is.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A Daemon is a "background" thread that will not prevent a program from ending.

In the following example, two threads are created. One has an infinite loop and the other has a finite loop. But the thread with the infinite loop is a Daemon, so it does not prevent the program from ending after the non-Daemon thread completes.
 
Patrick van Zandbeek
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You already have 2 threads about threads moved to the threads forum, this very day. Since you don't seem to understand why they were moved let me explain:
The threads forum is for threads about discussing threads and any threads related topics deserve their own thread in there.

That way, you save the nice people around here the work of manually moving them and you have a much bigger chance of the right people reading your question so they can help you. Everyone wins that way!
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark --

Thread questions go in the "Threads and Synchronization" forum. I've already moved several of your topics from today to that forum -- please post any additional Threads questions over there. Thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!