Thread question

K

Kaspar Minosiants

Hi !

i've been perplexed about a thread life cycle

there is question from preparation to SCJP 1.4

------------------------------------------------------

which of the following is true regarding main Thread

1. It's the thread from which other child threads wil be spawned
2. It must be the last thread to finish execution. When the main thread
stops , the program terminates.
3. It has highest priority
4. main is not a thread .

-------------------------------------------------------

correct answers are 1 & 2
i'm curious about the second answer [ When the main thread stops , the
program terminates. ]
is it realy true ?

Thanks a lot !
 
X

xarax

Kaspar Minosiants said:
Hi !

i've been perplexed about a thread life cycle

there is question from preparation to SCJP 1.4

------------------------------------------------------

which of the following is true regarding main Thread

1. It's the thread from which other child threads wil be spawned
2. It must be the last thread to finish execution. When the main thread
stops , the program terminates.
3. It has highest priority
4. main is not a thread .

-------------------------------------------------------

correct answers are 1 & 2
i'm curious about the second answer [ When the main thread stops , the
program terminates. ]
is it realy true ?

Thanks a lot !

#2 is incorrect. The main thread can finish before
other non-daemon threads and the application will
continue to execute.

However, IF #2 was phrased within the context of
the main(String[]) method calling System.exit(0),
then it would be correct.
 
K

Kaspar Minosiants

Thanks a lot for answer !
I've quoted the all question !
There wasen't any aditional inf .

xarax said:
Kaspar Minosiants said:
Hi !

i've been perplexed about a thread life cycle

there is question from preparation to SCJP 1.4

------------------------------------------------------

which of the following is true regarding main Thread

1. It's the thread from which other child threads wil be spawned
2. It must be the last thread to finish execution. When the main thread
stops , the program terminates.
3. It has highest priority
4. main is not a thread .

-------------------------------------------------------

correct answers are 1 & 2
i'm curious about the second answer [ When the main thread stops , the
program terminates. ]
is it realy true ?

Thanks a lot !

#2 is incorrect. The main thread can finish before
other non-daemon threads and the application will
continue to execute.

However, IF #2 was phrased within the context of
the main(String[]) method calling System.exit(0),
then it would be correct.
 
J

John C. Bollinger

xarax said:
Hi !

i've been perplexed about a thread life cycle

there is question from preparation to SCJP 1.4

------------------------------------------------------

which of the following is true regarding main Thread

1. It's the thread from which other child threads wil be spawned
2. It must be the last thread to finish execution. When the main thread
stops , the program terminates.
3. It has highest priority
4. main is not a thread .

-------------------------------------------------------

correct answers are 1 & 2
i'm curious about the second answer [ When the main thread stops , the
program terminates. ]
is it realy true ?

Thanks a lot !


#2 is incorrect. The main thread can finish before
other non-daemon threads and the application will
continue to execute.

However, IF #2 was phrased within the context of
the main(String[]) method calling System.exit(0),
then it would be correct.

#1 Is also incorrect, because child threads may themselves spawn
threads. So although the main thread is an ancestor of all other
threads in the application, it is not necessarilly all other threads'
parent.

The main thread is only special in that it is started by the JVM instead
of by application code.


John Bollinger
(e-mail address removed)
 
D

David Zimmerman

The main thread is just the thread that enters the main(String[])
method. Any threads that are started by the main thread can start child
threads of their own. There is no parent-child relationship between the
threads, anyway.

Kaspar said:
Thanks a lot for answer !
I've quoted the all question !
There wasen't any aditional inf .

Hi !

i've been perplexed about a thread life cycle

there is question from preparation to SCJP 1.4

------------------------------------------------------

which of the following is true regarding main Thread

1. It's the thread from which other child threads wil be spawned
2. It must be the last thread to finish execution. When the main thread
stops , the program terminates.
3. It has highest priority
4. main is not a thread .

-------------------------------------------------------

correct answers are 1 & 2
i'm curious about the second answer [ When the main thread stops , the
program terminates. ]
is it realy true ?

Thanks a lot !

#2 is incorrect. The main thread can finish before
other non-daemon threads and the application will
continue to execute.

However, IF #2 was phrased within the context of
the main(String[]) method calling System.exit(0),
then it would be correct.
 
T

Thomas G. Marshall

xarax said:
Kaspar Minosiants said:
Hi !

i've been perplexed about a thread life cycle

there is question from preparation to SCJP 1.4

------------------------------------------------------

which of the following is true regarding main Thread

1. It's the thread from which other child threads wil be spawned
2. It must be the last thread to finish execution. When the main
thread stops , the program terminates.
3. It has highest priority
4. main is not a thread .

-------------------------------------------------------

correct answers are 1 & 2
i'm curious about the second answer [ When the main thread stops ,
the program terminates. ]
is it realy true ?

Thanks a lot !

#2 is incorrect. The main thread can finish before
other non-daemon threads and the application will
continue to execute.

In 8 years of java threading, I've never been /completely completely/ sure
of the details of when the main thread finishes. Which of the following
details is true:

(Forget the cause of program termination for a sec.)

1. The main thread terminates when the main()
method exits
or
2. The main thread stays alive even when the main()
method exits, until the program terminates (by some
other means).

However, IF #2 was phrased within the context of
the main(String[]) method calling System.exit(0),
then it would be correct.

or the exit() method of the Runtime class. And either must not be forbidden
by the security manager.

http://java.sun.com/docs/books/jls/second_edition/html/execution.doc.html#44862
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

java thread question 9
Question on Daemon thread 6
streaming problem and thread freeze 9
Question on homework.... 1
Thread-question 27
Thread Tkinter problem 4
Is code a safe thread? 4
Thread locking question. 5

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top