Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get server startup info

 
Clarence Dy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Is there a way for a servlet to get the time stamp on when the app server (or the JVM) was started? Is this even possible?

I was looking into deploying another app with a servlet that loads on startup. Basically this servlet would just carry the date/time stamp when it started.

My other application would then need to talk to this servlet using other communication methods. This seem like a crude solution and I was hoping to know if there's an easier way. Thank you.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64826
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would you use a servlet for this when you could just use a context listener to place the timestamp in application context?
 
Rashid Mayes
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using java.lang.management.ManagementFactory:

it sounds like you are interested in

ManagementFactory.getRuntimeMXBean().getStartTime();

and

ManagementFactory.getRuntimeMXBean().getUptime();

There are several other beans you can use to get more information. Start by looking at the java.lang.management.*.

Here is another exampe.
 
Clarence Dy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much, Rashid! This is very helpful.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic