views:

75

answers:

1

Hi guys,

I'm unhappy from GAE because - One can't have a global variable and the 'synchronize' keyword. Instead one have to catch a basically DB transcational exception and retry in a while loop - which will eat all my free CPU time and will start costing me money as I reach the google's qouata.

  1. Is it safe to use synchronize inside a doPost() in tomcat? (i guess that it's ok as long as all the servlets are running on on 1 VM?). If not in all tomcat configurations, how do I configure tomcat to make it safe?

How can I convert a GAE app to my own tomcat server? - How to install DataNucleus Access Platform on tomcat?

Best regards

+2  A: 

App Engine is fundamentally a distributed system. You can't use synchronization primitives, because your app will be running on muliple VMs and multiple machines. Relying on running on a single VM will put very hard limits on the scalability of your app.

Why do you want to do this? There's almost certainly a way to achieve it without locking.

Nick Johnson
thanks for asking. Say a user is asking for the best fit free resource. We need to sync it so two users won't be allocated with the same resource.I know we can use db transaction and if exception is thrown then we retrie in a loop but this solution waste the cpu and db. It's like not using sleep command and instead looping for nothing waisting cpu time...
bach
Just assume that the algo for finding 'best fit' is expensive - then the problem is more concrete
bach
As I've already said, it only 'loops' if there's a conflict. The vast majority of the time, there won't be contention, so it will execute fine the first time. And as others have said, optimistic concurrency is a common and valid approach to this, when contention is low.
Nick Johnson