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.