I was wondering if Java main method was a thread or not. I noticed that if the main method returns, all threads are killed. Can you explain me why this happens? Thank you in advance.
Actually the main method runs on the Main thread ! The main threads invokes your main()
All the other threads of a java application are spawned from this thread !
When you start your application the OS create a Thread for you which is the main thread (or UI thread in other contexts).
This thread just run your main method and stop.
Anyway there are two types of threads.
The main thread is a User thread.
The JVM will be stopped when all user threads are finished.
Well, it's just a "fast response" i'm pretty use you can found better answer by experts here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With