Thread Join using join() method
Java Thread Join using join() method
In this part 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.
- public void join() throws InterruptedException
- public void join(long miliseconds) throws InterruptedException
class JoinDemo extends Thread{ public void run(){ for(int i=1;i<=5;i++){ try{ Thread.sleep(500); }catch(Exception e){ System.out.println(e); } System.out.println("Dinesh on Java "+i); } } public static void main(String args[]){ JoinDemo t1 = new JoinDemo(); JoinDemo t2 = new JoinDemo(); JoinDemo t3 = new JoinDemo(); t1.start(); try{ t1.join(); }catch(Exception e){ System.out.println(e); } t2.start(); t3.start(); } }
post a comment