code: public static void waitThreadTermination(Thread thread) {
      while (thread != null && thread.isAlive()) {
        thread.interrupt();
        try {
          thread.join();
        } catch (InterruptedException e) {
        }
      }
    }
docs: A realiable way to wait for the thread termination
  @param thread thread to wait for