如果我想从同一个IndexReader实例(大概是一个单例实例)中从多个线程中读取数据,这将对性能产生怎样的影响?是否存在“读取锁定”或任何可能损害多线程可能性的内容?

有没有在多线程环境中使用相同的IndexReader的最佳实践?

最佳答案

根据documentation

IndexReader instances are completely thread safe, meaning multiple threads can call any
of its methods, concurrently. If your application requires external synchronization,
you should not synchronize on the IndexReader instance; use your own (non-Lucene)
objects instead.

但是您还要考虑的另一件事是,如果indexreader由多个线程共享,并且在该过程中索引被更新,则在创建新的indexreader实例之前,更新的索引将不会得到反射(reflect)。

08-28 13:02