org.springframework.aop.target
Class ThreadLocalTargetSource

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

public final class ThreadLocalTargetSource
extends AbstractPrototypeTargetSource
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.

Version:
$Id: ThreadLocalTargetSource.java,v 1.8 2004/03/18 02:46:13 trisberg Exp $
Author:
Rod Johnson

Field Summary
 
Fields inherited from class org.springframework.aop.target.AbstractPrototypeTargetSource
logger
 
Constructor Summary
ThreadLocalTargetSource()
           
 
Method Summary
 void destroy()
          Dispose of targets if necessary; clear ThreadLocal.
 int getHits()
           
 int getInvocations()
           
 int getObjects()
           
 IntroductionAdvisor getStatsMixin()
          Return an introduction advisor mixin that allows the AOP proxy to be case to ThreadLocalInvokerStats.
 java.lang.Object getTarget()
          Implementation of abstract getTarget() method.
 void releaseTarget(java.lang.Object o)
           
 
Methods inherited from class org.springframework.aop.target.AbstractPrototypeTargetSource
afterPropertiesSet, getTargetBeanName, getTargetClass, isStatic, newPrototypeInstance, setBeanFactory, setTargetBeanName
 
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

releaseTarget

public void releaseTarget(java.lang.Object o)
Specified by:
releaseTarget in interface TargetSource
See Also:
TargetSource.releaseTarget(java.lang.Object)

destroy

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

Specified by:
destroy in interface DisposableBean
See Also:
DisposableBean.destroy()

getInvocations

public int getInvocations()
Specified by:
getInvocations in interface ThreadLocalTargetSourceStats
Returns:
all clients given one of us

getHits

public int getHits()
Specified by:
getHits in interface ThreadLocalTargetSourceStats
Returns:
hits that were satisfied by a thread bound object

getObjects

public int getObjects()
Specified by:
getObjects in interface ThreadLocalTargetSourceStats
Returns:
thread bound objects created

getStatsMixin

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



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