• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

JVM start time

 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 28371
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 28371
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.





 
joke time: What is brown and sticky? ... ... ... A stick! Use it to beat this tiny ad!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic