Package org.springframework.aop.target
Class ThreadLocalTargetSource
java.lang.Object
org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource
org.springframework.aop.target.AbstractPrototypeBasedTargetSource
org.springframework.aop.target.ThreadLocalTargetSource
- All Implemented Interfaces:
- Serializable,- ThreadLocalTargetSourceStats,- TargetClassAware,- TargetSource,- Aware,- BeanFactoryAware,- DisposableBean
public 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 of thread-bound objects is performed on BeanFactory destruction,
 calling their DisposableBean.destroy() method if available.
 Be aware that many thread-bound objects can be around until the application
 actually shuts down.
- Author:
- Rod Johnson, Juergen Hoeller, Rob Harrop
- See Also:
- 
Field SummaryFields inherited from class org.springframework.aop.target.AbstractBeanFactoryBasedTargetSourcelogger
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoiddestroy()Dispose of targets if necessary; clear ThreadLocal.intReturn the number of hits that were satisfied by a thread-bound object.intReturn the number of client invocations.intReturn the number of thread-bound objects created.Return an introduction advisor mixin that allows the AOP proxy to be cast to ThreadLocalInvokerStats.Implementation of abstract getTarget() method.Methods inherited from class org.springframework.aop.target.AbstractPrototypeBasedTargetSourcedestroyPrototypeInstance, newPrototypeInstance, setBeanFactory, writeReplaceMethods inherited from class org.springframework.aop.target.AbstractBeanFactoryBasedTargetSourcecopyFrom, equals, getBeanFactory, getTargetBeanName, getTargetClass, hashCode, isStatic, releaseTarget, setTargetBeanName, setTargetClass, toString
- 
Constructor Details- 
ThreadLocalTargetSourcepublic ThreadLocalTargetSource()
 
- 
- 
Method Details- 
getTargetImplementation 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:
- getTargetin interface- TargetSource
- Returns:
- the target object which contains the joinpoint,
 or nullif there is no actual target instance
- Throws:
- BeansException
 
- 
destroypublic void destroy()Dispose of targets if necessary; clear ThreadLocal.- Specified by:
- destroyin interface- DisposableBean
- See Also:
 
- 
getInvocationCountpublic int getInvocationCount()Description copied from interface:ThreadLocalTargetSourceStatsReturn the number of client invocations.- Specified by:
- getInvocationCountin interface- ThreadLocalTargetSourceStats
 
- 
getHitCountpublic int getHitCount()Description copied from interface:ThreadLocalTargetSourceStatsReturn the number of hits that were satisfied by a thread-bound object.- Specified by:
- getHitCountin interface- ThreadLocalTargetSourceStats
 
- 
getObjectCountpublic int getObjectCount()Description copied from interface:ThreadLocalTargetSourceStatsReturn the number of thread-bound objects created.- Specified by:
- getObjectCountin interface- ThreadLocalTargetSourceStats
 
- 
getStatsMixinReturn an introduction advisor mixin that allows the AOP proxy to be cast to ThreadLocalInvokerStats.
 
-