org.springframework.aop.target
Class ThreadLocalTargetSource

java.lang.Object
  extended byorg.springframework.aop.target.AbstractPrototypeBasedTargetSource
      extended byorg.springframework.aop.target.ThreadLocalTargetSource
All Implemented Interfaces:
BeanFactoryAware, DisposableBean, InitializingBean, java.io.Serializable, TargetSource, ThreadLocalTargetSourceStats

public final class ThreadLocalTargetSource
extends AbstractPrototypeBasedTargetSource
implements ThreadLocalTargetSourceStats, DisposableBean

Alternative to an object pool. This TargetSource uses a threading model in which every thread has its own copy of the target. There's no contention for targets. Target object creation is kept to a minimum on the running server.

Application code is written as to a normal pool; callers can't assume they will be dealing with the same instance in invocations in different threads. However, state can be relied on during the operations of a single thread: for example, if one caller makes repeated calls on the AOP proxy.

Cleanup is performed in the destroy() method from DisposableBean.

Author:
Rod Johnson, Juergen Hoeller
See Also:
destroy(), Serialized Form

Field Summary
 
Fields inherited from class org.springframework.aop.target.AbstractPrototypeBasedTargetSource
logger
 
Constructor Summary
ThreadLocalTargetSource()
           
 
Method Summary
 void destroy()
          Dispose of targets if necessary; clear ThreadLocal.
 int getHitCount()
          Return the number of hits that were satisfied by a thread-bound object.
 int getHits()
          Deprecated. in favor of getHitCount
 int getInvocationCount()
          Return the number of client invocations.
 int getInvocations()
          Deprecated. in favor of getInvocationCount
 int getObjectCount()
          Return the number of thread-bound objects created.
 int getObjects()
          Deprecated. in favor of getObjectCount
 IntroductionAdvisor getStatsMixin()
          Return an introduction advisor mixin that allows the AOP proxy to be cast to ThreadLocalInvokerStats.
 java.lang.Object getTarget()
          Implementation of abstract getTarget() method.
 void releaseTarget(java.lang.Object target)
          Release the given target object obtained from the getTarget() method.
 
Methods inherited from class org.springframework.aop.target.AbstractPrototypeBasedTargetSource
afterPropertiesSet, getTargetBeanName, getTargetClass, isStatic, newPrototypeInstance, setBeanFactory, setTargetBeanName, writeReplace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThreadLocalTargetSource

public ThreadLocalTargetSource()
Method Detail

getTarget

public java.lang.Object getTarget()
Implementation of abstract getTarget() method. We look for a target held in a ThreadLocal. If we don't find one, we create one and bind it to the thread. No synchronization is required.

Specified by:
getTarget in interface TargetSource
Returns:
the target object, whicch contains the joinpoint

releaseTarget

public void releaseTarget(java.lang.Object target)
Description copied from interface: TargetSource
Release the given target object obtained from the getTarget() method.

Specified by:
releaseTarget in interface TargetSource
Parameters:
target - object obtained from a call to getTarget()
See Also:
TargetSource.getTarget()

destroy

public void destroy()
Dispose of targets if necessary; clear ThreadLocal.

Specified by:
destroy in interface DisposableBean

getInvocationCount

public int getInvocationCount()
Description copied from interface: ThreadLocalTargetSourceStats
Return the number of client invocations.

Specified by:
getInvocationCount in interface ThreadLocalTargetSourceStats

getHitCount

public int getHitCount()
Description copied from interface: ThreadLocalTargetSourceStats
Return the number of hits that were satisfied by a thread-bound object.

Specified by:
getHitCount in interface ThreadLocalTargetSourceStats

getObjectCount

public int getObjectCount()
Description copied from interface: ThreadLocalTargetSourceStats
Return the number of thread-bound objects created.

Specified by:
getObjectCount in interface ThreadLocalTargetSourceStats

getInvocations

public int getInvocations()
Deprecated. in favor of getInvocationCount

Specified by:
getInvocations in interface ThreadLocalTargetSourceStats
See Also:
getInvocationCount()

getHits

public int getHits()
Deprecated. in favor of getHitCount

Specified by:
getHits in interface ThreadLocalTargetSourceStats
See Also:
getHitCount()

getObjects

public int getObjects()
Deprecated. in favor of getObjectCount

Specified by:
getObjects in interface ThreadLocalTargetSourceStats
See Also:
getObjectCount()

getStatsMixin

public IntroductionAdvisor getStatsMixin()
Return an introduction advisor mixin that allows the AOP proxy to be cast to ThreadLocalInvokerStats.



Copyright (C) 2003-2004 The Spring Framework Project.