Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc: JdbcTemplate + NamedParameterJdbcTemplate + SimpleJdbcTemplate are thread-safe [SPR-11478] #16103

spring-projects-issues opened this issue Feb 24, 2014 · 0 comments
type: task


Copy link

@spring-projects-issues spring-projects-issues commented Feb 24, 2014

Oleksandr Gavenko opened SPR-11478 and commented

Official docs:

state that:

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.

It is awesome!

Recently I look to JdbcDaoSupport in order to simplify code and investigate that there are simpler approach:

<bean id="dataSource" ...>...</bean>
<bean id="jdbcTemplate"
    <constructor-arg ref="dataSource"/>

with simply:

private NamedParameterJdbcTemplate jdbcTemplate;

But javadoc doesn't say anything about thread safety for

I investigate sources and didn't found any state in this classes.

Is that classes thread safe?

Is them can be configured in context and reused across DAO code by injecting?

My goal to avoid such code:

private NamedParameterJdbcTemplate namedTemplate;
@Autowired(required = true)
public void setDataSource(final DataSource dataSource) {
    namedTemplate = new NamedParameterJdbcTemplate(dataSource);

and have only @Autowired NamedParameterJdbcTemplate namedTemplate;.

Please update javadoc for this classes if them are thread safe so any developer doesn't afraid to use them in convenient way...

No further details from SPR-11478

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
type: task
None yet

No branches or pull requests

2 participants