Tomcat jdbc-pool acquireRetryDelay - tomcat7

C3p0 cache has acquireRetryDelay parameter to set time between acquire attempts.
Has tomcat7 jdbc-pool the same functionality?

No, tomcat jdbc pool does not automatically try to connect again, when the attempt to create a connection fails. It simply will throw the exception it got as an SQLException (if it was not one in the first place).
If it's you code which needs to do retry you can do it yourself, by trying to get connection several times. Or you might be able to make a patch, it does not seem to be so hard to do.
You can try to use some different libraries, they say BoneCP is quite good (although I never tried that).

Related

BoneCP vs WebLogic's own DB connection pool

I have a servlet which connects to Oracle DB using JDBC (ojdbc6.jar) and BoneCP. I now need to port my BoneCP-using code to something which will work in WebLogic out-of-the-box, without having BoneCP in the package.
What would be the recommended approach? What WebLogic feature I can use, specifically to get an equivalent of BoneCP's:
Performance
Ability to log failed SQL statements
Auto-resume from lost DB connection
Thanks in advance.
The best approach would be to create a standard Oracle JDBC connection pool pointing to your database. Tune it according to your necessities (number of connections, etc.). Next you would need to refactor out of your code any explicit reference to your former connection pool implementation. If you have been working with java.sql.* interfaces in your code, there should be few to no references at all.
Once all that is refactorized, you will have only a bit of code (or config file) telling your app to recover something implementing javax.sql.DataSource from a given JNDI name and getting Connections out of it. The rest should be the same - just do whatever you need and close your ResultSets, Statements and Connections as you must have been doing until now.
About your questions, you will find extensive information on how to monitor your connection pool, and its fail recovery policies, here (depending on your app server version, I paste here the one I have used):
http://docs.oracle.com/cd/E15051_01/wls/docs103/jdbc_admin/jdbc_datasources.html
About performance, I have no accurate data nor benchmarks comparing both implementations; for your tranquility, I would say you that I have never found a database performance problem in the connection pool implementation - this does not mean that it cannot exist, but it is the last place I would look for it ;)

Connection get/return listener?

Using Hibernate and Spring, my app needs to get the opportunity to manipulate the connection at the start and end of every database update. Our first guess was to override the transaction manager, but that is seeming to have some side effects from an intermittent "Pre-bound JDBC Connection found!" error to a few other harder to describe symptoms.
What is the best/easiest way to get this oppostunity. I saw someone suggest overriding the data source and then wrapping the connection, but is that really the best idea? Wrapping the connection seems dangerous, espceially since Websphere has it's own version (WSconnection).
Ideas?
Manipulation of the connection is done the easiest when a DataSource.getConnection is done, that way you know for certain that something is going to happen. So you could simply create a DataSourceProxy/-Wrapper (give it a name) which does this. There is one thing you have to take care of and that is, probably on close of the connection, that you undo the manipulation (if that is needed that is).
Instead of creating a proxy you could use some AOP to execute the code (like in this answer.

com.ibm.websphere.ce.cm.ConnectionWaitTimeoutException: Connection not available from a DBA

I am an Oracle DBA and not a java developer or websphere expert. We recently started using websphere in our environment. So the developers are still learning it. So I may not word my question properly. I did search the forums and saw 2 other questions like this. My question is more about how to trouble shoot this.
Websphere 8.5.0.2
Oracle 11.2.0.3
I see 20 open connections in the database. All are inactive. So they are not processing. From oracle it is v$session. Inactive means, you are open and not doing anything. Basically it is idle.
If they are inactive and not processing, they should be available for the connection pool to give to a new requester, assuming the DAO the java developer is using is being closed when done (this includes try/catch block). We confirmed that he is closing his connections.
Checks so far:
1. We reviewed the developers code. He is using standard java DAOs. He is closing his connection. He has a try/catch block and the first thing he does in the catch is close the connection.
2. My assumption is that this should cover the code path.
We don't see any errors raised in a log about 'closing' a connection.
My understanding of how a connection pool works
1. Pool Manager opens a configurable set of connections to the database. In our case it is 20.
2. When an application requests a connection, the connection manager does a lookup of the pool for the next available connection, then passes a pointer to that connect to the requesting function.
Possibility:
1. really slow server. We are using VMs for development/test. We do not have visibility to the servers to see if they are busy. So another VM could be using up CPU or disk.
Though lookups for available connections are light weight, it is possible that the server is hung up at 100% cpu and we timeout. Problem is, I don't have a way to look at this. No privileges and no access to someone who does.
not closing connections: We checked pretty thoroughly. We don't see any code passes (including exceptions) where he is not closing connections. First thing he does in a catch, is close the connection.
Any suggestions on where to look? I think its an issue with a slow server, but I want to rule other stuff out. I would like to state again that I am not a java developer or a websphere expert. So my question may be worded poorly.
the first thing he does in the catch is close the connection
Get the developer to introduce finally block after catch block and close connection in finally block, instead of catch block. Flow will move to catch only in case of error, but on normal flow the connection will not be released soon.
try {
//do something
}
catch(Exception ex) {
// log error
}
finally {
//close connection here
}
The symptoms you've described indicate a connection leak. Leaks are easy to solve (see ad-inf's response), but it can be hard to locate the source of the leak. Luckily, WAS comes with ConnLeakLogic mechanism. After enabling it, in the trace.log you'll find entries related to connections which have been retrieved from pool by application and haven't been returned for longer period of time. That connection information will also print a stack trace of a Java thread from the time of obtaining the connection. Seeing that stack traces, Java developer should be able to identify offending code.

DBCP connection validation problem

I decided to use DBCP mainly because I was getting timeouts on my database connections. In theory, once you define a "validation query", DBCP will by default run that query on the connection before using it, so you always know the connection is OK.
I set it up two weeks ago and it seemed to work. However, last night I got a timeout exception on a connection.
On my dev machine the code survives a MySQL restart without a problem, so I guess DBCP is doing something.
How should I proceed investigating this? Do you use DBCP for this purpose?
(Just deleted 50 lines or so of more detail, trying to keep the question readable. Let me know if some crucial info is missing).
EDIT: Guess I should have read this question before I started...
This is not always true. I experienced similar problems, but it turned out to be that DBCP has a default behavior that is not very well documented.
You must set the time between eviction runs to purge idle connections. This can be set on a SharedPoolDataSource object by calling setTimeBetweenEvictionRunsMillis. If this is never set, the default value is negative, and the thread never runs!

Flushing JDBC connection pools

Does anyone know the best (or any) way to flush a JDBC connection pool? I can't find anything obvious in the documentation. It appears connection pools aren't meant to ever be deleted.
My current thought is to delete all DataSources from the hash we store them in, which will trigger our code to make new ones. However, my first attempt throws a ConcurrentModificationException.
You shouldn't be writing a connection pool. Even if you want to manage the pool yourself (as opposed to letting a container do it), you should use a library for that (such as Commons DBCP).
If you want to delete everything from a hash, you should use hash.clear().
If you want to avoid ConcurrentModificationException, you need to add synchronization.
If you delete references to Connections (are you sure you meant DataSources?), be sure to close() them first.
Why do you want to delete, rather don't create it at first place.
It should be based on your appserver, may be some JNDI programming could do the trick.
You shouldn't be writing a connection pool. That's handled by the Java EE app server.

Resources