code: synchronized ReadOnlyIndexReader getReadOnlyIndexReader(final boolean initCache) throws IOException
     {
        // get current modifiable index reader
        CommittableIndexReader modifiableReader = getIndexReader();
        long modCount = modifiableReader.getModificationCount();
        if (readOnlyReader != null)
        {
           if (readOnlyReader.getDeletedDocsVersion() == modCount)
           {
              // reader up-to-date
              readOnlyReader.acquire();
              return readOnlyReader;
           }
           else
           {
              // reader outdated
              if (readOnlyReader.getRefCounter() == 1)
              {
                 // not in use, except by this index
                 // update the reader
                 readOnlyReader.updateDeletedDocs(modifiableReader);
                 readOnlyReader.acquire();
                 return readOnlyReader;
              }
              else
              {
                 // cannot update reader, it is still in use
                 // need to create a new instance
                 readOnlyReader.release();
                 readOnlyReader = null;
              }
           }
        }
        // if we get here there is no up-to-date read-only reader
        // capture snapshot of deleted documents
        BitSet deleted = new BitSet(modifiableReader.maxDoc());
        for (int i = 0; i < modifiableReader.maxDoc(); i++)
        {
           if (modifiableReader.isDeleted(i))
           {
              deleted.set(i);
           }
        }
        if (sharedReader == null)
        {
           // create new shared reader
           IndexReader reader = IndexReader.open(getDirectory(), termInfosIndexDivisor);
           CachingIndexReader cr = new CachingIndexReader(reader, cache, initCache);
           sharedReader = new SharedIndexReader(cr);
        }
        readOnlyReader = new ReadOnlyIndexReader(sharedReader, deleted, modCount);
        readOnlyReader.acquire();
        return readOnlyReader;
     }
docs: Returns a read-only index reader, that can be used concurrently with
  other threads writing to this index. The returned index reader is
  read-only, that is, any attempt to delete a document from the index
  will throw an <code>UnsupportedOperationException</code>.
  
  @param initCache if the caches in the index reader should be initialized
  before the index reader is returned.
  @return a read-only index reader.
  @throws IOException if an error occurs while obtaining the index reader.