title: Java. Join threads in order of completion and run a kind of a hook after each join
body: <p>I want to be able to join each thread at once it finished its job. In the code example below main thread will wait as long as each thread will run by their order in the list and only then next thread will be joined.</p>
  
  <pre><code>    List&lt;Thread&gt; threads = new ArrayList&lt;&gt;();
  
      threads.add(new Thread(new Worker(), "T1"));
      threads.add(new Thread(new Worker(), "T2"));
      threads.add(new Thread(new Worker(), "T3"));
  
      threads.forEach(Thread::start);
  
      threads.forEach(thread -&gt; {
          try {
              thread.join();
              someHook();
          } catch (InterruptedException e) {
              e.printStackTrace();
          }
      });
  </code></pre>