Without multithreading, when a method is called, the next line of code does not execute until the method returns.
doThis(); //then when method returns... doThis(); //then when method returns... doThis(); //then when method returns... finish();
But with multithreading, a separate process can start in its own thread, allowing the calling thread to continue on with what it's doing.
startNewThread(); //then as soon as start call returns... finish();
In this case, even after finish() returns, the new thread's run method can continue executing separately. As long as the new thread is not a daemon, this would keep the program alive.
Basically a daemon thread is a background process whose completion is not required for the program to end.
Monica Dharwad
Greenhorn
Joined: Aug 14, 2006
Posts: 8
posted
0
Thanks a lot for the reply. It explains the concept very well.
When main() ends, that may or may not be the end of the program i didnt get this line.. Because i think when main() ends it will surely terminate your program as it is main thread. please clear my doubt
Because i think when main() ends it will surely terminate your program as it is main thread.
The program will terminate if all non-daemon threads have terminated. If a GUI is visible then there will be several non-daemon threads, e.g. the event handling thread. In many applications the main method terminates very quickly, right after constructing the GUI. [ August 16, 2006: Message edited by: Ulf Dittmer ]