java setdefaultfont,java时区setDefault效果

这篇博客讨论了如何在JPA和Hibernate中使用UTC时区存储日期和时间戳。设置默认时区为UTC可能会影响整个JVM,但如果有安全经理配置,可以设置线程局部值,从而只影响特定应用的线程。文章指出,没有直接的方法仅针对特定应用设置时区,除非能精确控制应用使用的线程集合。
摘要由CSDN通过智能技术生成

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.

解决方案

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).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值