Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Thread-safety in javax.jdbc.DataSource?

843854Oct 15 2003 — edited Mar 1 2004

Hi.

I am using Tomcat with an Oracle DB, and using the Oracle DataSource and thin client implementation for my connection pooling. I am wondering if the javax.sql.DataSource class is threadsafe. That is, if I have a DataSource defined for my application in Tomcat's server.xml, and have code...


javax.sql.DataSource ds = null;
javax.naming.Context ctx = null;
java.sql.Connection conn = null;

ctx = new InitialContext();
ds = (DataSource)ctx.lookup("myDataSource");
conn = ds.getConnection();

... if two threads execute this code at the same time, will there be any threading problems? Will ds.getConnection() blowup? Or will two clients get different instances of DataSource that are not inter-dependant? Is this application server specific?

Could someone post a URL to someplace that discusses threading issues in these cases? Thanks.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 29 2004
Added on Oct 15 2003
10 comments
74 views