lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Satoshi Hasegawa" <haseg...@p03.worldsoftware.co.jp>
Subject Is opening IndexReader multiple times safe?
Date Tue, 16 Nov 2004 01:25:11 GMT
Hello,

I need to handle IOExceptions that arise from index access 
(IndexReader#open, #delete, IndexWriter#optimize etc.), and I'm not sure if 
the IndexReader is open when the exception is thrown/caught. Specifically, 
my code is as follows.

        try {
            indexReader.delete(term);
            indexReader.close();
            IndexWriter indexWriter = new IndexWriter(fsDirectory,
                    new JapaneseAnalyzer(), false);
            indexWriter.optimize();
            indexWriter.close();
        } catch (Exception e) {
            // IndexReader may or may not be open
            indexReader = IndexReader.open(path);
            indexReader.undelete();
        }

Is the above code safe? IndexReader may already be open at the beginning of 
the catch clause if the exception was thrown before closing the IndexReader.



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


Mime
View raw message