Set a limit on JDBC query time in JBoss EAP

Solution Verified - Updated -

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 4
    • 5
    • 6
    • 7

Issue

  • How can a limit on JDBC query time be set in JBoss EAP?
  • Can JBoss detect and cancel deadlocking operations in the database?
  • Query time out is not enforced

Resolution

  • JBoss cannot detect deadlock within the database but can request that the JDBC driver enforce query timeout.
  • Set the default query timeout for transactions using <query-timeout> (seconds)
    • EAP 7/6 query timeout is configured in the timeout configuration for an XA or non-XA datasource
      • <JBOSS_HOME>/docs/schema/jboss-as-datasources_1_*.xsd
      • <JBOSS_HOME>/docs/schema/wildfly-datasources_*.xsd
    • EAP 5/4 query timeout is configured in <JBOSS_HOME>/server/$PROFILE/deploy/*-ds.xml
  • It is also possible to set the query timeout based on the remaining time before transaction timeout.
  • Set query timeout explicitly, per query using Statement.setQueryTimeout(int) programmatically in your application.

External Dependencies/Limitations

  • Query timeout enforcement is dependent upon the underlying JDBC driver implementation and the implementation of the database server.
  • Depending on driver implementation, enforcement of query timeout may also be subject to network interruptions.
  • Query timeout is unsupported in certain older PostgreSQL drivers.

Additional References

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments