code: public LuceneIndex current() {
      // Reopen index searcher if necessary.
      IndexSearcher oldSearcher = index.searcher.get();
  
      try {
        // Guarded lock, to prevent us from unnecessarily synchronizing every time.
        if (oldSearcher == null) {
          synchronized (this) {
            if ((oldSearcher = index.searcher.get()) == null) {
              IndexSearcher newSearcher = new IndexSearcher(index.directory);
              index.searcher.compareAndSet(null, newSearcher);
            }
          }
  
          // Yes it's open, but is it stale?
        } else {
          DirectoryReader directoryReader = DirectoryReader.openIfChanged(index.directory);
          if (null != directoryReader) {
            index.directory = directoryReader;
  
            synchronized (this) {
              IndexSearcher newSearcher;
              try {
                newSearcher = new IndexSearcher(directoryReader);
              } catch (AlreadyClosedException e) {
                log.warning("Old index reader could not be reopened. Opening a new one...");
                newSearcher = new IndexSearcher(DirectoryReader.open(index.writer, true));
              }
              if (!index.searcher.compareAndSet(oldSearcher, newSearcher)) {
                // Someone beat us to it. No worries.
                log.finest("Another searcher was already open for this index. Nothing to do.");
              }
            }
          }
        }
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
  
      return index;
    }
docs: This has pool semantics, so consider making this a checkin/checkout style operation.