views:

104

answers:

2

I've got a large multi-threaded webapp in which I am passing in jdbcTemplates into DAO classes via constructor injection. Is this a multi-threading risk? Should I be passing in just the datasource instead?

+1  A: 

Spring IOC runs in only 1 thread on start up so threading issues are not an issue there. Spring will not publish the DAO as a bean (to be retrieved from elsewhere) until it is completely constructed.

krock
+1  A: 

There is no risk of multithreading, you can safely pass jdbcTemplate into DAO classes. In every query execution method, it essentially talks to the injected datasource and does not use any state which could lead to any side effect.

Amit Goyal