code: public void doShutdown() {
          long t = System.currentTimeMillis();
          LOG.info(""+name+" is going down now");
          synchronized (this){
              this.stopped = false;
              this.run = false;
          }
          while(true){
              synchronized (this){
                  if(stopped)
                      break;
              }
              try {
                  Thread.sleep(1);
              } catch (InterruptedException e) {
                  break;
              }
          }
          LOG.info(""+name+" stopped in "+(System.currentTimeMillis()-t)+" ms.");
      }
docs: Stopping worker gracefully