Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring JdbcTemplate and Threading

Is it safe to fork off a Thread to execute an insert using a JdbcTemplate in Swing.

It's a logging event and as much as possible I don't want it to affect perceived performance.

like image 279
Allain Lalonde Avatar asked Dec 04 '22 16:12

Allain Lalonde


2 Answers

Also note that its thread-safety is very well explained in the Spring 3.1 reference documentation:

13.2.1.2 JdbcTemplate best practices

Instances of the JdbcTemplate class are threadsafe once configured. This is important because it means that you can configure a single instance of a JdbcTemplate and then safely inject this shared reference into multiple DAOs (or repositories). The JdbcTemplate is stateful, in that it maintains a reference to a DataSource, but this state is not conversational state.

like image 196
stivlo Avatar answered Dec 06 '22 06:12

stivlo


This answer from the Spring forum says yes.t=25965

JdbcTemplate is a singleton that won't change state once it's set.

like image 41
duffymo Avatar answered Dec 06 '22 05:12

duffymo