Announcement Announcement Module
Collapse
No announcement yet.
ThreadLocalTargetSource help Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ThreadLocalTargetSource help

    Hi all,

    I would like to destroy / cleanup a bean that has its target set as a
    ThreadLocalTargetSource object. I am using ApplicationContext to create the
    mentioned bean. What's the best way to cleanup only the ThreadLocal bean?

    I could call ApplicationContext.destroy() but it would close the context and
    destroy all singletons. Is it approximate to get a reference to
    ThreadLocalTargetSource and cast it to DisposableBean and invoke destroy()
    directly? If so, how do I do it?

    Here's my config:

    Code:
        <bean id="sessionManager"
    class="org.springframework.aop.framework.ProxyFactoryBean">
            <property name="proxyInterfaces" value="foo.SessionManager"/>
            <property name="targetSource">
                <bean
    class="org.springframework.aop.target.ThreadLocalTargetSource">
                    <property name="targetBeanName" value="sessionManagerImpl"/>
                </bean>
            </property>
        </bean>
    
        <bean id="sessionManagerImpl" class="foo.SessionManagerImpl"
    singleton="false"/>
    On another note, I was checking the ThreadLocalTargetSource
    source and the way it's clearing the ThreadLocal variable is like this:

    Code:
    	public void destroy&#40;&#41; &#123;
                            .........
    		this.targetSet.clear&#40;&#41;;
    		
    		// clear ThreadLocal
    		this.targetInThread = null;
    	&#125;
    Shouldn't we call this.targetInThread.set(null) instead?


    Thanks for your help!

    Vincent

  • #2
    Re: ThreadLocalTargetSource help

    Originally posted by wsshek
    Hi all,

    I would like to destroy / cleanup a bean that has its target set as a
    ThreadLocalTargetSource object. I am using ApplicationContext to create the
    mentioned bean. What's the best way to cleanup only the ThreadLocal bean?
    If you need control over a ThreadLocal variable I would advise to not use ThreadLocalTargetSource, but to manage the variable yourself as ThreadLocal. So you are able to change its contents as you see it fits.

    Regards,
    Andreas

    Comment

    Working...
    X