Package org.apache.uima.util
Class JCasPool
- java.lang.Object
-
- org.apache.uima.util.JCasPool
-
public class JCasPool extends java.lang.ObjectThis class represents a simple pool ofJCasinstances. This is useful for multithreaded applications, where there is a need for multiple CASes to be processed simultaneously. Because JCas creation is expensive, it is a good idea to create a pool of reusable JCas instances at initialization time, rather than creating a new JCas each time one is needed.Clients check-out JCas instances from the pool using the
getJCas()method and check-in JCas instances using thereleaseJCas(JCas)method.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.Class<JCasPool>CLASS_NAMEcurrent classprivate static java.lang.StringLOG_RESOURCE_BUNDLEresource bundle for log messagesprivate java.util.Vector<JCas>mAllInstancesprivate java.util.Vector<JCas>mFreeInstancesprivate intmNumInstances
-
Constructor Summary
Constructors Constructor Description JCasPool(int aNumInstances, AnalysisEngine aAnalysisEngine)Creates a new JCasPoolJCasPool(int aNumInstances, TextAnalysisEngine aTextAnalysisEngine)Deprecated.As of v2.0, TextAnalysisEngine has been deprecated.JCasPool(int aNumInstances, ProcessingResourceMetaData aMetaData)Creates a new JCasPool
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidfillPool(ProcessingResourceMetaData aMetaData)Utility method used in the constructor to fill the pool with CAS instances.protected java.util.Vector<JCas>getAllInstances()protected java.util.Vector<JCas>getFreeInstances()JCasgetJCas()Checks out a JCas from the pool.JCasgetJCas(long aTimeout)Checks out a JCas from the pool.intgetSize()Gets the size of this pool (the total number of JCas instances that it can hold).voidreleaseJCas(JCas aJCas)Checks in a JCas to the pool.
-
-
-
Field Detail
-
mAllInstances
private java.util.Vector<JCas> mAllInstances
-
mFreeInstances
private java.util.Vector<JCas> mFreeInstances
-
mNumInstances
private int mNumInstances
-
LOG_RESOURCE_BUNDLE
private static final java.lang.String LOG_RESOURCE_BUNDLE
resource bundle for log messages- See Also:
- Constant Field Values
-
CLASS_NAME
private static final java.lang.Class<JCasPool> CLASS_NAME
current class
-
-
Constructor Detail
-
JCasPool
@Deprecated public JCasPool(int aNumInstances, TextAnalysisEngine aTextAnalysisEngine) throws ResourceInitializationExceptionDeprecated.As of v2.0, TextAnalysisEngine has been deprecated. UseJCasPool(int, AnalysisEngine)instead.Creates a new JCasPool- Parameters:
aNumInstances- the number of JCas instances in the poolaTextAnalysisEngine- the TAE that will create the JCas instances and which will later be used to process them- Throws:
ResourceInitializationException- if the JCas instances could not be created
-
JCasPool
public JCasPool(int aNumInstances, AnalysisEngine aAnalysisEngine) throws ResourceInitializationExceptionCreates a new JCasPool- Parameters:
aNumInstances- the number of JCas instances in the poolaAnalysisEngine- the AE that will create the JCas instances and which will later be used to process them- Throws:
ResourceInitializationException- if the JCas instances could not be created
-
JCasPool
public JCasPool(int aNumInstances, ProcessingResourceMetaData aMetaData) throws ResourceInitializationExceptionCreates a new JCasPool- Parameters:
aNumInstances- the number of JCas instances in the poolaMetaData- metadata that includes the type system for the CAS- Throws:
ResourceInitializationException- if the CAS instances could not be created
-
-
Method Detail
-
getJCas
public JCas getJCas()
Checks out a JCas from the pool.- Returns:
- a JCas instance. Returns
nullif none are available (in which case the client mayObject.wait()on this object in order to be notified when an instance becomes available).
-
releaseJCas
public void releaseJCas(JCas aJCas)
Checks in a JCas to the pool. This automatically calls theJCas.reset()method, to ensure that when the JCas is later retrieved from the pool it will be ready to use. Also notifies other Threads that may be waiting for an instance to become available.- Parameters:
aJCas- the JCas to release
-
getJCas
public JCas getJCas(long aTimeout)
Checks out a JCas from the pool. If none is currently available, wait for the specified amount of time for one to be checked in.- Parameters:
aTimeout- the time to wait in milliseconds. A value of <=0 will wait forever.- Returns:
- a JCas instance. Returns
nullif none are available within the specified timeout period.
-
getSize
public int getSize()
Gets the size of this pool (the total number of JCas instances that it can hold).- Returns:
- the size of this pool
-
fillPool
protected void fillPool(ProcessingResourceMetaData aMetaData) throws ResourceInitializationException
Utility method used in the constructor to fill the pool with CAS instances.- Parameters:
aMetaData- metadata including the type system for the CASes- Throws:
ResourceInitializationException- if the Resource instances could not be created
-
getAllInstances
protected java.util.Vector<JCas> getAllInstances()
-
getFreeInstances
protected java.util.Vector<JCas> getFreeInstances()
-
-