Is this JWhiz thread question wrong?
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
A) It is the thread from which other "child" threads will be spawned.
B) It must be the last thread to finish execution. When the main thread stops, the program terminates.
C) It has the highest priority.
D) main is not a thread.
Answer: A, B
I knew answer A but then I was lost. Why must the main thread be the last thread to finish execution? I thought unless a spawned thread was set as a Daemon thread, that the main thread could terminate but any other spawned threads could keep going?
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Rob
Rob
SCJP 1.4
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Younes
By constantly trying one ends up succeeding. Thus: the more one fails the more one has a chance to succeed.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
This is the output from your code
in main
in new Thread
Does it mean that the main thread had died? Why?
If you change your code to this.
Here is the output:
in main
in main
in main
in new Thread// this is line 674 of the output
in main
in main
in main
in main
There is something that I must have not catch, because I don't understand your conclusion.
Do you have an url where it is explained???
Again thx a lot
Younes
By constantly trying one ends up succeeding. Thus: the more one fails the more one has a chance to succeed.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Originally posted by Younes Essouabni:
I am not sure of that. Can a spawned thread die after the main. I don't think it. Could you please explain with some code???
Yes.
Rob

Rob
SCJP 1.4
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Originally posted by Younes Essouabni:
I am not sure of that. Can a spawned thread die after the main. I don't think it. Could you please explain with some code???
A spawned thread may die before or after the main thread. They are independent. The program goes on until the last non-daemon thread is finished, regardless whether it is the main thread or a spawned thread.
JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Younes
By constantly trying one ends up succeeding. Thus: the more one fails the more one has a chance to succeed.
| When you have exhausted all possibilities, remember this: you haven't - Edison. Tiny ad: Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |









