本文介绍了自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.
有关详细信息,请参阅 java.sun/j2se/1.5.0/docs/api/java/lang/management/RuntimeMXBean.html
For more info see java.sun/j2se/1.5.0/docs/api/java/lang/management/RuntimeMXBean.html
更多推荐
自JVM启动以来的时间
发布评论