The default mode of google appengine is that each instance runs in single threaded mode. They handle concurrent requests by spawning new JVM instances if it is required.
A new switch though allows appengine to handle multiple requests in parallel on the same instance.
What I've been doing so far in regularly hosted Java web applications in order to ensure thread safety between requests of the same user was to synchronize on the http session (or on a value stored in the session). Spring does it as well (using the synchronizeOnSession flag).
This is not possible in GAE because the HttpSession (together with all variables it stores) is always new in each http request. That is, the hashcode is always different. So synchronizing on that has no effect whatsoever. But even if this was possible, appengine does not guarantee that two requests from the same user will be handled by the same instance (something like sticky session).
The new flag of appengine warns that:
If you wish to use concurrent requests, your application code needs to use proper thread synchronization before you enable .
So, how can I ensure that my application will be thread safe regarding operations from the same user? I'm mostly concerned on actions that the user can perform on data existing in his http session. I obviously only care about synchronizing requests of the same user in the same instance.
Thanks
A few notes:
Try keeping application state on client side, i.e. handle it with javascript. There you can prevent user to send multiple requests at a time or out-of-order.
Since GAE can run several instances in parallel on different servers, your effort to synchronize on session will work most of the time, but is not guaranteed to work all of the time.
I suppose what you are trying to do is prevent user to put his data in inconsistent state (by executing actions out-of-order). Ultimately the only point of sync in GAE is Datastore transactions. Use them to keep data in consistent state.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With