Here are my two classes:
public class Firstclass {
public static void main(String args[]) throws InterruptedException {
System.out.println(\"Main sta
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.