I don't know how to get the jvm start up time. Can somebody put some light into this please?
I checked the api for System and Runtime classes.
Our jvm once started, runs for many weeks without stop. We have scripts to restart the jvm during deploys. But sometimes these scripts fails and don't do the restart of jvm.
By displaying the jvm start time we will be able to identify whether the script was successful or not. If not successful we will get the option to manually restart the jvm.
Yes I meant the time at which jvm started. Not the duration. Thanks for clarifying.
Then the only option is to store it in a variable
Regarding saving the jvm start up timestamp into a variable --
1. Caching the timestamp to a static variable or a singleton object instance will be one solution.
2. Use System.setProperty() to store the timestamp.
Both have drawbacks of garbage collection, class loader issues and security issues.
Sorry for not being clear about the class loader issues. I may be wrong in assuming that there will be class loader issues in this case. But I have seen class loader issues which I am writing below.
Suppose we keep the variable in a class as a static variable, initializes the variable when the class is loaded and the class is set to load soon after jvm starts;
there could be other instance of the class called "Class" if another class loader is involved during referencing the variable. In this scenario the actual timestamp is with the first instance of the Class; the second Class don't have the right timestamp.
What's brown and sticky? ... a stick. Or a tiny ad.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop