mirror of https://github.com/apache/lucene.git
LUCENE-1186: add Analyzer.close() to close the internal ThreadLocal
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@749326 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ae19121e4c
commit
dcd63a35e7
|
@ -56,6 +56,9 @@ API Changes
|
|||
IndexReader. This matches IndexWriter's commit methods. (Jason
|
||||
Rutherglen via Mike McCandless)
|
||||
|
||||
9. LUCENE-1186: Add Analyzer.close() to free internal ThreadLocal
|
||||
resources. (Christian Kohlschütter via Mike McCandless)
|
||||
|
||||
Bug fixes
|
||||
|
||||
1. LUCENE-1415: MultiPhraseQuery has incorrect hashCode() and equals()
|
||||
|
@ -81,6 +84,9 @@ Bug fixes
|
|||
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. (Christian Kohlschütter via Mike McCandless)
|
||||
|
||||
New features
|
||||
|
||||
1. LUCENE-1411: Added expert API to open an IndexWriter on a prior
|
||||
|
|
|
@ -20,6 +20,9 @@ package org.apache.lucene.analysis;
|
|||
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.
|
||||
* <p>
|
||||
|
@ -44,20 +47,36 @@ public abstract class Analyzer {
|
|||
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 @@ public abstract class Analyzer {
|
|||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Frees persistent resources used by this Analyzer */
|
||||
public void close() {
|
||||
tokenStreams.close();
|
||||
tokenStreams = null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue