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 Jason Tesser <ja...@gmail.com> on 2010/03/31 14:36:04 UTC

Is it safe to use reopen on IndexReader

Is it safe to use reopen on IndexReader if their are other threads who had
readers out or do I need to use a ref counter to make sure all readers are
checked in?

Secondly right now we also check this when we reopen
IndexReader ir = indexSearcher.getIndexReader();
                    indexSearcher = new IndexSearcher(ir.reopen(true));
                    if(ir != indexSearcher.getIndexReader()){
                        ir.close();
                    }
Is the if(ir != indexSearcher.getIndexReader()){   check needed?

Thanks,
Jason Tesser
dotCMS Lead Development Manager
1-305-858-1422

Re: Is it safe to use reopen on IndexReader

Posted by Michael McCandless <lu...@mikemccandless.com>.
It's perfectly safe to .reopen a reader when other threads are using
that reader (eg, for searching, or for anything else).  The reopen
call doesn't affect the original reader in any way.

You should close the old reader when you're done (if indeed a new
reader was returned by .reopen), but if multiple threads may be using
it, you should use incRef/decRef to make sure the close only happens
when all threads are done.

That if check is necessary -- if the reader is unchanged (not
reopened) you shouldn't close the old one.

Mike

On Wed, Mar 31, 2010 at 8:36 AM, Jason Tesser <ja...@gmail.com> wrote:
> Is it safe to use reopen on IndexReader if their are other threads who had
> readers out or do I need to use a ref counter to make sure all readers are
> checked in?
>
> Secondly right now we also check this when we reopen
> IndexReader ir = indexSearcher.getIndexReader();
>                    indexSearcher = new IndexSearcher(ir.reopen(true));
>                    if(ir != indexSearcher.getIndexReader()){
>                        ir.close();
>                    }
> Is the if(ir != indexSearcher.getIndexReader()){   check needed?
>
> Thanks,
> Jason Tesser
> dotCMS Lead Development Manager
> 1-305-858-1422
>

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