Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Datasource and connection  RSS feed

 
Johnson Tmmet
Greenhorn
Posts: 8
  • 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
Sheriff
Posts: 36406
454
Eclipse IDE Java VI Editor
  • 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
Boost this thread!