• 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

Tell me the output and how u go it please....

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class A extends Thread
{
A()
{
setDaemon(true);
}
public void run()
{
(new B()).start();
try
{
Thread.sleep(60000);
}
catch (InterruptedException x)
{
}
System.out.println(�A done�);
}

class B extends Thread
{
public void run()
{
try
{
Thread.sleep(60000);
}
catch (InterruptedException x)
{
}
System.out.println(�B done�);
}
}

public static void main(String[] args)
{
(new A()).start();
}
} //Please tell me the use of setDaemon(true);
 
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just a suggestion...for finding out what setDeamon does google is best...I got this when I queried for it

setDaemon
public final void setDaemon(boolean on)Marks this thread as either a daemon thread or a user thread. The Java Virtual Machine exits when the only threads running are all daemon threads.
This method must be called before the thread is started.

--------------------------------------------------------------------
The the second thing I would suggest is running the code in NetBeans...first commenting out this setDaemon and then uncommenting out the setDaemon...and then looking into the defination I found above.

Wow...that tells me that the output would be nothing in case of this question, bcoz the JVM exited as only the daemon thread was running. If the setDaemon would not have been called, then I would have got

"A done" and "B done" printed in undetermined order.

Good luck
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good response megha joshi. It's a good idea to use the java API to find out about such things (keep an http link to it or copy the Java docs directly from Sun's website).
 
Clowns were never meant to be THAT big! We must destroy it with 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