-
Notifications
You must be signed in to change notification settings - Fork 271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Find a better way to keep JdbcDaoFactory's PreparedStatementSource cache from leaking memory #2739
Comments
I believe in JdbcDaoFactory you can just change The Guava library is already a dependency of donkey. This will return a java.util.concurrent.ConcurrentMap with weak key references as in a java.util.WeakMap. This way, once the connection pool has discarded its reference to the connection, the JdbcDaoFactory is only holding a weak reference to it, and it will become eligible for garbage collection. The map takes care of auto-removing keys that have been garbage collected. Imported Comment. Original Details: |
JdbcDao uses CachedPreparedStatementSource objects to cache PreparedStatements to improve performance. Since a connection pool is also used, we must create a CachedPreparedStatementSource object for each connection obtained from the pool. The cache objects are mapped to connections in a Map object called statementSources in JdbcDaoFactory.
Occasionally, connections become closed and are replaced by new connections in the connection pool. When this happens, we must remove those connections from the statement cache map to prevent a memory leak.
Currently, when a new connection is put into the map, we then test all of the existing connections to see if any have been closed and then remove them.
Ideally, we would remove the connection from the map immediately once it has been closed. However we don't currently know of a way to add some sort of hook to do that.
It may be worth investigating potential ways to detect immediately when a connection is closed so the connection can then be removed from the map.
Imported Issue. Original Details:
Jira Issue Key: MIRTH-2811
Reporter: brentm
Created: 2013-07-30T10:12:05.000-0700
The text was updated successfully, but these errors were encountered: