title: java threads and main thread
body: <p>what's the best way to make main thread to wait until all threads are finished?</p>
  
  <pre>
  for(int i=0;i&lt;n;i++){
     Thread t=new Thread();
     t.start();
  
  }
  
  //wait for all threads to finish
  
  </pre>