org.apache.lucene.search

## Class NRTManagerReopenThread

- java.lang.Object
- - java.lang.Thread
  - - org.apache.lucene.search.NRTManagerReopenThread

- All Implemented Interfaces:
    Closeable, AutoCloseable, Runnable, NRTManager.WaitingListener

      public class NRTManagerReopenThread
      extends Thread
      implements NRTManager.WaitingListener, Closeable

  Utility class that runs a reopen thread to periodically reopen the NRT searchers in the provided `NRTManager`.

  Typical usage looks like this:

         ... open your own writer ...

         NRTManager manager = new NRTManager(writer);

         // Refreshes searcher every 5 seconds when nobody is waiting, and up to 100 msec delay
         // when somebody is waiting:
         NRTManagerReopenThread reopenThread = new NRTManagerReopenThread(manager, 5.0, 0.1);
         reopenThread.setName("NRT Reopen Thread");
         reopenThread.setPriority(Math.min(Thread.currentThread().getPriority()+2, Thread.MAX_PRIORITY));
         reopenThread.setDaemon(true);
         reopenThread.start();

  Then, for each incoming query, do this:

         // For each incoming query:
         IndexSearcher searcher = manager.get();
         try {
           // Use searcher to search...
         } finally {
           manager.release(searcher);
         }

  You should make changes using the `NRTManager`; if you later need to obtain a searcher reflecting those changes:

         // ... or updateDocument, deleteDocuments, etc:
         long gen = manager.addDocument(...);

         // Returned searcher is guaranteed to reflect the just added document
         IndexSearcher searcher = manager.get(gen);
         try {
           // Use searcher to search...
         } finally {
           manager.release(searcher);
         }

  When you are done be sure to close both the manager and the reopen thrad:

         reopenThread.close();
         manager.close();

  WARNING: This API is experimental and might change in incompatible ways in the next release.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class java.lang.Thread

      `Thread.State, Thread.UncaughtExceptionHandler`

  - ### Field Summary

    - ### Fields inherited from class java.lang.Thread

      `MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `NRTManagerReopenThread(NRTManager manager, double targetMaxStaleSec, double targetMinStaleSec)` Create NRTManagerReopenThread, to periodically reopen the NRT searcher.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()`
    `void` | `run()`
    `void` | `waiting(long targetGen)`

    - ### Methods inherited from class java.lang.Thread

      `activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield`

    - ### Methods inherited from class java.lang.Object

      `equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### NRTManagerReopenThread

          public NRTManagerReopenThread(NRTManager manager,
                                double targetMaxStaleSec,
                                double targetMinStaleSec)

      Create NRTManagerReopenThread, to periodically reopen the NRT searcher.
      Parameters:
        `targetMaxStaleSec` - Maximum time until a new reader must be opened; this sets the upper bound on how slowly reopens may occur
        `targetMinStaleSec` - Mininum time until a new reader can be opened; this sets the lower bound on how quickly reopens may occur, when a caller is waiting for a specific indexing change to become visible.

  - ### Method Detail

    - #### close

          public void close()

      Specified by:
        `close` in interface `Closeable`
      Specified by:
        `close` in interface `AutoCloseable`

    - #### waiting

          public void waiting(long targetGen)

      Specified by:
        `waiting` in interface `NRTManager.WaitingListener`

    - #### run

          public void run()

      Specified by:
        `run` in interface `Runnable`
      Overrides:
        `run` in class `Thread`

Copyright © 2000-2013 Apache Software Foundation. All Rights Reserved.