views:

198

answers:

2

Every few times I run my app on the development server it seems to deadlock. I'm not sure if it also deadlocks on the production server. I pause the threads and see that one of them is stuck at Permissions.implies:162 which is the start of a synchronized block.

What my code does is: on the home page, it sends 5 jquery requests at the same time to my InitServlet servlet that has the service method synchronized. Each time through the service method a different component is initialized, each of them taking about 2 seconds to initialize. It doesn't matter the order in which the threads reach the service method, and this only happens 5 times, during startup time of the server, so I think it should be okay to synchronize the service method.

Any suggestions on how to fix this deadlock, or does anyone know if its just a bug with the development server?

EDIT: Figured out where the deadlock happens, still don't know why though. While inside the lock for Permissions.implies, one thread calls Class.getDeclaredConstructors0, and never returns from it. Another thread is waiting to acquire the lock at Permissions.implies. The first thread that hangs on getDeclaredConstructors0, is doing the class initialization for the standard PersistenceManagerFactory class taken from the GAE example documents.

+1  A: 

You shouldn't be using requests to initialize your app like this: Instances of an App Engine app can be started or shut down at any time, and App Engine will spawn multiple concurrent instances to handle requests at any rate, so different VMs may get different subsets of the 'initialization' calls.

Nick Johnson
Yea its kind of a hack I did to get my app engine cold start time down to 3 seconds instead of 10 seconds. JDO takes quite a bit of time to initialize, ~2 seconds for getPersistenceManagerFactory, and for me about ~3 seconds on the first query I do because it builds some metadata about the model classes or something. Plus I'm using openid4java which also has significant startup time. So what I do is until initialization is complete I just serve pages straight out of the memcache if I can.
Kyle
If only App Engine supported this feature request -http://code.google.com/p/googleappengine/issues/detail?id=2690. Then I wouldn't have to worry about cold start times, and wouldn't have to spend a bunch of time optimizing my cold start time. Because as it is now, it seems that even with a good stream of traffic, there will always be loading requests for some users (eg. when a second or third JVM instance starts up).
Kyle