If the code spawning threads is not put within try-catch block in the main() method, the main thread would finish executing before the child thread; however, the program would run until the child thread completes
Can anyone please explain how this should be implemented and why it does what it does? Thanks, Gian Franco Casula
My GUESS is that the try-catch block would somehow (without blocking the application code from executing past it) block the main thread from exiting until all threads creating within it terminate. My experience with threading is limited though so I may be wrong in this
Gian, There appears to be more than this than you're letting on. Just putting a block of code within a try/catch block isn't going to prevent it from moving forward. Perhaps there was something else the author mentioned, such as a join method invocation, or something else. It seems that your statement is taken very "out of context" and, in order to make any sort of intelligible reply, we need to be given more information. Corey
Hi, It supposedly has to come from Programmer's Guide to Java Certification by Mughal according to some notes I got from JavaRanch topic: Ashraf Fouad's concentrated guide to SCJP I don't have the book now so I can't check the context of the statment. Anyone an idea? Thanks for you help, Gian Franco
As far as I know the running program will wait only for user threads. If in the main method you start a deamon thread, your program won't wait for it. I don't see what the try/catch block has to do with anything. It all comes down to user vs. deamon thread. Maybe it's all out of context as Corey said ... L.
This is probably in ref. with the execution of user threads vs daemon threads, as explained in section 9.2 of "A Programmer's Guide to Java Certification Second Edition" by K Mughal and R Rasmussen If it does not violate any copyright laws, I can quote the paragraph.