You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Kai Hu <ka...@dusee.cn> on 2007/08/06 12:29:05 UTC

答复: About muti-Threads in Lucene

Thanks , Patrick,

It is useful. But I found a problem that I use 

“new LuceneIndexAccessor(accessProvider);” when a request comes in B/S,the LuceneIndexAccessor.getWriter() will lose its sense,it will new an IndexWriter.

public IndexWriter getWriter() throws IOException {

       IndexWriter result;

       synchronized (this) {//here “synchronized” will lose its sense 

           checkClosed();

           ...

       if (cachedWriter != null) {

              log.debug("returning cached writer");

              result = cachedWriter;

              writerUseCount++;

           } else {

              log.debug("opening new writer and caching it");

              result = accessProvider.getWriter();// when new a LuceneIndexAccessor Object ,it will new an IndexWriter Object 

              cachedWriter = result;

              writerUseCount = 1;

           }

    }

}

It will also throw a Exception “cann’t obtain the Lock”,should I use a single instance of LuceneIndexAccessor? Suppose I use a single instance of LuceneIndexAccessor,how to set a different Directory or Analyzer at one time.

 

kai


///////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////

 

>Hi Kai

> 

>We use the Lucene Index Accessor contribution:

> 

>http://www.nabble.com/Fwd%3A-Contribution%3A-LuceneIndexAccessor-t17416.html#a47049

> 

>Patrick

 

On 06/08/07, Kai Hu <ka...@dusee.cn> wrote:

> Hi,

> 

>          How do you solve the problems when add,update,delete documents

> in muti-threads,use synchronized ?

> 

> 

 

---------------------------------------------------------------------

To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org

For additional commands, e-mail: java-user-help@lucene.apache.org

 


Re: 答复: About muti-Threads in Lucene

Posted by Patrick Kimber <ma...@gmail.com>.
Hi Kai

We keep a synchronized map of LuceneIndexAccessor instances, one instance per
Directory.  The map is keyed on the directory path.  We then re-use
the accessor rather than creating a new one each time.

Patrick

On 06/08/07, Kai Hu <ka...@dusee.cn> wrote:
> Thanks , Patrick,
>
> It is useful. But I found a problem that I use
>
> "new LuceneIndexAccessor(accessProvider);" when a request comes in B/S,the LuceneIndexAccessor.getWriter() will lose its sense,it will new an IndexWriter.
>
> public IndexWriter getWriter() throws IOException {
>
>        IndexWriter result;
>
>        synchronized (this) {//here "synchronized" will lose its sense
>
>            checkClosed();
>
>            ...
>
>        if (cachedWriter != null) {
>
>               log.debug("returning cached writer");
>
>               result = cachedWriter;
>
>               writerUseCount++;
>
>            } else {
>
>               log.debug("opening new writer and caching it");
>
>               result = accessProvider.getWriter();// when new a LuceneIndexAccessor Object ,it will new an IndexWriter Object
>
>               cachedWriter = result;
>
>               writerUseCount = 1;
>
>            }
>
>     }
>
> }
>
> It will also throw a Exception "cann't obtain the Lock",should I use a single instance of LuceneIndexAccessor? Suppose I use a single instance of LuceneIndexAccessor,how to set a different Directory or Analyzer at one time.
>
>
>
> kai
>
>
> ///////////////////////////////////////////////////////////
>
> ///////////////////////////////////////////////////////////
>
>
>
> >Hi Kai
>
> >
>
> >We use the Lucene Index Accessor contribution:
>
> >
>
> >http://www.nabble.com/Fwd%3A-Contribution%3A-LuceneIndexAccessor-t17416.html#a47049
>
> >
>
> >Patrick
>
>
>
> On 06/08/07, Kai Hu <ka...@dusee.cn> wrote:
>
> > Hi,
>
> >
>
> >          How do you solve the problems when add,update,delete documents
>
> > in muti-threads,use synchronized ?
>
> >
>
> >
>
>
>
> ---------------------------------------------------------------------
>
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org