Why does a thread outlive the main method in Java?

前端 未结 6 2031
小蘑菇
小蘑菇 2020-12-08 14:19

I was teaching myself Java threading and I noticed something that confuses me a little. I made a class called engine implementing Runnable. The r

6条回答
  •  独厮守ぢ
    2020-12-08 14:25

    The main thread is also a user thread which is being created and its lifecylce is similar to any other user thread for that matter.
    The other user threads are not dependent on the main thread for any reason unless you set the threads as daemon threads. Once the main thread completes its work it ends(it neither ends the other user threads nor will end the process because the other user threads are running).

提交回复
热议问题