What is the result?
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.
Daemon threads only run as long as there are User Threads (non-daemon threads) running.
Once you start thread A in the main method, the 'main thread' (which is the only remaining user thread) ends. At that point the JVM shuts down the daemon thread. This happens before Thread A has the opportunity to print its own output or create thread B.
If you comment out the setDaemon() line, you will probably see it prints out the output lines for both A & B threads. In that situation, you are not creating a Daemon thread. Both A & B are user threads.
Nomaan Butt
Ranch Hand
Joined: Oct 19, 2011
Posts: 54
posted
0
call the sleep() method just after you call the start() method of Thread A, this will validate Keith's reply