This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

ThreadLocalTargetSource help

Jul 14th, 2005, 08:39 PM

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?

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.