aspose file tools*
The moose likes Java in General and the fly likes JVM start time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "JVM start time" Watch "JVM start time" New topic
Author

JVM start time

jiju ka
Ranch Hand

Joined: Oct 12, 2004
Posts: 306
I need to display the jvm start up time.

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.

Context:
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.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18152
    
    8

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?
jiju ka
Ranch Hand

Joined: Oct 12, 2004
Posts: 306
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.

Is there any other option to store in a variable?


Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18152
    
    8

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???
jiju ka
Ranch Hand

Joined: Oct 12, 2004
Posts: 306
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: JVM start time
 
Similar Threads
wlst and sun's jvm method to get Garbage collection start end information?
apache/tomcat
NullPointerException when invoking a web service
<script> Block in Html
Security Setup Problem With WAS V 3.5