加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – Lucene.Net是否管理访问相同索引的多个线程,一个索引

发布时间:2020-12-15 23:40:07 所属栏目:asp.Net 来源:网络整理
导读:当使用Lucene.Net与ASP.NET时,我可以想象一个Web请求可以触发对索引的更新,而另一个Web请求执行搜索. Lucene.Net是否已经建立了管理并发访问的能力,或者我必须管理它,以避免“被另一个进程使用”的错误? 编辑:阅读文档和实验后,这是我认为我学到的:线程安
当使用Lucene.Net与ASP.NET时,我可以想象一个Web请求可以触发对索引的更新,而另一个Web请求执行搜索. Lucene.Net是否已经建立了管理并发访问的能力,或者我必须管理它,以避免“被另一个进程使用”的错误?

编辑:阅读文档和实验后,这是我认为我学到的:线程安全和并发有两个问题.多线程是“安全的”,因为你不能对索引做任何坏事.但是,只要一个对象同时在索引上锁定就是安全的.第二个对象将会出现并抛出异常.所以,你不能让搜索打开,并期望另一个线程中的作者能够更新索引.如果线程忙于更新索引,则尝试创建搜索器将失败.

此外,搜索者会看到索引,因为它是在它们打开的时候,所以如果你保持它们,并更新索引,他们将看不到更新.

我希望我的搜索者能够看到最新的更新.

我的设计,到目前为止,它的作品和搜索者共享一个锁,所以它们不会失败 – 他们只是等待 – 直到当前的写入或搜索完成.

解决方法

根据 this page,

Indexing and searching are not only
thread safe,but process safe. What
this means is that:

  • Multiple index searchers can read the
    lucene index files at the same time.
  • An index writer or reader can edit the
    lucene index files while searches are
    ongoing
  • Multiple index writers or
    readers can try to edit the lucene
    index files at the same time (it’s
    important for the index writer/reader
    to be closed so it will release the
    file lock). However,the query parser
    is not thread safe,so each thread
    using the index should have its own
    query parser.

The index writer however,is thread safe,so you can update the index while people are searching it. However,you then have to make sure that the threads with open index searchers close them and open new ones,to get the newly updated data.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读