Is the main java method a thread?

I was wondering if the main Java method is a stream or not. I noticed that if the main method returns, all threads will be killed. Can you explain to me why this is happening? Thank you in advance.

+3
source share
3 answers

Actually the main method works in the main thread! main threads invokes your main()

All other java application threads are generated from this thread!

+3
source

When you start the application, the OS creates a Thread for you, which is the main thread (or the user interface thread in other contexts).

This thread just starts your method mainand stops. In any case, there are two types of streams.

  • Custom thread

main thread - User thread. JVM , .

, " ", , .

+1

, . - .

Daemon, , .

, , ..

, , . , main - void, .: D

But without delaying the penalty, if you create one or more user threads that run for a long time, and you do not use the method join()in your method main, then even if the main method ends, other threads are still executed if their method has run()not stopped execution.

0
source

All Articles