public class PoolContext extends AllocatorContext
This class represents a shared pool context for object
allocation/recycling. Unlike HeapContext, objects recycled
can be reused by all threads running in a PoolContext.
// To avoid each new thread to enter a PoolContext, the default
// allocator context can be configured to PoolContext.class
Thread thread1 = new Thread() {
public void run() {
PoolContext.enter();
try {
...
myObject = myObjectFactory.object(); // Returns an object potentially recycled by thread2.
...
} finally {
PoolContext.exit();
}
}};
Thread thread2 = new Thread() {
public void run() {
PoolContext.enter();
try {
...
myObjectFactory.recycle(myObject); // Recycles an object potentially created by thread1.
...
} finally {
PoolContext.exit();
}
}};
AllocatorContext.Reference<T>DEFAULT| Constructor and Description |
|---|
PoolContext()
Default constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
deactivate()
Deactivates the
allocators belonging to this context
for the current thread. |
static void |
enter()
Enters a pool context.
|
protected void |
enterAction()
The action to be performed after this context becomes the current
context.
|
static void |
exit()
Exits the current pool context.
|
protected void |
exitAction()
The action to be performed before this context is no more the current
context.
|
protected Allocator |
getAllocator(ObjectFactory factory)
Returns the allocator for the specified factory in this context.
|
getCurrentAllocatorContext, getDefault, outerCopy, outerCopy, outerExecuteenter, enter, exit, exit, getCurrentContext, getOuter, getOwner, setConcurrentContext, toStringpublic static void enter()
public static void exit()
java.lang.ClassCastException - if the context is not a pool context.protected void deactivate()
AllocatorContextallocators belonging to this context
for the current thread. This method is typically called when an inner
allocator context is entered by the current thread, when exiting an
allocator context or when a concurrent executor has completed its task
within this allocator context. Deactivated allocators have no
user (null).deactivate in class AllocatorContextprotected Allocator getAllocator(ObjectFactory factory)
AllocatorContextgetAllocator in class AllocatorContextfactory - the factory for which the allocator is returned.protected void enterAction()
ContextenterAction in class Contextprotected void exitAction()
ContextexitAction in class ContextCopyright © 2005 - 2007 Javolution.