4

I'm tracking this error for a while now, it hapens on irregular basis unpredictibly and I haven't find a way to reproduce it for now.

Our environment

  • linux centos 5.3 hosting one jboss 5.1 app server
  • linux centos 5.3 hosting one oracle 10g XE db
  • windows server 2003 R2 hosting another oracle 10g XE db

Programming environment

  • seam 2.1
  • hibernate
  • JSF 1.2

Most of this errors happens on a "APPLICATION" scope seam component, but it also happened elswhere.

Wea are using XA-datasource to access the databases.

It appeares that tis is also some sort of a bug in jboss 5.1 look here, but we do not have queries or requests that last 60 seconds.

What could be the possible reason for this kind of errors?

The final stack trace of the error:

Caused by: java.sql.SQLException: Unable to obtain lock in 60 seconds: org.jboss.resource.adapter.jdbc.xa.XAManagedConnection@1d314d
    at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.tryLock(BaseWrapperManagedConnection.java:267)
    at org.jboss.resource.adapter.jdbc.WrappedConnection.lock(WrappedConnection.java:79)
    at org.jboss.resource.adapter.jdbc.WrappedConnection.prepareStatement(WrappedConnection.java:237)
    at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:534)
    at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:452)
    at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:161)
    at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1573)
    at org.hibernate.loader.Loader.doQuery(Loader.java:696)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
    at org.hibernate.loader.Loader.doList(Loader.java:2228)
simonC
  • 4,101
  • 10
  • 50
  • 78

1 Answers1

1

There are some tricks you can do in your app-ds.xml file. If you have one that is? For instance, if you are running mysql you can write

<check-valid-connection-sql>SELECT 1</check-valid-connection-sql>

You should also look in the config file for your database, and maybe you can tweak some settings there. For instance, wait_timeout, max_connections etc. Especially you can consider increasing the latter. Maybe you have many idle sql connections that are not doing anything, and when the pool is reached, it will wait until one is reached, and then you get this exception?

Also remember that Application scoped components are thread safe. Thus make sure that you limit application scoped components and session components as much as possible. Better to use Event and Conversation scoped components where applicable.

Shervin Asgari
  • 23,901
  • 30
  • 103
  • 143
  • I used the in the pool config, but with no results still the mentioned error poped up, I was avoiding the because I thaught that it is not optimal for production environments...does this setting bring some significant performance overhead? In the documentation I also noticed the setting that should validate the connection when the connection is checked out of the pool, but it seam that is already on true by default. – simonC Sep 26 '11 at 07:29
  • We have also the max_connections set to 500 which should be enouhg, and wait_timeout to 28800 which should also be enough mybe there is realy a problem in the Application/Session scoped components, we do not have a lot of them but they are used in almost every request. How can I test if this is a problem? – simonC Sep 26 '11 at 07:34
  • 1
    You can try to use JMeter http://jakarta.apache.org/jmeter/ and issue lots of request. There also might be other performance stuff you can do. Using factories and unwrap, and less state as possible. – Shervin Asgari Sep 26 '11 at 07:42
  • Yes that is exactly what are we doing...loading tests with Jmeter, I would like aslo to understand more what exactly this exception means...does it mean that some transaction is locking a some row in a db table for 60 seconds? Or am I missing something here? – simonC Sep 26 '11 at 15:56