通过HP-UNIX jvm获取的时间与操作系统不一致问题分析

freish 发布于 2012/02/07 14:47
阅读 945
收藏 0

【开源中国 APP 全新上线】“动弹” 回归、集成大模型对话、畅读技术报告”

如果是时区导致的问题,基本一眼能发现。

但如果相差个十几秒,找起原因也是让人大费周折。

最近就碰到一个jvm时间(System.currentTimeMillis)与操作系统时间不一致的问情形,用的HP-UNIX系统,多台服务器的时间同步是用了一个NTP服务。

 原因如下:

hotspot jvm使用gettimeofday系统调用来获取日期和时间信息。但在HP-UX中,由于性能原因,在应用启动后,采用了一种使用CPU 时钟周期数的机制来计算当前时间。带来的后果就是,使用date命令,adjtime函数或者形如ntp的时间同步服务工具修改系统时间后,java应用未能在重启之前反映出这种修改。如果要求操作系统时间修改立马反映到java应用中,可以使用-XX:+UseGetTimeOfDay选项来告诉JVM使用gettimeofday系统调用,但需要注意的是,这会使性能下降。

因为hotspot本身就是使用的gettimeofday系统调用,所以不会有这个问题

The HotSpot JVM uses the gettimeofday() system call to obtain date and time
information. For performance reasons a new mechanism that uses the number of CPU
ticks since the application started is used to calculate the current time. As a result,
changes to the system date or time using the date command, adjtime() function, or
time synchronization utilities such as ntp will not be reflected in the date and time
that the Java program returns until the process is restarted.
If your application requires that system time changes are immediately reflected, you
can use the -XX:+UseGetTimeOfDay option to tell the JVMto use the gettimeofday
call instead of the new, lightweight mechanism. However you may notice a drop in

performance

引用文出处:

http://bizsupport2.austin.hp.com/bc/docs/support/SupportManual/c02697864/c02697864.pdf

加载中
0
红薯
红薯
真实经验,顶
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部