CodeSniffer
CodeSniffer

Reputation: 93

Multithreading with lucene IndexWriter

I'm using lucene 6.3.0 to create an indexer. 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.

I've created a ThreadPool class to manage it, but I'm getting a :

Exception in thread "pool-1-thread-2" org.apache.lucene.util.SetOnce$AlreadySetException: The object cannot be set twice!

It comes from

IndexWriter writer = new IndexWriter(directory, indexWriterConfig);

However, indexes are created anyway.

Why I'm getting this exception and how I avoid getting it?

Upvotes: 1

Views: 1055

Answers (1)

femtoRgon
femtoRgon

Reputation: 33341

You are reusing the same instance of IndexWriterConfig across multiple IndexWriters. That is not allowed, you'll need to generate a new instance for the each IndexWriter.

Upvotes: 2

Related Questions