Monday, April 13, 2009

The JVM Dance: Follow your app from JVM to JVM on GAE/J

When you upload an app to the Google App Engine/J environment HTTP-requests sent to your app will be served by multiple JVM:s (or more specifically, requests will be served by one or more JVM:s).

This means that two consecutive HTTP-requests sent by the same user to the same GAE/J-app may very well be served by two different JVM:s.

The fact that multiple JVM:s are serving your requests might not be apparent since the GAE/J infrastructure makes sure that all objects you store in the session (HttpSession) are available across all JVM:s serving your app (this is done by temporarily storing your session objects in the datastore). On the other hand, you might notice that code within static blocks will be executed once for each JVM loading your code.

To identify which JVM that is serving a request, use the following code:
int currentJvm = Runtime.getRuntime().hashCode();

I've written a small JSP-file that will show you which JVM that is serving the current request, and alert you when two consecutive HTTP-requests are being served by different JVM:s -- let's term this jumping between JVM:s the "GAE/J JVM dance" :-)
jvmdance.jsp: http://pastebin.com/f127200f1

8 comments:

  1. How many differents JVMs did you see ?

    ReplyDelete
  2. I've seen the follow up but too late ;-)
    Thanks for these posts.

    ReplyDelete
  3. Really good site thank you so much for your time in writing the posts for all of us to learn about. It will be very useful for me.
    share market
    stock market
    Indian Stock Market Tips

    ReplyDelete
  4. This is a great post ! it was very informative. I look forward in reading more of your work.
    Intraday Nifty Future Tips
    Share market tips
    Share and Earn

    ReplyDelete
  5. I was very encouraged to find this site. I wanted to thank you for this special read.
    Commodity tips
    Stock Market
    Share Market
    Nse Tips
    Bse Tips

    ReplyDelete
  6. Hi there! I just would like to give a huge thumbs up for the nice info you will have right here on this post. I will likely be coming again to your weblog for extra soon.
    Buy Property
    Sell Property
    Invest in Property
    Find real estate agent

    ReplyDelete
  7. I am very much pleased with the contents you have mentioned. I enjoyed every little bit part of it. It contains truly information. I want to thank you for this informative read.
    Intraday Calls || Nifty Trading || Nifty Intraday Tips.

    ReplyDelete