Home Tutorial Java Thread Java Thread Join

 
 

Share on Google+Share on Google+
Java Thread Join
Posted on: November 7, 2009 at 12:00 AM
Advertisement
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
Advertisement

Related Tags for Java Thread Join:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 7, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com