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.
jiju ka wrote:I need to display the jvm start up time.
From the rest of your post it appears this means "The time at which the JVM started up" as opposed to, say "The length of time it took for the JVM to start up".
Anyway there's no method to find that value. However there's nothing stopping your application from saving the current time into a variable as the first thing it does. Would that be close enough?
Joined: Oct 12, 2004
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.
jiju ka wrote:Both have drawbacks of garbage collection, class loader issues and security issues.
Really, it's just a variable containing a Date object. Let's not get too carried away with such objections. Class loader issues???
Joined: Oct 12, 2004
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.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com