TomcatExpert

Thread pooling and TimeZone.setDefault()

posted by SpringSource on May 20, 2010 12:10 PM

Multiple applications inside a single container will pollute threads with wrong Time Zone information.

Running multiple applications in a single container that rely on the TimeZone.getDefault() method will cause problems where the time zone can not be reset inside the thread.  For instance, if one application calls TimeZone.setDefault("GMT"), it will affect the TimeZone (or ZoneInfo) instance over the entire thread.  If a second application is then run on that thread, it will pick up the default set by the previous container. 

There is not much Tomcat since this particular problem lies in the JVM. With this said, there are couple of options, however:

1. Run each app on its own Tomcat instance
2. Write a valve/filter that resets the default timezone.  Unfortunately there is not a way to divide the thread pool and assign them per application.

Option 1 would be the recommended and simple solution and use option 2 as the fallback.


 

For more than 10 years, SpringSource employees have been supporting Apache technologies, with unparalleled experience and commitment to the Apache Software Foundation. More than 400 of the Fortune 500 count on SpringSource to support their mission-critical business applications. Leaders of the Apache Software Foundation, including Board Members, work at SpringSource and dedicate a significant amount of time further developing the Apache Tomcat open source project. Over the last 2 years, 95% of the issues fixed in the Apache Tomcat project were fixed by SpringSource engineers. For more information on how SpringSource can help your enterprise, see the SpringSource website, or call 800/444-1935.

Comments

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.