Results 1 to 2 of 2

Thread: ThreadLocalTargetSource help

  1. #1
    Join Date
    Jul 2005
    Posts
    3

    Default 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. #2
    Join Date
    Aug 2004
    Posts
    2,715

    Default Re: ThreadLocalTargetSource help

    Quote 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •