• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Manoj Mani
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • 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);
 
megha joshi
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
  • 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
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • 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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic