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

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

Comments

@spring-projects-issues
Copy link
Collaborator

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

Oleksandr Gavenko opened SPR-11478 and commented

Official docs:

http://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/jdbc.html#jdbc-JdbcTemplate-idioms

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:

http://stackoverflow.com/a/21992433/173149

<bean id="dataSource" ...>...</bean>
<bean id="jdbcTemplate"
     class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
    <constructor-arg ref="dataSource"/>
</bean>

with simply:

@Autowire
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
Labels
type: task
Projects
None yet
Development

No branches or pull requests

2 participants