自JVM启动以来的时间

编程入门 行业动态 更新时间:2024-10-27 00:28:32
本文介绍了自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启动以来的时间

本文发布于:2023-06-02 12:23:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/447349.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时间   JVM

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!