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