Query:What does main thread do in java?

J

Jack Dowson

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!
 
A

Andrew Thompson

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
 
Joined
May 2, 2007
Messages
6
Reaction score
0
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...
 
T

Thomas Fritsch

Jack said:
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)
 
P

Patricia Shanahan

Thomas said:
Jack said:
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
 
J

Jack Dowson

Patricia Shanahan 写é“:
Thomas said:
Jack said:
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.
 
T

Thomas Fritsch

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).
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top