自 JVM 启动以来的时间 [英] time since JVM started

查看:17
本文介绍了自 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 启动以来的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆