File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Datasource and connection

 
Johnson Tmmet
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 33674
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Johnson,
No the calls to getConnection() don't have to be synchronized. The datasource/driver handles that for you.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic