code: public void waitEnd(final long... timeout) {
  
          long start = System.currentTimeMillis();
          if (timeout.length == 1) {
              start += timeout[0];
          } else {
              start += DEFAULT_TIME_OUT;
          }
  
          while (!this.hasRun.get()) {
              try {
                  Thread.sleep(SLEEP_TIME);
              } catch (final InterruptedException e) {
                  break;
              }
              if (System.currentTimeMillis() > start) {
                  break; // Break the loop after 1s to avoid freezing the thread
              }
          }
  
      }
docs: Wait the end of the runnable.
  
  @param timeout the maximum to wait to avoid to freeze the thread