public void close() {
    dataManager.removeListener(this);
    taskList.removeChangeListener(this);
    repositoryManager.removeListener(this);

    maintainIndexJob.cancel();
    try {
      maintainIndexJob.join();
    } catch (InterruptedException e) {
      // ignore
    }

    Lock writeLock = indexReaderLock.writeLock();
    writeLock.lock();
    try {
      synchronized (this) {
        if (indexReader != null) {
          try {
            indexReader.close();
          } catch (IOException e) {
            // ignore
          }
          indexReader = null;
        }
      }
      if (directory != null) {
        try {
          directory.close();
        } catch (IOException e) {
          StatusHandler.log(
              new Status(
                  IStatus.ERROR,
                  TasksIndexCore.ID_PLUGIN,
                  "Cannot close index: " + e.getMessage(),
                  e)); //$NON-NLS-1$
        }
      }
    } finally {
      writeLock.unlock();
    }
  }