分享

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

 昵称15242507 2015-01-12
如果是时区导致的问题,基本一眼能发现。但如果相差个十几秒,找起原因也是让人大费周折。

最近就碰到一个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

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多