public class HeapContext extends AllocatorContext
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.
AllocatorContext.Reference<T>DEFAULT| Constructor and Description |
|---|
HeapContext()
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 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.
|
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 heap 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.