|
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.ImmortalContext
public final class ImmortalContext
This class represents an allocator from immortal memory (RTSJ).
It is typically used to allocate (and recycle) from immortal memory
allowing dynamically created static instances to be accessible by
NoHeapRealtimeThread
:
public synchronized Text intern() {
if (!INTERN_INSTANCES.containsKey(this)) {
ImmortalContext.enter();
try { // Forces interned instance to be in immortal memory.
Text txt = this.copy(); // In ImmortalMemory.
INTERN_INSTANCES.put(txt, txt);
} finally {
ImmortalContext.exit();
}
}
return (Text) INTERN_INSTANCES.get(str);
}
Because class initialization may occur while running in a non-heap
context, it is recommended to force factory produced constants
to immortal memory:
public class Rational {
public static final Rational ZERO;
public static final Rational ONE;
...
static { // Forces constants to ImmortalMemory.
ImmortalContext.enter();
try {
ZERO = Rational.valueOf(0, 1); // Factory produced.
ONE = Rational.valueOf(1, 1); // Factory produced.
} finally {
ImmortalContext.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 |
Method Summary | |
---|---|
protected void |
deactivate()
Deactivates the allocators belonging to this context
for the current thread. |
static void |
enter()
Enters an immortal memory context. |
protected void |
enterAction()
The action to be performed after this context becomes the current context. |
static void |
exit()
Exits the current immortal memory 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 |
Method Detail |
---|
public static void enter()
public static void exit()
java.lang.ClassCastException
- if the context is not an immortal 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 |