Index: CHANGES.txt =================================================================== --- CHANGES.txt (revision 747250) +++ CHANGES.txt (working copy) @@ -51,6 +51,9 @@ that's visited. All core collectors now use this API. (Mark Miller, Mike McCandless) +8. LUCENE-1186: Add Analyzer.close() to free internal ThreadLocal + resources. (Mike McCandless) + Bug fixes 1. LUCENE-1415: MultiPhraseQuery has incorrect hashCode() and equals() @@ -76,6 +79,9 @@ 5. LUCENE-1544: Fix deadlock in IndexWriter.addIndexes(IndexReader[]). (Mike McCandless via Doug Sale) +6. LUCENE-1186: Add Analyzer.close() to free internal ThreadLocal + resources. (Mike McCandless) + New features 1. LUCENE-1411: Added expert API to open an IndexWriter on a prior Index: src/java/org/apache/lucene/analysis/Analyzer.java =================================================================== --- src/java/org/apache/lucene/analysis/Analyzer.java (revision 747250) +++ src/java/org/apache/lucene/analysis/Analyzer.java (working copy) @@ -20,6 +20,9 @@ import java.io.Reader; import java.io.IOException; +import org.apache.lucene.util.CloseableThreadLocal; +import org.apache.lucene.store.AlreadyClosedException; + /** An Analyzer builds TokenStreams, which analyze text. It thus represents a * policy for extracting index terms from text. *
@@ -44,20 +47,36 @@ return tokenStream(fieldName, reader); } - private ThreadLocal tokenStreams = new ThreadLocal(); + private CloseableThreadLocal tokenStreams = new CloseableThreadLocal(); /** Used by Analyzers that implement reusableTokenStream * to retrieve previously saved TokenStreams for re-use * by the same thread. */ protected Object getPreviousTokenStream() { - return tokenStreams.get(); + try { + return tokenStreams.get(); + } catch (NullPointerException npe) { + if (tokenStreams == null) { + throw new AlreadyClosedException("this Analyzer is closed"); + } else { + throw npe; + } + } } /** Used by Analyzers that implement reusableTokenStream * to save a TokenStream for later re-use by the same * thread. */ protected void setPreviousTokenStream(Object obj) { - tokenStreams.set(obj); + try { + tokenStreams.set(obj); + } catch (NullPointerException npe) { + if (tokenStreams == null) { + throw new AlreadyClosedException("this Analyzer is closed"); + } else { + throw npe; + } + } } @@ -78,4 +97,10 @@ { return 0; } + + /** Frees persistent resources used by this Analyzer */ + public void close() { + tokenStreams.close(); + tokenStreams = null; + } }