Query:What does main thread do in java?

Discussion in 'Java' started by Jack Dowson, May 4, 2007.

  1. Jack Dowson

    Jack Dowson Guest

    Hello Everybody:
    I'm new to java.
    I want to know what does main thread do when a java program is excuting!
    Thanks in advance!
    Jack Dowson, May 4, 2007
    #1
    1. Advertising

  2. Jack Dowson wrote:
    ...
    >I'm new to java.


    A good group for those new to Java, is
    comp.lang.java.help
    but even there..

    >I want to know what does main thread do when a java program is excuting!


    you will be expected to read your textbooks, do a
    bit if googling, and ask a smart question.
    <http://www.catb.org/~esr/faqs/smart-questions.html>

    --
    Andrew Thompson
    http://www.athompson.info/andrew/

    Message posted via JavaKB.com
    http://www.javakb.com/Uwe/Forums.aspx/java-general/200705/1
    Andrew Thompson, May 4, 2007
    #2
    1. Advertising

  3. Jack Dowson

    pundeerd

    Joined:
    May 2, 2007
    Messages:
    6
    The main thread is non daemon thread is invoked by JVM to execute the application.It is responsible for pushing/pulling values of variables to/from stack to do intermediate calculations,managing Program Counter within JVM.

    Read more...
    pundeerd, May 4, 2007
    #3
  4. Jack Dowson wrote:
    > I'm new to java.
    > I want to know what does main thread do when a java program is excuting!

    It calls your method
    static void main(String[] args)

    --
    Thomas
    Thomas Fritsch, May 4, 2007
    #4
  5. Thomas Fritsch wrote:
    > Jack Dowson wrote:
    >> I'm new to java.
    >> I want to know what does main thread do when a java program is excuting!

    > It calls your method
    > static void main(String[] args)
    >


    and therefore runs the main method itself, and everything called from
    it, directly or indirectly.

    It is perhaps better to think about things that it does NOT run:

    Administrative work, such a garbage collection, that the JVM chooses to
    do from another thread.

    Event handling.

    Anything that you put in a different thread, by creating a Thread and
    calling its start() method.

    Patricia
    Patricia Shanahan, May 4, 2007
    #5
  6. Jack Dowson

    Jack Dowson Guest

    Patricia Shanahan 写é“:
    > Thomas Fritsch wrote:
    >> Jack Dowson wrote:
    >>> I'm new to java.
    >>> I want to know what does main thread do when a java program is excuting!

    >> It calls your method
    >> static void main(String[] args)
    >>

    >
    > and therefore runs the main method itself, and everything called from
    > it, directly or indirectly.
    >
    > It is perhaps better to think about things that it does NOT run:
    >
    > Administrative work, such a garbage collection, that the JVM chooses to
    > do from another thread.
    >
    > Event handling.
    >
    > Anything that you put in a different thread, by creating a Thread and
    > calling its start() method.
    >
    > Patricia

    Really thank you!
    That means sometimes the program does not terminate when main thread is
    over?Right?

    Dowson.
    Jack Dowson, May 4, 2007
    #6
  7. Jack Dowson wrote:
    [...]
    > That means sometimes the program does not terminate when main thread is
    > over?Right?

    Yes, right!
    Actually this is how all applications with a GUI (graphical user interface)
    work. Their main thread usually finishes after less than one second. But
    other threads continue for minutes (or even hours).

    --
    Thomas
    Thomas Fritsch, May 4, 2007
    #7
    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,539
    Herfried K. Wagner [MVP]
    Dec 9, 2004
  2. Andy Howells
    Replies:
    4
    Views:
    16,043
    HiteshMehra
    Aug 21, 2007
  3. Froggy
    Replies:
    5
    Views:
    10,248
    Jose Rubio
    Dec 5, 2003
  4. Hugo
    Replies:
    4
    Views:
    1,745
    Logan Shaw
    Mar 27, 2008
  5. Replies:
    2
    Views:
    448
Loading...

Share This Page