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