freish

          HP-UNIX上通過jvm獲取的時間與操作系統時間不一致的原因與解決方案

          最近碰到一個jvm時間(System.currentTimeMillis)與操作系統時間不一致的問題,用的HP-UNIX系統,多臺服務器的時間同步是用了一個NTP服務。時間同步策略:時間和主服務器的誤差大于1秒。

           

          經過查找資料,終于發現原因,如下:


          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

          -XX:+UseGetTimeOfDa

          Instructs the JVM to use the GetTimeOfDay call instead of the mechanism used in
          earlier versions whereby the number of cpu ticks since the application started is used
          to calculate the current time. With this new mechanism, changes to the system date or
          time using date(1), adjtime(2), or time synchronization utilities such as ntp are
          not reflected in the date and time that Java™ returns, until the process is restarted. If
          your application requires that Java™ immediately reflects such system time changes,
          you can use the -XX:+UseGetTimeOfDay option, however you may notice a drop in
          performance.

           

          以上信息引用處:http://bizsupport2.austin.hp.com/bc/docs/support/SupportManual/c02697864/c02697864.pdf

          hotspot jvm使用gettimeofday系統調用來獲取日期和時間信息。在HP-UX中,由于性能原因,在應用啟動后,采用了一種使用CPU 時鐘周期的機制來計算當前時間。帶來的后果就是,使用date命令,adjtime函數或者形如ntp的時間同步服務工具修改系統時間后,java應用未能在重啟之前反映出這種修改。如果要求操作系統時間修改立馬反映到java應用中,可以使用-XX:+UseGetTimeOfDay選項來告訴JVM使用gettimeofday系統調用,但需要注意的是,這會使性能下降。

          posted on 2012-02-07 14:15 Freish 閱讀(804) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          導航

          統計

          留言簿

          文章檔案

          搜索

          最新評論

          主站蜘蛛池模板: 焦作市| 天门市| 宝兴县| 司法| 志丹县| 自治县| 河池市| 徐州市| 安塞县| 武安市| 稻城县| 尚义县| 乡宁县| 唐河县| 易门县| 历史| 娄烦县| 曲阳县| 屯门区| 伊金霍洛旗| 乌苏市| 喀喇| 古浪县| 壶关县| 崇文区| 仪陇县| 上饶市| 桃江县| 陈巴尔虎旗| 平阴县| 宣武区| 宁陕县| 个旧市| 永康市| 沙雅县| 肥乡县| 遂平县| 时尚| 奉化市| 孝感市| 堆龙德庆县|