How can thread run after main method closes?

后端 未结 6 1831
借酒劲吻你
借酒劲吻你 2021-02-13 22:41

Here are my two classes:

public class Firstclass {
    public static void main(String args[]) throws InterruptedException {
        System.out.println(\"Main sta         


        
6条回答
  •  被撕碎了的回忆
    2021-02-13 23:16

    Your main thread is not closed -

          // ...
          System.out.println("Main close...");
          // <--- Your main method is here while all the other threads complete (sort of).
         }
    

    On part 2 of your question - There is no connection between join and synchronized. They are almost opposite.

    • join - Wait for the thread to complete before resuming.
    • synchronized - Only one thread can enter here, all others must wait.

提交回复
热议问题