自JVM启动以来的时间 [英] time since JVM started
本文介绍了自JVM启动以来的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法找出自JVM启动以来的时间?
Is there a way to find out the time since the JVM started?
当然,除了在 main
,因为在我的场景中我正在编写库代码,并且要求在启动后立即调用某些东西是太麻烦。
Of course, other than starting a timer somewhere near the beginning of main
, because in my scenario I am writing library code and the requirement that something be called immediately after startup is a too burdensome.
推荐答案
使用此代码段:
long jvmUpTime = ManagementFactory.getRuntimeMXBean().getUptime();
或:
long jvmStartTime = ManagementFactory.getRuntimeMXBean().getStartTime();
这是检索JVM正常运行时间的正确方式。
This is the correct way of retrieving JVM up-time.
有关详细信息,请参阅 http://java.sun.com/j2se/1.5.0/docs/api/java/lang/management/RuntimeMXBean.html
For more info see http://java.sun.com/j2se/1.5.0/docs/api/java/lang/management/RuntimeMXBean.html
这篇关于自JVM启动以来的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文