Announcement Announcement Module
Collapse
No announcement yet.
Spring JDBC reentrancy question Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring JDBC reentrancy question

    Hi,

    With Spring JDBC, is it safe to declare SqlUpdate and MappingSqlQuery objects as statics and reuse them throughout the lifetime of a multithreaded application?

    I've tried this and it seems to work OK, but as with any threading issue, it's easy for issues to crop up in production that weren't seen in testing.

    Is there a large overhead involved in instantiating a MappingSqlQuery object and calling the compile method? Or does this just basically call prepareStatement?

    Thanks,
    Frank

  • #2
    SqlUpdate and MappingSqlQuery are both thread-safe.

    Comment


    • #3
      Indeed, Spring's JDBC operation objects are generally thread-safe. The only exception is BatchSqlUpdate, which is documented to be non-thread-safe and meant to be created on a per-operation basis.

      Creating JDBC operation objects per operation isn't really expensive, as it essentially just boils down to some parameter checks. But if you can reuse them as shared objects (ideally in instance variables of DAOs rather than in static fields), we recommend to do so.

      Juergen

      Comment

      Working...
      X