• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Daemon Thread

 
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
author and iconoclast
Posts: 24206
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
What's gotten into you? Could it be this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic