In the new 4.4.0 release of Lucene the Near Real Time Manager (org.apache.lucene.search.NRTManage) has been replaced by ControlledRealTimeReopenThread
Does anyone have some sample code for the new ControlledRealTimeReopenThread usage?
EDIT: I answer my own question below
You should not commit after every document, and you shouldn't need to Thread.interrupt the reopen thread (in fact, this is deadly when you are using NIOFSDirectory). Instead, just call its (ControlledRealTimeReopenThread) close method: under the hood, it notifies itself and should finish quickly.
I've made some research about the question and built an utillity type... not throughfully tested (specially in concurrency conditions), anyway it works and i'm pretty sure it's thread safe.
EDIT 2: For thoose using the previous lucene 4.3 NearRealTime Manager type this is the analogous code
'commit' flushes all pending data to disk. So if commit is used, there is no need to use ControlledRealTimeThread. ControlledRealTimeThread coordinates write and read operation in real time.
For add document: ReferenceManager.maybeRefresh()
For search operation: ReferenceManager.acquire(), op.., ReferenceManager.acquire()
Test Code