@Override
  public synchronized void close() {
    if (isClosed()) {
      return;
    }
    setIsClosed(true);
    if (inferenceWorker != null) {
      try {
        inferenceWorker.releaseInferenceResources(MSECS_TO_WAIT_FOR_CLOSE);
      } catch (IOException ioe) {
        throw new RuntimeException(ioe.getMessage(), ioe);
      }
    }
  }