gpt4 book ai didi

java - 并发编写 Lucene 索引

转载 作者:搜寻专家 更新时间:2023-11-01 03:11:30 24 4
gpt4 key购买 nike

一个索引由多个 IndexWriters 共享。显然,如果一个打开索引即将被其他IndexWriter打开,就会抛出LockObtainFailedException。我的解决方案是创建具有较长超时时间的 IndexWriter:

IndexWriterConfig conf= new IndexWriterConfig(Version.LUCENE_30, new SimpleAnalyzer (Version.LUCENE_30));
conf.setWriteLockTimeout(30*1000);//Wait 30 seconds timeout
try{
IndexWriter writer = new IndexWriter(dir, conf);
}catch(LockObtainFailedException e){
System.out.println("give up trying...");
}

对于这种情况有更好的解决方案吗?

编辑:灵感来自 Thilo。我找到了 IndexWriter 的 JavaDoc:

IndexWriter 实例完全线程安全,这意味着多个线程可以同时调用它的任何方法。如果您的应用程序需要外部同步,则不应在 IndexWriter 实例上进行同步,因为这可能会导致死锁;请改用您自己的(非 Lucene)对象。

最佳答案

单个目录不能由多个IndexWriters 共享。只需在您的线程中共享一个 IndexWriter

关于java - 并发编写 Lucene 索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9108147/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com