Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Is there a way to find out the time since the JVM started?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
131 views
Welcome To Ask or Share your Answers For Others

1 Answer

Use this snippet:

long jvmUpTime = ManagementFactory.getRuntimeMXBean().getUptime();

or:

long jvmStartTime = ManagementFactory.getRuntimeMXBean().getStartTime();

This is the correct way of retrieving JVM up-time.

For more info see RuntimeMXBean


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...