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.
ThreadLocalTargetSourceStats, org.springframework.beans.factory.DisposableBean#destroy()
| Modifier and Type | Field and Description |
|---|---|
| private int | |
| private int | |
| private final ThreadLocal | targetInThread
ThreadLocal holding the target associated with the current thread. |
| private final Set | targetSet
Set of managed targets, enabling us to keep track of the targets we've created. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | destroy()
Implements org. |
| public int | getHitCount()
Implements org. |
| public int | getInvocationCount()
Implements org. |
| public int | getObjectCount()
Implements org. |
| public IntroductionAdvisor | getStatsMixin()
Return an introduction advisor mixin that allows the AOP proxy to be cast to ThreadLocalInvokerStats. |
| public Object | getTarget()
Implements org. |
| hitCount | back to summary |
|---|---|
| private int hitCount | |
| invocationCount | back to summary |
|---|---|
| private int invocationCount | |
| targetInThread | back 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. | |
| targetSet | back to summary |
|---|---|
| private final Set<Object> targetSet Set of managed targets, enabling us to keep track of the targets we've created. | |
| ThreadLocalTargetSource | back to summary |
|---|---|
| public ThreadLocalTargetSource() | |
| destroy | back to summary |
|---|---|
| public void destroy() Implements org. Dispose of targets if necessary; clear ThreadLocal.
| |
| getHitCount | back to summary |
|---|---|
| public int getHitCount() Implements org. Doc from org. Return the number of hits that were satisfied by a thread-bound object.
| |
| getInvocationCount | back to summary |
|---|---|
| public int getInvocationCount() Implements org. Doc from org. Return the number of client invocations.
| |
| getObjectCount | back to summary |
|---|---|
| public int getObjectCount() Implements org. Doc from org. Return the number of thread-bound objects created.
| |
| getStatsMixin | back to summary |
|---|---|
| public IntroductionAdvisor getStatsMixin() Return an introduction advisor mixin that allows the AOP proxy to be cast to ThreadLocalInvokerStats. | |
| getTarget | back to summary |
|---|---|
| public Object getTarget() throws BeansException Implements org. 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.
| |