title: communication between threads in java: stopping a thread if another thread has finished
body: <p>How can I make a thread run only if the other thread is running too, meaning, if I return from run in one thread, then I want the other to stop running too, 
  my code looks something like this:</p>
  
  <pre><code>ClientMessageHandler clientMessagehandler = new ClientMessageHandler();
  ServerMessageHandler serverMessagehandler = new ServerMessageHandler();
  Thread thread1 = new Thread(serverMessagehandler);
  Thread thread2 = new Thread(clientMessagehandler);
  thread2.start();
  thread1.start();
  </code></pre>
  
  <p>I want to cause <code>thread1</code> to stop running when <code>thread2</code> stops running.</p>
  
  <p>edit: detecting when <code>thread2</code> stops running in order stop <code>thread1</code> from running, and not how to stop <code>thread1</code> from running 
  thanks</p>