获得应用程序正常运行 [英] Get application uptime

查看:141
本文介绍了获得应用程序正常运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在java中编写了一个应用程序,我想添加一个功能来报告应用程序的正常运行时间。 JVM中是否有可以执行此操作的类/方法?

I've written an application in java and I want to add a feature to report the uptime of the application. Is there a Class/method in the JVM that can do this?

应该在应用程序启动时保存时间戳,然后计算当前正常运行时间的差异。要求?

Should I save the timestamp when application starts, then calculate the difference with the current uptime in the moment of the request?

在Java中检索应用程序正常运行时间的更好方法是什么?

What's a better way to retrieve application uptime in Java?

推荐答案

你可以使用 RuntimeMXBean.getUptime()

RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean();
long uptime = rb.getUptime();

这篇关于获得应用程序正常运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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