|
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.HeapContext
public class HeapContext
This class represents the default allocator context. Allocations are
performed using the new
keyword and explicit object
recycling
is supported:
char[] buffer = ArrayFactory.CHARS_FACTORY.array(4098); // Possibly recycled.
while (reader.read(buffer) > 0) { ... }
ArrayFactory.CHARS_FACTORY.recycle(buffer); // Explicit recycling.
It should be noted that object recycling is performed on a thread basis
(for performance reasons) and should only be performed if the object
has been factory produced by the same thread doing the recycling.
It is usually not a problem because recycling is done for temporary
objects within the same method. For example:
If allocation/recycling is performed by different threads then
public String toString() {
TextBuilder tmp = TextBuilder.newInstance(); // Calls ObjectFactory.object()
try {
tmp.append(...);
...
return tmp.toString();
} finally {
TextBuilder.recycle(tmp); // Calls ObjectFactory.recycle(...)
}
}
PoolContext
should be employed.
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 | |
---|---|
HeapContext()
Default constructor. |
Method Summary | |
---|---|
protected void |
deactivate()
Deactivates the allocators belonging to this context
for the current thread. |
static void |
enter()
Enters a heap context. |
protected void |
enterAction()
The action to be performed after this context becomes the current context. |
static void |
exit()
Exits the current heap 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 HeapContext()
Method Detail |
---|
public static void enter()
public static void exit()
java.lang.ClassCastException
- if the context is not a heap 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 |