• 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

threads

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello there
can anybody tell me exactly "setdaemon(true)" means in thread
i got this from dan'sclass A extends Thread {
public void run() {
synchronized (this) {
try {wait();} catch (InterruptedException ie){}
}}
public static void main(String[] args) {
A a1 = new A();
a1.setDaemon(true);
long startTime = System.currentTimeMillis();
a1.start();
System.out.print(System.currentTimeMillis() - startTime + ",");
i'd appreciated
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Marking a thread as a "daemon" thread means that the JVM no longer waits for it to complete before exiting. Your Java application terminates when there are no longer and "non-daemon" threads executing. When the last non-dameon thread completes, the application exits. If there is one or more "daemon" threads running when that occurs, those threads automatically quit.
Daemon threads are great for "support" tasks that constantly run. Garbage collection is a perfect example. It's something that runs continuously (or periodically) but, when all of the other processing is completed, there's no reason for garbage collection to continue. That's a perfect use for a daemon thread.
I hope that helps,
Corey
 
Ranch Hand
Posts: 271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's also important to note that even when the main thread is done , if you still have non-daemon threads running , the app will still continue to run until those non-daemon threads are done.If , however , the main thread is done , and the non-daemon threads are also done , all remaining daemon threads are terminated by the JVM.
jeff mutonho
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic