This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC 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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Datasource and connection" Watch "Datasource and connection" New topic
Author

Datasource and connection

Johnson Tmmet
Greenhorn

Joined: Oct 27, 2005
Posts: 8
Hi,
I have a question.I use datasource.getConnection() to get the connection as
below.
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;
try{
DataSource dataSource = serviceLocator.getInstance().getDataSource
(dataSourceName);
conn = dataSource.getConnection();
}
catch(Exception ex)
{
//do something here
}
return conn;
}
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30076
    
149

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


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Datasource and connection
 
Similar Threads
Connection Pooling Managment
getting user name from session inside getconnection method
possibility of getting user name from session inside getconnection method
Accessing session object from getConnection method
Datasource