5 Replies Latest reply on Jun 27, 2012 5:43 PM by Vetle Leinonen-Roeim

    Global lock when creating beans

    Vetle Leinonen-Roeim Newbie



      We're having some performance issues in an application, and we are looking for culprits. This is a Java EE 6 application - EJBs, dependency injection, JSF, JPA, the works. While debugging, we think we're seeing that Weld has a global lock when creating bean instances. I'm referring to line 110 in org.jboss.weld.context.AbstractContext (https://github.com/weld/core/blob/1.1.8.Final/impl/src/main/java/org/jboss/weld/context/AbstractContext.java#L101). We're actually using 1.1.1-Final, though (but that particular code doesn't seem to have changed).


      Please excuse me if I'm completely wrong here, and feel free to use nasty words when telling me how it's really done if I'm mistaken... but if there's a global lock when creating beans:


      * how does this affect performance on high load systems, i.e. when creating lots and lots of beans?

      * if a bean has many EJBs that are injected (as we do in our case), does this mean that the lock is held until all the EJBs are looked up and injected? In our case the EJBs are even on a remote server.


      Here's a stack trace that lead us to wonder about this:


      "http-thread-pool-8080(201)" daemon prio=10 tid=0x00002aaae089d800 nid=0x5971 waiting on condition [0x000000005e00c000]
         java.lang.Thread.State: WAITING (parking)
              at sun.misc.Unsafe.park(Native Method)
              - parking to wait for  <0x000000068ba49870> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)
              at java.util.concurrent.locks.LockSupport.park(LockSupport.java:158)
              at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:811)
              at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireQueued(AbstractQueuedSynchronizer.java:842)
              at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(AbstractQueuedSynchronizer.java:1178)
              at java.util.concurrent.locks.ReentrantLock$NonfairSync.lock(ReentrantLock.java:186)
              at java.util.concurrent.locks.ReentrantLock.lock(ReentrantLock.java:262)
              at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:114)
              at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:99)
              at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:87)


      But perhaps Weld works fine, and thisis just a symptom of other errors.