J avolution v3.7 (J2SE 1.5+)

javolution.realtime
Class PoolContext

java.lang.Object
  extended by javolution.realtime.Context
      extended by javolution.realtime.PoolContext

public class PoolContext
extends Context

This class represents a pool context; it is used to recycle objects transparently, reduce memory allocation and avoid garbage collection.

Threads executing in a pool context may allocate objects from the context's pools (also called "stack") through an ObjectFactory. Allocated objects are recycled automatically upon exit. This recycling is almost instantaneous and has no impact on performance.

Objects allocated within a pool context should not be directly referenced outside of the context unless they are exported (e.g. result being returned) or preserved (e.g. shared static instance). If this simple rule is followed, then pool context are completely safe. In fact, pool contexts promote the use of immutable objects (as their allocation cost is then negligible with no adverse effect on garbarge collection) and often lead to safer, faster and more robust applications.

Finally, the framework guarantees that all pool objects belongs to the same memory area (the memory area where the pool context resides). In other words, pool contexts allocated in ImmortalMemory can safely be used by NoHeapRealtimeThread executing in ScopedMemory.

Version:
3.7, January 1, 2006
Author:
Jean-Marie Dautelle

Field Summary
protected static XmlFormat XML
          Holds the XML representation for pool contexts.
 
Constructor Summary
PoolContext()
          Default constructor.
 
Method Summary
 void clear()
          Moves all objects belonging to this pool context to the heap.
static PoolContext current()
          Returns the current pool context or null if the current thread does not execute within a pool context.
static void enter()
          Enters a PoolContext allocated in the same memory area as the memory area of the current context.
protected  void enterAction()
          The action to be performed after this context becomes the current context.
static void exit()
          Exits the current PoolContext.
protected  void exitAction()
          The action to be performed before this context is no more the current context.
 
Methods inherited from class javolution.realtime.Context
enter, enter, exit, exit, getOuter, getOwner
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

XML

protected static final XmlFormat XML
Holds the XML representation for pool contexts. It holds the sizes of the pool being used in order to repopulate these pools during deserialization.

Constructor Detail

PoolContext

public PoolContext()
Default constructor.

Method Detail

current

public static PoolContext current()
Returns the current pool context or null if the current thread does not execute within a pool context.

Returns:
the current pool context.

enter

public static void enter()
Enters a PoolContext allocated in the same memory area as the memory area of the current context.


exit

public static void exit()
Exits the current PoolContext.

Throws:
java.lang.IllegalStateException - if the current context is not an instance of PoolContext.

clear

public void clear()
Moves all objects belonging to this pool context to the heap.

Overrides:
clear in class Context

enterAction

protected void enterAction()
Description copied from class: Context
The action to be performed after this context becomes the current context.

Specified by:
enterAction in class Context

exitAction

protected void exitAction()
Description copied from class: Context
The action to be performed before this context is no more the current context.

Specified by:
exitAction in class Context

J avolution v3.7 (J2SE 1.5+)

Copyright © 2006 Javolution.