spring-framework / org.springframework.aop.target / ThreadLocalTargetSource

ThreadLocalTargetSource

open class ThreadLocalTargetSource : AbstractPrototypeBasedTargetSource, ThreadLocalTargetSourceStats, DisposableBean

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.

Author
Rod Johnson

Author
Juergen Hoeller

Author
Rob Harrop

See Also
ThreadLocalTargetSourceStatsorg.springframework.beans.factory.DisposableBean#destroy()

Constructors

<init>

ThreadLocalTargetSource()

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.

Functions

destroy

open fun destroy(): Unit

Dispose of targets if necessary; clear ThreadLocal.

getHitCount

open fun getHitCount(): Int

getInvocationCount

open fun getInvocationCount(): Int

getObjectCount

open fun getObjectCount(): Int

getStatsMixin

open fun getStatsMixin(): IntroductionAdvisor

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

getTarget

open fun getTarget(): Any

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.