简体   繁体   English

使用 lucene IndexWriter 进行多线程处理

[英]Multithreading with lucene IndexWriter

I'm using lucene 6.3.0 to create an indexer.我正在使用 lucene 6.3.0 创建索引器。 It reads the collection from one folder and create the index to another one.它从一个文件夹中读取集合并为另一个文件夹创建索引。 This works fine, but I want to do it multithreading, I mean, given 2 collections (c1 and c2), run 2 threads, each one with one collection and with one index folder, so that, thread one will create an index for the collection c1 to the folder i1 and thread 2 will create an index for the collection c2 to the folder i2.这工作正常,但我想做多线程,我的意思是,给定 2 个集合(c1 和 c2),运行 2 个线程,每个线程有一个集合和一个索引文件夹,这样,线程一将为集合 c1 到文件夹 i1 和线程 2 将为集合 c2 创建到文件夹 i2 的索引。

I've created a ThreadPool class to manage it, but I'm getting a :我创建了一个 ThreadPool 类来管理它,但是我得到了一个:

Exception in thread "pool-1-thread-2" org.apache.lucene.util.SetOnce$AlreadySetException: The object cannot be set twice!线程“pool-1-thread-2”org.apache.lucene.util.SetOnce$AlreadySetException 中的异常:对象不能设置两次!

It comes from它来自

IndexWriter writer = new IndexWriter(directory, indexWriterConfig); IndexWriter writer = new IndexWriter(directory, indexWriterConfig);

However, indexes are created anyway.但是,无论如何都会创建索引。

Why I'm getting this exception and how I avoid getting it?为什么我会收到此异常以及如何避免它?

You are reusing the same instance of IndexWriterConfig across multiple IndexWriters.您正在跨多个 IndexWriter 重用同一个IndexWriterConfig实例。 That is not allowed, you'll need to generate a new instance for the each IndexWriter.这是不允许的,您需要为每个 IndexWriter 生成一个新实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM