Tomcat logs not showing correct time

We upgraded from Java 1.8 to openjdk 16.

And among many other issues that we have been struggling with for the past 3 weeks, we saw unusual behavior in tomcat. After deploying the webapp, we found that dates in the database were changed and logged GMT time instead of normal UTC time that is our server time. 

And after redeployment, the logs were also showing time in GMT. It was quite strange behavior. As the system has been working for past 8 years on Java 1.8 without any issues.

Finally we found out the issue to be a line of code that did set a default time zone. Here is the line of code that was in there for a eons, without any issues.

TimeZone.setDefault(TimeZone.getTimeZone("GMT"))

But I would say, openjdk probably handles this in a correct way. So this method sets a static value in the java process.

So this changes goes across all the webapps running in the same tomcat.

Conclusion

Be careful with setting default static values within Java. Any change would go across applications using the same java process and consequences may be devastating.

 

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.