Thread question

Discussion in 'Java' started by Kaspar Minosiants, Nov 13, 2003.

  1. 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 !
     
    Kaspar Minosiants, Nov 13, 2003
    #1
    1. Advertising

  2. Kaspar Minosiants

    xarax Guest

    "Kaspar Minosiants" <> wrote in message
    news:bp01lp$1i2g3p$-berlin.de...
    >
    > 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.
     
    xarax, Nov 13, 2003
    #2
    1. Advertising

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

    "xarax" <> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
    news:9%Lsb.11387$...
    > "Kaspar Minosiants" <> wrote in message
    > news:bp01lp$1i2g3p$-berlin.de...
    > >
    > > 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.
    >
    >
     
    Kaspar Minosiants, Nov 13, 2003
    #3
  4. xarax wrote:

    > "Kaspar Minosiants" <> wrote in message
    > news:bp01lp$1i2g3p$-berlin.de...
    >
    >>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
     
    John C. Bollinger, Nov 13, 2003
    #4
  5. 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 Minosiants wrote:

    > Thanks a lot for answer !
    > I've quoted the all question !
    > There wasen't any aditional inf .
    >
    > "xarax" <> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
    > news:9%Lsb.11387$...
    >
    >>"Kaspar Minosiants" <> wrote in message
    >>news:bp01lp$1i2g3p$-berlin.de...
    >>
    >>>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.
    >>
    >>

    >
    >
    >
     
    David Zimmerman, Nov 13, 2003
    #5
  6. xarax <> coughed up the following:

    > "Kaspar Minosiants" <> wrote in message
    > news:bp01lp$1i2g3p$-berlin.de...
    >>
    >> 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
     
    Thomas G. Marshall, Nov 14, 2003
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Charles A. Lackman

    Terminating a thread from the main thread

    Charles A. Lackman, Dec 9, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    1,588
    Herfried K. Wagner [MVP]
    Dec 9, 2004
  2. pawo
    Replies:
    0
    Views:
    542
  3. Stephen Miller
    Replies:
    3
    Views:
    4,040
    Stephen Miller
    Jul 2, 2004
  4. Johanna
    Replies:
    0
    Views:
    625
    Johanna
    Oct 13, 2004
  5. vincent wehren
    Replies:
    0
    Views:
    454
    vincent wehren
    Dec 11, 2003
Loading...

Share This Page