Home Tutorial Java Thread Java Thread Join

 
 

Java Thread Join
Posted on: November 7, 2009 at 12:00 AM
In this segment of tutorial we will learn how to use the join method in the Thread.Then We will create an example of Thread with the use of join method.

  • Java Join method join the next thread at the end of the current thread
  • After current thread stops execution then next thread executes.


Java Join Thread Example

public class join implements Runnable {

	@Override
	public void run() {
		for (int x = 1; x <= 3; x++) {
			System.out.println("this is thread "
					+ Thread.currentThread().getName());
		}
	}

	public static void main(String[] args) throws Exception {
		join j1 = new join();
		Thread t1 = new Thread(j1, "1");
		Thread t2 = new Thread(j1, "2");
		Thread t3 = new Thread(j1, "3");
		t1.start();
		t1.join();
		t2.start();
		t3.start();
	}
}

Output :

this is thread 1 this is thread 1 this is thread 1 this is thread 3 this is thread 2 this is thread 2 this is thread 2 this is thread 3 this is thread 3

Related Tags for Java Thread Join:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.