J avolution v5.4 (J2SE 1.6+)

javolution.context
Class PoolContext

java.lang.Object
  extended by javolution.context.Context
      extended by javolution.context.AllocatorContext
          extended by javolution.context.PoolContext
All Implemented Interfaces:
java.io.Serializable, XMLSerializable

public class PoolContext
extends AllocatorContext

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();
                }
            }};
     

Version:
5.3, March 10, 2009
Author:
Jean-Marie Dautelle
See Also:
Serialized Form

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
getCurrent, getDefault, outerCopy, outerCopy, outerExecute
 
Methods inherited from class javolution.context.Context
enter, enter, exit, exit, getOuter, getOwner, setCurrent, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PoolContext

public PoolContext()
Default constructor.

Method Detail

enter

public static void enter()
Enters a pool context.


exit

public static void exit()
Exits the current pool context.

Throws:
java.lang.ClassCastException - if the context is not a pool context.

deactivate

protected void deactivate()
Description copied from class: AllocatorContext
Deactivates the 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).

Specified by:
deactivate in class AllocatorContext

getAllocator

protected Allocator getAllocator(ObjectFactory factory)
Description copied from class: AllocatorContext
Returns the allocator for the specified factory in this context.

Specified by:
getAllocator in class AllocatorContext
Parameters:
factory - the factory for which the allocator is returned.
Returns:
the allocator producing instances of the specified factory.

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 v5.4 (J2SE 1.6+)

Copyright © 2005 - 2009 Javolution.