You are optimizing before the threads are finished adding to the index.
I think this should work:
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();
while(t1.getState()!=State.TERMINATED
||t2.getState()!=State.TERMINATED
||t3.getState()!=State.TERMINATED
){
try{
Thread.currentThread().sleep(100l);
}
catch(InterruptedException ie)
{
ie.printStackTrace();
}
}//wait until the threads end.
writer.optimize();
writer.close();
Date end = new Date();
2009/8/13 Chuan SHI <[email protected]>:
> 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
>
--
-
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]