java Timezone setDefault effects

浪尽此生 提交于 2019-12-29 06:17:04

问题


following How to store date/time and timestamps in UTC time zone with JPA and Hibernate I want to set my application default time zone to UTC. My app runs on tomcat on a linux server along side some other apps. The server has other tomcat instances that run even more apps.

Will Timezone.setDefault(tz) affect the other apps on the same tomcat instance?

Will it affect other apps on other tomcat instances?

Is it possible to set the timezone only for the app? I loosely remember something about security manager settings to allow this.


回答1:


The default timezone setting in java is kind of screwy. by default, if you set the default timezone, it will affect the entire jvm. however, if you are running with a SecurityManager, and the current security context is not allowed to set the default, then the TimeZone.setDefault() method will instead set a thread local value (so any other code running on the same thread will see this value as the default, but the rest of the jvm will be unaffected). i don't think there is a way to set the default just for you "application" unless you can narrow your application to a specific collection of threads (highly unlikely).




回答2:


Would launching your app server with the java option -Duser.timezone=GMT do it for you?



来源:https://stackoverflow.com/questions/9891881/java-timezone-setdefault-effects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!