Multiple JdbcTemplate instances or not?

后端 未结 4 1727
一向
一向 2021-02-04 01:01

From what I understand, both DataSource and JdbcTemplates are threadsafe, so you can configure a single instance of a JdbcTempla

4条回答
  •  名媛妹妹
    2021-02-04 02:03

    Inherently spring is very subtle about best practices.

    JdbcTemplate is thread-safe, notably lock-free (v4.2.4). Meaning it should not cause performance degradation when shared between concurrent threads*. Thus, there are no compelling reasons for more than one instance per data source.

    Speculative note: this section is indeed confusing. Probably due to historical (evolutionary) reasons. Maybe spring had per dao policy in the past due to non thread safety or poor understading of domain at a time. Similar to xml based configuration "disaster". Nowadays spring renounce opinionated views and strive to be flexible instead. Which, unfortunately, led to bad design choices being acknowleged only covertly.

    * measure don't guess

提交回复
热议问题