|
J avolution v5.5 (J2SE 1.6+) | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavolution.context.Context
javolution.context.AllocatorContext
javolution.context.PoolContext
public class PoolContext
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();
}
}};
Nested Class Summary |
---|
Nested classes/interfaces inherited from class javolution.context.AllocatorContext |
---|
AllocatorContext.Reference<T> |
Field Summary |
---|
Fields inherited from class javolution.context.AllocatorContext |
---|
DEFAULT |
Fields inherited from class javolution.context.Context |
---|
ROOT |
Constructor Summary | |
---|---|
PoolContext()
Default constructor. |
Method Summary | |
---|---|
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. |
Methods inherited from class javolution.context.AllocatorContext |
---|
getCurrentAllocatorContext, getDefault, outerCopy, outerCopy, outerExecute |
Methods inherited from class javolution.context.Context |
---|
enter, enter, exit, exit, getCurrentContext, getOuter, getOwner, setConcurrentContext, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public PoolContext()
Method Detail |
---|
public static void enter()
public static void exit()
java.lang.ClassCastException
- if the context is not a pool context.protected void deactivate()
AllocatorContext
allocators
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 AllocatorContext
protected Allocator getAllocator(ObjectFactory factory)
AllocatorContext
getAllocator
in class AllocatorContext
factory
- the factory for which the allocator is returned.
protected void enterAction()
Context
enterAction
in class Context
protected void exitAction()
Context
exitAction
in class Context
|
J avolution v5.5 (J2SE 1.6+) | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |