Uploaded image for project: 'Application Server 3  4  5 and 6'
  1. Application Server 3 4 5 and 6
  2. JBAS-7811

Multithreaded access to remote JDBC datasource is broken

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 6.0.0.M3
    • 6.0.0.M2
    • JCA service
    • None
    • Hide

      Accessing datasources remotely is an anti-pattern. Redesign the application to invoke an EJB over RMI to retrieve data from the datasource.

      Show
      Accessing datasources remotely is an anti-pattern. Redesign the application to invoke an EJB over RMI to retrieve data from the datasource.

      Heavy access to a remote JDBC datasource (i.e. one configured with <use-java-context>false</use-java-context>) with multiple threads sometimes results in errors.

      The root of this problem is how the proxied datasource objects (e.g. ResultSet, Connection, Statement, etc.) are stored in the server-side HashMap for re-use by the remote client. These objects are, not surprisingly, keyed by their respective hash code (i.e. object.hashCode()). There are cases where different objects return the same hashCode which means a remote client can close someone else's ResultSets, etc. One can easily see this by turning on DEBUG logging and executing your test. For example:

      DEBUG [org.jboss.resource.adapter.jdbc.remote.WrapperDataSourceService] Created ResultSet proxy for invoker=jboss:service=invoker,type=jrmp, targetName=jboss.jca:service=DataSourceBinding,name=PostgresDS, cacheID=12215563
      DEBUG [org.jboss.resource.adapter.jdbc.remote.WrapperDataSourceService] Created ResultSet proxy for invoker=jboss:service=invoker,type=jrmp, targetName=jboss.jca:service=DataSourceBinding,name=PostgresDS, cacheID=12215563
      ...
      DEBUG [org.jboss.resource.adapter.jdbc.remote.WrapperDataSourceService] Closed ResultSet=12215563

      Of course, the other client using the ResultSet whose cacheID is "12215563" will break when it tries to access it later.

      To solve this problem, something other than hashCode should be used to key the HashMap entries.

            rhn-support-jbertram Justin Bertram
            rhn-support-jbertram Justin Bertram
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: