Hi all,
I am new to multi-thread programming and lucene. I want to change the
indexing demo of lucene143 into a multi-thread one. I create one instance of
IndexWriter which is shared by three threads. But I find that the time it
costs when three threads are used is approximate three times of that of
single thread.(My computer is dual-core) It seems I write a pseudo
multi-thread program and it does the same work for three times.
Following is a snippet of my code. Please tell me how to write the correct
code. Thanks.
IndexWriter writer = new IndexWriter("D:\\index", new StandardAnalyzer(),
true);
File file=new File(args[0]);
Thread t1=new Thread(new IndexFiles(writer,file));
Thread t2=new Thread(new IndexFiles(writer,file));
Thread t3=new Thread(new IndexFiles(writer,file));
t1.start();
t2.start();
t3.start();
writer.optimize();
writer.close();
while(t1.getState()!=State.TERMINATED
||t2.getState()!=State.TERMINATED
||t3.getState()!=State.TERMINATED
){}//wait until the threads end.
Date end = new Date();
--
Best regards,
Chuan SHI