File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Datasource and connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Datasource and connection" Watch "Datasource and connection" New topic

Datasource and connection

Johnson Tmmet

Joined: Oct 27, 2005
Posts: 8
I have a question.I use datasource.getConnection() to get the connection as
My question is does getConnection() have to be synchronized? Won't the
datasource manage the connections in the pool.

public Connection static synchronized getConnection(){
Connection conn = null;
DataSource dataSource = serviceLocator.getInstance().getDataSource
conn = dataSource.getConnection();
catch(Exception ex)
//do something here
return conn;
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 32818

No the calls to getConnection() don't have to be synchronized. The datasource/driver handles that for you.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: Datasource and connection
It's not a secret anymore!