public class CasPool extends Object
CAS
instances. This is useful for multithreaded
applications, where there is a need for multiple CASes to be processed simultaneously. Because
CAS creation is expensive, it is a good idea to create a pool of reusable CAS instances at
initialization time, rather than creating a new CAS each time one is needed.
Clients check-out CAS instances from the pool using the getCas()
method and check-in CAS
instances using the releaseCas(CAS)
method.
Design considerations: The pool favors reuse of CASes is some arbitrary preferred priority order. For example if there is a pool of 10 CASes, but only 2 are being check-out at any given time, the same 2 CASes will be used (as opposed to a FIFO approach where all the CASes would be cycled through). If more threads request CASes from the pool than are available, the pool (optionally) puts requesting threads into a wait state. When CASes become available, the longest-waiting thread gets the CAS; this approach prevents starvation behavior (where some threads get all the CASes and others get none).
Constructor and Description |
---|
CasPool(int aNumInstances,
AnalysisEngine aAnalysisEngine)
Creates a new CasPool
|
CasPool(int aNumInstances,
CasDefinition aCasDefinition,
Properties aPerformanceTuningSettings)
Creates a new CasPool.
|
CasPool(int aNumInstances,
CasManager aCasManager,
Properties aPerformanceTuningSettings)
Creates a new CasPool
|
CasPool(int aNumInstances,
Collection<? extends ProcessingResourceMetaData> aCollectionOfProcessingResourceMetaData,
Properties aPerformanceTuningSettings,
ResourceManager aResourceManager)
Creates a new CasPool
|
CasPool(int aNumInstances,
ProcessingResourceMetaData aMetaData)
Creates a new CasPool
|
CasPool(int aNumInstances,
ProcessingResourceMetaData aMetaData,
ResourceManager aResourceManager)
Creates a new CasPool
|
Modifier and Type | Method and Description |
---|---|
protected Vector<CAS> |
getAllInstances() |
CAS |
getCas()
Checks out a CAS from the pool.
|
CAS |
getCas(long aTimeout)
Checks out a CAS from the pool.
|
protected Vector<CAS> |
getFreeInstances() |
int |
getNumAvailable()
Gets the number of CASes currently available in this pool.
|
int |
getSize()
Gets the size of this pool (the total number of CAS instances that it can hold).
|
void |
releaseCas(CAS aCas)
Checks in a CAS to the pool.
|
public CasPool(int aNumInstances, Collection<? extends ProcessingResourceMetaData> aCollectionOfProcessingResourceMetaData, Properties aPerformanceTuningSettings, ResourceManager aResourceManager) throws ResourceInitializationException
aNumInstances
- the number of CAS instances in the poolaCollectionOfProcessingResourceMetaData
- a collection of
ProcessingResourceMetaData
objects.aPerformanceTuningSettings
- Properties object containing framework performance tuning settings using key names
defined on UIMAFramework
interfaceaResourceManager
- the resource manager to use to resolve import declarations within the metadataResourceInitializationException
- if the CAS instances could not be createdpublic CasPool(int aNumInstances, AnalysisEngine aAnalysisEngine) throws ResourceInitializationException
aNumInstances
- the number of CAS instances in the poolaAnalysisEngine
- the analysis engine that will create the CAS instances and which will later be used to
process themResourceInitializationException
- if the CAS instances could not be createdpublic CasPool(int aNumInstances, ProcessingResourceMetaData aMetaData) throws ResourceInitializationException
aNumInstances
- the number of CAS instances in the poolaMetaData
- metadata that includes the type system for the CASResourceInitializationException
- if the CAS instances could not be createdpublic CasPool(int aNumInstances, ProcessingResourceMetaData aMetaData, ResourceManager aResourceManager) throws ResourceInitializationException
aNumInstances
- the number of CAS instances in the poolaMetaData
- metadata that includes the type system for the CASaResourceManager
- Resource ManagerResourceInitializationException
- if the CAS instances could not be createdpublic CasPool(int aNumInstances, CasDefinition aCasDefinition, Properties aPerformanceTuningSettings) throws ResourceInitializationException
aNumInstances
- the number of CAS instances in the poolaCasDefinition
- the Cas definition, which includes the type system, type priorities, and indexes for
the CASes in the pool.aPerformanceTuningSettings
- Properties object containing framework performance tuning settings using key names
defined on UIMAFramework
interfaceResourceInitializationException
- -public CasPool(int aNumInstances, CasManager aCasManager, Properties aPerformanceTuningSettings) throws ResourceInitializationException
aNumInstances
- the number of CAS instances in the poolaCasManager
- CAS Manager that will be used to create the CAS. The CAS Manager
holds the CAS Definition. Also all CASes created from the same
CAS Manager will share identical TypeSystem objects.aPerformanceTuningSettings
- Properties object containing framework performance tuning settings using key names
defined on UIMAFramework
interfaceResourceInitializationException
- -public CAS getCas()
null
if none are available (in which case the
client may Object.wait()
on this object in order to be notified when an
instance becomes available).public CAS getCas(long aTimeout)
aTimeout
- the time to wait in milliseconds. A value of <=0 will wait forever.null
if none are available within the specified
timeout period.public void releaseCas(CAS aCas)
CAS.reset()
method, to ensure
that when the CAS 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.
Synchronized on the CAS to avoid the unnatural case where
multiple threads attempt to return the same CAS to the pool
at the same time.aCas
- the Cas to releasepublic int getSize()
public int getNumAvailable()
Copyright © 2006–2017 The Apache Software Foundation. All rights reserved.