Issue Details (XML | Word | Printable)

Key: DBCP-218
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Bill Liu
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Commons Dbcp

basicDataSource.setLoginTimeout(n) not work?

Created: 10/May/07 11:24 PM   Updated: 27/Aug/07 03:32 PM
Return to search
Component/s: None
Affects Version/s: 1.1, 1.2, 1.2.1, 1.2.2
Fix Version/s: 1.3

Time Tracking:
Not Specified

Environment: Windows
Issue Links:
Reference
 

Resolution Date: 12/Jun/07 06:25 PM


 Description  « Hide
Hi:

We tried to set the login timeout value of the basic data source but got the exception. Is this feature (Login timeout is not supported.)? We want the connection pool not to wait forever if the database is too busy. Any ideas? Thanks.

In the code:
BasicDataSource bds = new BasicDataSource();
bds.setDriverClassName("oracle.jdbc.driver.OracleDriver");
bds.setUsername("my username");
bds.setPassword("my password");
bds.setUrl("jdbc:oracle:thin:@mrhost:1521:test");
bds.setMaxActive(2);
bds.setLoginTimeout(5);

Result:
Exception in thread "main" java.lang.UnsupportedOperationException: Login timeout is not supported.



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Phil Steitz added a comment - 11/May/07 02:33 AM
Unfortunately, the PoolingDataSource that BasicDataSource wraps does not support the loginTimeout parameter. The BasicDataSource javadoc should be fixed to indicate that.

Marking as 1.3 fix version. Javadoc (or enhancement) patches welcome.

If what you want is for the datasource to timeout rather than waiting indefinitely on a connection when all connections in the pool are busy, you can set the maxWait property, which is a pool property that controls how long the pool will wait for a an object to become available to return to the client. If what you really want is for the driver to timeout when the pool uses it to open a physical connection, you could try setting the loginTimeout in the connection URL provided to setUrl. It looks like the Oracle driver supports that, though I have not tried this.


Bill Liu added a comment - 11/May/07 04:53 PM
Thanks Phil.

We actually wanted the first scenario: the datasource to time out if there are no connections available from the pool and the max active has been reached. I did not know the default value of maxWait was -1 and did not check it. Yes I set it to be 5 seconds and it worked.


Henri Yandell added a comment - 12/Jun/07 06:25 PM
svn ci -m "Adding the Javadoc to state that getLoginTimeout and setLoginTimeout are NOT supported by BasicDataSource as per DBCP-218" src/java/org/apache/commons/dbcp/BasicDataSource.java

Sending src/java/org/apache/commons/dbcp/BasicDataSource.java
Transmitting file data .
Committed revision 546583.