I'm having a problem configuring the timeout that is used when establishing a new connection to an Oracle database when using a connection pool.
I'm using DBCP
in Tomcat and XML to configure the resource .
In the source code I get a DataSource
and connection like this:
DataSource ds = (DataSource) envCtx.lookup("jdbc/anncDB");
Connection conn = ds.getConnection();
This works fine if the IP specified in the url is available. But if it is not available, it takes 3 minutes before getConnection()
returns. I need to configure this to be smaller.
I've tried setLoginTimeout()
, but that doesn't work. Doing ds.setLoginTimeout()
takes 3 minutes before failing.
Any ideas?
You said that you use XML for declaring the resource. So i suppose you have something like that :
<Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="javauser" password="javadude" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/javatest"/>
In this case, watch the maxWait attribute. In the documentation , it's specified that it's the hmaximum time to wait for a database connection to become available (10s in the example).
Hope this help
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.