listenerThread.join(); listenerStopping = false;
listenerThread.join(3000); if (listenerThread.isAlive()) { listenerThread.interrupt(); listenerThread.join(); } stopping = false;
   protected void stopListener()   {      listenerStopping = true;            //The listener loop may not be waiting, so interrupting the thread will      //not necessarily work, thus leaving it hanging      //so we use the listenerStopping variable too      listenerThread.interrupt();      try      {         listenerThread.join();         listenerStopping = false;      }      catch (InterruptedException e)      {         log.error("Thread interrupted", e);      }               }