Friday, April 12, 2019

multithreading with join method


public class cl extends Thread{ 
 public void run(){ 
  for(int i=1;i<=3;i++){ 
   try{ 
    Thread.sleep(500); 
   }catch(Exception e){System.out.println(e);} 
  System.out.println(i); 
  } 
 } 
public static void main(String args[]){ 
 cl t1=new cl(); 
 cl t2=new cl(); 
 cl t3=new cl(); 
 t1.start(); 
 try{ 
  t1.join(); 
 }catch(Exception e){System.out.println(e);} 
 
 t2.start(); 
 t3.start(); 
 } 
}


$javac cl.java
$java -Xmx128M -Xms16M cl
1
2
3
1
1
2
2
3 
3 

No comments:

Post a Comment