Top Description Fields Constructors Methods
org.springframework.aop.target

public Class ThreadLocalTargetSource

extends AbstractPrototypeBasedTargetSource
implements ThreadLocalTargetSourceStats, DisposableBean
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.DisposableBean, org.springframework.aop.target.ThreadLocalTargetSourceStats
Annotations
@SuppressWarnings:serial
Imports
java.util.HashSet, .Set, org.springframework.aop.IntroductionAdvisor, org.springframework.aop.support.DefaultIntroductionAdvisor, .DelegatingIntroductionInterceptor, org.springframework.beans.BeansException, org.springframework.beans.factory.DisposableBean, org.springframework.core.NamedThreadLocal

Alternative to an object pool. This org.springframework.aop.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.

Authors
Rod Johnson, Juergen Hoeller, Rob Harrop
See Also
ThreadLocalTargetSourceStats, org.springframework.beans.factory.DisposableBean#destroy()

Field Summary

Modifier and TypeField and Description
private int
private int
private final ThreadLocal<Object>
targetInThread

ThreadLocal holding the target associated with the current thread.

private final Set<Object>
targetSet

Set of managed targets, enabling us to keep track of the targets we've created.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
destroy()

Implements org.springframework.beans.factory.DisposableBean.destroy.

Dispose of targets if necessary; clear ThreadLocal.
public int
getHitCount()

Implements org.springframework.aop.target.ThreadLocalTargetSourceStats.getHitCount.

Return the number of hits that were satisfied by a thread-bound object.
public int
public int
getObjectCount()

Implements org.springframework.aop.target.ThreadLocalTargetSourceStats.getObjectCount.

Return the number of thread-bound objects created.
public IntroductionAdvisor
getStatsMixin()

Return an introduction advisor mixin that allows the AOP proxy to be cast to ThreadLocalInvokerStats.

public Object
getTarget()

Implements org.springframework.aop.TargetSource.getTarget.

Implementation of abstract getTarget() method.
Inherited from org.springframework.aop.target.AbstractPrototypeBasedTargetSource:
destroyPrototypeInstancenewPrototypeInstancesetBeanFactorywriteReplace

Field Detail

hitCountback to summary
private int hitCount
invocationCountback to summary
private int invocationCount
targetInThreadback to summary
private final ThreadLocal<Object> targetInThread

ThreadLocal holding the target associated with the current thread. Unlike most ThreadLocals, which are static, this variable is meant to be per thread per instance of the ThreadLocalTargetSource class.

targetSetback to summary
private final Set<Object> targetSet

Set of managed targets, enabling us to keep track of the targets we've created.

Constructor Detail

ThreadLocalTargetSourceback to summary
public ThreadLocalTargetSource()

Method Detail

destroyback to summary
public void destroy()

Implements org.springframework.beans.factory.DisposableBean.destroy.

Dispose of targets if necessary; clear ThreadLocal.

Annotations
@Override
See Also
destroyPrototypeInstance
getHitCountback to summary
public int getHitCount()

Implements org.springframework.aop.target.ThreadLocalTargetSourceStats.getHitCount.

Doc from org.springframework.aop.target.ThreadLocalTargetSourceStats.getHitCount.

Return the number of hits that were satisfied by a thread-bound object.

Annotations
@Override
getInvocationCountback to summary
public int getInvocationCount()

Implements org.springframework.aop.target.ThreadLocalTargetSourceStats.getInvocationCount.

Doc from org.springframework.aop.target.ThreadLocalTargetSourceStats.getInvocationCount.

Return the number of client invocations.

Annotations
@Override
getObjectCountback to summary
public int getObjectCount()

Implements org.springframework.aop.target.ThreadLocalTargetSourceStats.getObjectCount.

Doc from org.springframework.aop.target.ThreadLocalTargetSourceStats.getObjectCount.

Return the number of thread-bound objects created.

Annotations
@Override
getStatsMixinback to summary
public IntroductionAdvisor getStatsMixin()

Return an introduction advisor mixin that allows the AOP proxy to be cast to ThreadLocalInvokerStats.

getTargetback to summary
public Object getTarget() throws BeansException

Implements org.springframework.aop.TargetSource.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.

Returns:Object

Doc from org.springframework.aop.TargetSource.getTarget.

the target object which contains the joinpoint, or null if there is no actual target instance

Annotations
@Override