How can thread run after main method closes?

后端 未结 6 1832
借酒劲吻你
借酒劲吻你 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:13

    I want to know that even though the main method is closed How are both threads still running?

    Your main() method was run by a separate thread, which start another two threads (First ad Second). All Threads are not depend on each other, so, main thread can print the line below the starting line of other threads.

    My second question is can anybody explain me what is the difference between join method and synchronized?

    join() means waiting for a thread to complete. This is a blocker method. synchronized is a keyword to denote that, multiple thread can't access a synchronized block/method synchronously.

提交回复
热议问题