Hi,

I am trying to use a shared IndexWriter instance for a multi-thread
application. Surprisingly, this under performs by creating a writer
instance within a thread.

My code is as follow. Can someone help explain why? Thanks.


Scenario 1: shared IndexWriter instance

RAMDirectory ramDir = new RAMDirectory();
IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_35,  new
IKAnalyzer() );
IndexWriter iw = new IndexWriter(ramDir, iwc);

ExecutorService executor = Executors
.newFixedThreadPool(20);

for(int i=0; i<10000; i++){
   Runnable runable = new MyRunnable(iw, ramDir);
}

Scenario 2: create IndexWriter instance with MyRunnable()

public MyRunnable implements Runnable{

......

public void run(){
RAMDirectory ramDir = new RAMDirectory();
IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_35,  new
IKAnalyzer() );
IndexWriter iw = new IndexWriter(ramDir, iwc);
}


}

Reply via email to