Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (13.1k points)

Can anyone help me to understand the below code for join and break. I didn't get the part for Join() and break.

Thread t1 = new Thread(new EventThread("e1"));

t1.start();

Thread t2 = new Thread(new EventThread("e2"));

t2.start();

while (true) {

   try {

      t1.join();

      t2.join();

      break;

   } catch (InterruptedException e) {

      e.printStackTrace();

   }

}

1 Answer

0 votes
by (26.7k points)

Basically, the main thread created the threads t1 and t2 and they are started running in parallel. Whereas, t1.join() will wait for the thread t1 to finish, when it finished t1.join() will return the main thread. Similarly, with the t2 thread also.

I hope this will help.

Want to know more about Java? Prefer this tutorial on Java Tutorial.

Want to become a Java Expert? Join Java Certification now!!

Related questions

0 votes
1 answer
asked Mar 8, 2021 in Java by dante07 (13.1k points)
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...