• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Thread Question.

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,all:
Given:

A. A done
B. B done
C. A done
B done
D. B done
A done
E. There is no exception that the application will print anything.
F. The application outputs �A done� and �B done�, in no guaranteed order.
The given answer is E.
As I compile and run it, it will print nothing. What's the use for setDeamon() method here? Why it print nothing after sleeping duration?

Thanks,
Roger
[ August 30, 2003: Message edited by: Roger Zhao ]
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Roger,
Please use UBB Code to ident the code.
This is from Thinking in Java by Bruce Eckel:


Daemon threads
A �daemon� thread is one that is supposed to provide a general service in the background as long as the program is running, but is not part of the essence of the program. Thus, when all of the non-daemon threads complete, the program is terminated. Conversely, if there are any non-daemon threads still running, the program doesn�t terminate. There is, for instance, a thread that runs main( ). Comment
You can find out if a thread is a daemon by calling isDaemon( ), and you can turn the �daemonhood� of a thread on and off with setDaemon( ). If a thread is a daemon, then any threads it creates will automatically be daemons.


Try coomenting out "setDaemon(true);" and you will see the difference.
 
Roger Zhao
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jose, base on your explanation in this case, both new A() & new B() are deamon threads. So if run it, the program terminates directly without printing anything.right?
Pls correct me if I am wrong.
 
"How many licks ..." - I think all of this dog's research starts with these words. Tasty tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic