Announcement Announcement Module
Collapse
No announcement yet.
Some kind of deadlock when trying to get session Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Some kind of deadlock when trying to get session

    I get this when I pause my locked thread in Eclipse:
    Code:
    waiting for: org.apache.commons.pool.impl.GenericObjectPool  (id=62)	
    java.lang.Object.wait(long) line: not available [native method]	
    org.apache.commons.pool.impl.GenericObjectPool(java.lang.Object).wait() line: not available	
    org.apache.commons.pool.impl.GenericObjectPool.borrowObject() line: 810	
    org.apache.commons.dbcp.PoolingDataSource.getConnection() line: 95	
    org.apache.commons.dbcp.BasicDataSource.getConnection() line: 540	
    org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(javax.sql.DataSource) line: 112	
    org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy.getConnection() line: 107	
    org.springframework.orm.hibernate3.TransactionAwareDataSourceConnectionProvider(org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider).getConnection() line: 81	
    org.hibernate.jdbc.ConnectionManager.openConnection() line: 417	
    org.hibernate.jdbc.ConnectionManager.getConnection() line: 144	
    org.hibernate.jdbc.BatchingBatcher(org.hibernate.jdbc.AbstractBatcher).prepareQueryStatement(java.lang.String, boolean, org.hibernate.ScrollMode) line: 105	
    org.hibernate.loader.entity.EntityLoader(org.hibernate.loader.Loader).prepareQueryStatement(org.hibernate.engine.QueryParameters, boolean, org.hibernate.engine.SessionImplementor) line: 1561	
    org.hibernate.loader.entity.EntityLoader(org.hibernate.loader.Loader).doQuery(org.hibernate.engine.SessionImplementor, org.hibernate.engine.QueryParameters, boolean) line: 661	
    org.hibernate.loader.entity.EntityLoader(org.hibernate.loader.Loader).doQueryAndInitializeNonLazyCollections(org.hibernate.engine.SessionImplementor, org.hibernate.engine.QueryParameters, boolean) line: 224	
    org.hibernate.loader.entity.EntityLoader(org.hibernate.loader.Loader).loadEntity(org.hibernate.engine.SessionImplementor, java.lang.Object, org.hibernate.type.Type, java.lang.Object, java.lang.String, java.io.Serializable, org.hibernate.persister.entity.EntityPersister) line: 1785	
    org.hibernate.loader.entity.EntityLoader(org.hibernate.loader.entity.AbstractEntityLoader).load(org.hibernate.engine.SessionImplementor, java.lang.Object, java.lang.Object, java.io.Serializable) line: 47	
    org.hibernate.loader.entity.EntityLoader(org.hibernate.loader.entity.AbstractEntityLoader).load(java.io.Serializable, java.lang.Object, org.hibernate.engine.SessionImplementor) line: 41	
    org.hibernate.persister.entity.JoinedSubclassEntityPersister(org.hibernate.persister.entity.AbstractEntityPersister).load(java.io.Serializable, java.lang.Object, org.hibernate.LockMode, org.hibernate.engine.SessionImplementor) line: 2730	
    org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(org.hibernate.event.LoadEvent, org.hibernate.persister.entity.EntityPersister, org.hibernate.engine.EntityKey, org.hibernate.event.LoadEventListener$LoadType) line: 365	
    org.hibernate.event.def.DefaultLoadEventListener.doLoad(org.hibernate.event.LoadEvent, org.hibernate.persister.entity.EntityPersister, org.hibernate.engine.EntityKey, org.hibernate.event.LoadEventListener$LoadType) line: 346	
    org.hibernate.event.def.DefaultLoadEventListener.load(org.hibernate.event.LoadEvent, org.hibernate.persister.entity.EntityPersister, org.hibernate.engine.EntityKey, org.hibernate.event.LoadEventListener$LoadType) line: 123	
    org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(org.hibernate.event.LoadEvent, org.hibernate.persister.entity.EntityPersister, org.hibernate.engine.EntityKey, org.hibernate.event.LoadEventListener$LoadType) line: 177	
    org.hibernate.event.def.DefaultLoadEventListener.onLoad(org.hibernate.event.LoadEvent, org.hibernate.event.LoadEventListener$LoadType) line: 87	
    org.hibernate.impl.SessionImpl.fireLoad(org.hibernate.event.LoadEvent, org.hibernate.event.LoadEventListener$LoadType) line: 862	
    org.hibernate.impl.SessionImpl.get(java.lang.String, java.io.Serializable) line: 799	
    org.hibernate.impl.SessionImpl.get(java.lang.Class, java.io.Serializable) line: 792	
    net.bioclipse.lis.genericDAO.GenericDAO<T>.getById(long) line: 37	
    sun.reflect.NativeMethodAccessorImpl.invoke0(java.lang.reflect.Method, java.lang.Object, java.lang.Object[]) line: not available [native method]	
    sun.reflect.NativeMethodAccessorImpl.invoke(java.lang.Object, java.lang.Object[]) line: not available	
    sun.reflect.DelegatingMethodAccessorImpl.invoke(java.lang.Object, java.lang.Object[]) line: not available	
    java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object...) line: not available	
    org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(java.lang.Object, java.lang.reflect.Method, java.lang.Object[]) line: 287	
    org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint() line: 181	
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed() line: 148	
    net.bioclipse.lis.genericDAO.FinderIntroductionInterceptor.invoke(org.aopalliance.intercept.MethodInvocation) line: 18	
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed() line: 170	
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[]) line: 176	
    $Proxy24.getById(long) line: not available	
    net.bioclipse.lis.business.project.ProjectManager.getExperiment(long) line: 67	
    sun.reflect.NativeMethodAccessorImpl.invoke0(java.lang.reflect.Method, java.lang.Object, java.lang.Object[]) line: not available [native method]	
    sun.reflect.NativeMethodAccessorImpl.invoke(java.lang.Object, java.lang.Object[]) line: not available	
    sun.reflect.DelegatingMethodAccessorImpl.invoke(java.lang.Object, java.lang.Object[]) line: not available	
    java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object...) line: not available	
    org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(java.lang.Object, java.lang.reflect.Method, java.lang.Object[]) line: 287	
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[]) line: 165	
    $Proxy25.getExperiment(long) line: not available	
    lis_gui.setup.explorer.model.folders.Experiment.refresh() line: 28	
    lis_gui.setup.explorer.ExplorerContentProvider.treeModelUpdated(lis_gui.setup.explorer.model.TreeEvent) line: 107	
    lis_gui.setup.explorer.model.treeLeafs.Plate(lis_gui.setup.explorer.model.Model).fireUpdate() line: 8	
    lis_gui.setup.explorer.View$2$1.run() line: 135
    I am not sure what it is waiting for. I am trying to reload my persistant objects from a thread which is started from the gui. It works perfectly when done from the main thread but not from my other thread. Do anybody have an idea or hint at what might be wrong?

  • #2
    It looks like the code is deadlocked in the connection pool when trying to borrow a connection. I would presume all the connections are already allocated and it can't create anymore. It's therefore going to wait until a connection is freed up.

    Comment


    • #3
      Originally posted by karldmoore View Post
      It looks like the code is deadlocked in the connection pool when trying to borrow a connection. I would presume all the connections are already allocated and it can't create anymore. It's therefore going to wait until a connection is freed up.
      But that won't ever happend as far as I can see. What can I do?

      Comment


      • #4
        Originally posted by Jonathan Alvarsson View Post
        But that won't ever happend as far as I can see. What can I do?
        I don't understand how this can't ever happen, it seems to be. If you leave it on the main thread, then it's going to use the same thread bound connection. As you push it onto another thread, it's going to try and get a new thread bound connection.

        Comment


        • #5
          Originally posted by karldmoore View Post
          I don't understand how this can't ever happen, it seems to be. If you leave it on the main thread, then it's going to use the same thread bound connection. As you push it onto another thread, it's going to try and get a new thread bound connection.
          Okey I agree with what you say but I don't understand why this implies that it will get a free connection sometime. When my thread deadlocks it is the only thread actually running. The main thread is only waiting for new input from the user by the gui. So the main thread is certainly not gonna be putting any connections back in the pool...

          Do anyone know how many connections the pool contains? (It seems to me like there aren't enough) I guess some are tied up for Hibernate lazy loading and this means I probably would like to have more of them?

          Another question that arise is: do I have to do something special when a thread ends like closing a session in special way for the connections to be returned?

          Comment


          • #6
            Originally posted by Jonathan Alvarsson View Post
            Okey I agree with what you say but I don't understand why this implies that it will get a free connection sometime. When my thread deadlocks it is the only thread actually running. The main thread is only waiting for new input from the user by the gui. So the main thread is certainly not gonna be putting any connections back in the pool...
            I can't see any transaction support in the stracktrace. I might make sense to make one of your beans transactional e.g. ProjectManager. Are you using a release mode in the Hibernate configuration?
            http://www.springframework.org/docs/...ansaction.html

            Originally posted by Jonathan Alvarsson View Post
            Do anyone know how many connections the pool contains? (It seems to me like there aren't enough) I guess some are tied up for Hibernate lazy loading and this means I probably would like to have more of them?
            The number of connections will be defined in the configuration. If you aren't setting this yourself, the JavaDoc might give you the default.

            Originally posted by Jonathan Alvarsson View Post
            Another question that arise is: do I have to do something special when a thread ends like closing a session in special way for the connections to be returned?
            If you are letting Spring manage transactions and connections there shouldn't be anything to worry about.

            Comment


            • #7
              Originally posted by karldmoore View Post
              I can't see any transaction support in the stracktrace. I might make sense to make one of your beans transactional e.g. ProjectManager. Are you using a release mode in the Hibernate configuration?
              http://www.springframework.org/docs/...ansaction.html
              Most of my methods are configured as transactions. This one is not because it is a getter that loads objects from the database and in order to get the lazy loading to work the sessions needs to be open and I have not succeded in having transactional methods session kept open for lazy loading after the method that loads i finished. I don't think I have defined a release mode but my datasource been looks like this:

              Code:
              <bean 
                  id="dataSource"
                  class="org.apache.commons.dbcp.BasicDataSource"
                  destroy-method="close"> ...
              Will the destroy-method="close" do something like setting the release mode?

              Originally posted by karldmoore View Post
              The number of connections will be defined in the configuration. If you aren't setting this yourself, the JavaDoc might give you the default.
              I figured out how to set the number of connections and I also figured out that each of my object loading ties up one session for the lazy loading to work. And when I have used up all connections my thread deadlocks waiting for more.

              How is this to be done? I need the lazy loading but I can't afford to have one database connection for each time I load something from the database...

              I guess what I need is for the session to grab a connection from the pool when it needs one and put it back when it is not using it... or how is this problem normally solved?

              Comment


              • #8
                Originally posted by Jonathan Alvarsson View Post
                Most of my methods are configured as transactions. This one is not because it is a getter that loads objects from the database and in order to get the lazy loading to work the sessions needs to be open and I have not succeded in having transactional methods session kept open for lazy loading after the method that loads i finished. I don't think I have defined a release mode.
                I'm not quite sure this is going to work. I'm not sure you want to share Hibernate Session between threads as it isn't thead-safe. The release mode I was refering to is here.
                http://www.hibernate.org/hib_docs/v3...ection-release

                Originally posted by Jonathan Alvarsson View Post
                I figured out how to set the number of connections and I also figured out that each of my object loading ties up one session for the lazy loading to work. And when I have used up all connections my thread deadlocks waiting for more.

                How is this to be done? I need the lazy loading but I can't afford to have one database connection for each time I load something from the database...

                I guess what I need is for the session to grab a connection from the pool when it needs one and put it back when it is not using it... or how is this problem normally solved?
                This all just doesn't sound right. I'd have to play and a look into this more to understand what's going on.

                Comment


                • #9
                  See also this post it is somewhat related to the same problem...

                  Comment

                  Working...
                  X