Atomikos Forum |
|
Environment: Atomikos 3.7.0, iBATIS 2.3.4.726, Spring 2.5.6, PostgreSQL 8.4.3, Jetty 6.1.19,
We are seeing an error which suggests that the Atomikos connection pool is giving a database connection to thread B before thread A has released the connection. Is this possible? The documentation/wikis suggest not, as Atomikos no longer does transaction interleaving, but our scenario suggests that this is what is happening...here are the details: - Thread A executes a long-running query (5-10 seconds), using an iBATIS DAO - While thread A is processing the ResultSet, thread B calls the same method from the DAO, causing thread A to throw the following exception: Cause: org.postgresql.util.PSQLException: This ResultSet is closed. at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:103) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80) at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:212) at org.springframework.orm.ibatis.SqlMapClientTemplate.executeWithListResult(SqlMapClientTemplate.java:249) at org.springframework.orm.ibatis.SqlMapClientTemplate.queryForList(SqlMapClientTemplate.java:296) This suggests that Thread B is using the same PreparedStatement object, and when it executes the statement, Thread A's ResultSet is closed (since a PreparedStatement cannot have more than one ResultSet). Since the PreparedStatement belongs to a specific database connection, that would also mean that this error could only occur if Thread B was assigned the same database connection as Thread A. We can reproduce the error consistently using the Atomikos connection pool, but if we substitute an Apache DBCP connection pool instead, we cannot reproduce the error. Here are the relevant snippets from our Spring configuration: <bean id="ourDataSource" class="com.atomikos.jdbc.nonxa.AtomikosNonXADataSourceBean"> <property name="user" value="xxxxx"/> <property name="password" value="xxxxx"/> <property name="url" value="jdbc:postgresql://${DB_HOSTNAME}/${DB_NAME}"/> <property name="driverClassName" value="org.postgresql.Driver"/> <property name="uniqueResourceName" value="XADBMS"/> <property name="poolSize" value="5"/> </bean> Any thoughts or guidance are appreciated.
Can you confirm - via toSting on the connection object (its a proxy but does still print its delegate connection) - that its the same instance?
Did some tests (JPA, but should not matter) and i can confirm this one - although i am using the AtomikosDatasourceBean - every thread uses the same DAO - maybe i need some more tests to provoke this one.
Guy, Torsten, thanks for the feedback.
We will try to create a test case to replicate this. For the moment we are working around the issue by synchronizing the method which makes the call to the DAO. We will also log the connection details as Torsten suggested, so that we can confirm that the connection is being reused. Thanks. |