Below analysis is for spring-flex 1.0.3.RELEASE and BlazeDS 188.8.131.5231
1. On the main 'startup' thread during application startup, the <flex:message-broker id="_messageBroker"/> tag creates and initializes the BlazeDS MessageBroker. As a side-effect of creating the MessageBroker, several ThreadLocals for the startup thread are created:[ DelegatingServletConfig, SystemSettings, MessageBroker, SerializationContext ]
2. The problem is that these thread locals on the startup are never cleared. Thus when Tomcat shuts the application down, it complains about the thread leak (see original error msg in this post).
3. The fix is fairly simple: in my 'blazeds-config.xml' file used for the blazeds servlet configuration, I added:
The CleanupBlazeDSThreadLocalsOnStartup bean is also constructed on the 'startup' thread, and thus can clear the corresponding thread locals that are left over from the message broker creation :
<!-- CleanupBlazeDSThreadLocalsOnStartup uses @PostConstruct in this servlet context -->
Spring flex does NOT cleanup BlazeDS thread locals created from main initialization thread,
which results in Tomcat reporting a memory leak at shutdown.
public void afterPropertiesSet()
// Clear the thread locals used by the 'main' startup thread.
// Otherwise get thread leak messages from Tomcat on application shutdown.
// Clear other thread local objects on the 'main' initialization thread
This worked - after doing the above, Tomcat no longer complains about BlazeDS-related memory leaks.