Is the spring TransactionTemplate and SimpleJdbcTemplate thread-safe?

前端 未结 3 1255
暖寄归人
暖寄归人 2021-01-12 11:57

I am currently dealing with code where there is a singleton which is used by many threads and has no state except two fields for a TransactionTemplate and a SimpleJdbcTempla

3条回答
  •  抹茶落季
    2021-01-12 12:09

    TransactionalTemplate is thread safe.

    Finally, instances of the TransactionTemplate class are thread-safe, in that instances do not maintain any conversational state. TransactionTemplate instances do, however, maintain configuration state. So, while a number of classes may share a single instance of a TransactionTemplate, if a class needs to use a TransactionTemplate with different settings (for example, a different isolation level), you need to create two distinct TransactionTemplate instances.

    See https://docs.spring.io/spring/docs/5.2.3.RELEASE/spring-framework-reference/data-access.html#tx-prog-template-settings

    SimpleJdbcTemplate is deprecated. See https://docs.spring.io/autorepo/docs/spring/4.1.3.RELEASE/javadoc-api/index.html?org/springframework/jdbc/core/simple/SimpleJdbcTemplate.html

提交回复
热议问题