I'm going to be a "small government" candidate. I'll be the government. Just me. No one else.
Stephan van Hulst wrote:You should use a PooledConnectionFactory, and you should close your connections using try-with-resources, not with try-finally. You're also not using Spring's dependency injection mechanism properly.
Now the trick is to configure Spring that it creates a PooledConnectionFactory for your application once. You should be able to do it like this:
I'm going to be a "small government" candidate. I'll be the government. Just me. No one else.
Tim Holloway wrote:As a general rule, a Factory is a service class that's designed to dispense resources efficiently. If the resources are poolable, then often the factory will maintain its own internal pool. For example the DataSource factory that's built into every J(2)EE-compliant web application server.
And I won't even begin to consider what could happen if you have a single instance of something and multiple thread users without any synchronization.
Dave Tolls wrote:Doesn't have to be multiple users, as in people, just multiple threads.
If more than one thread at a time accesses this code then something will eventually break.
All it would take is for one thread to close the connection before another thread tries to use either it or the Session value from lines 70-78.
I'm going to be a "small government" candidate. I'll be the government. Just me. No one else.
Tim Holloway wrote:
Dave Tolls wrote:Doesn't have to be multiple users, as in people, just multiple threads.
If more than one thread at a time accesses this code then something will eventually break.
All it would take is for one thread to close the connection before another thread tries to use either it or the Session value from lines 70-78.
Or for two threads to try to use the connection at once and thus corrupt the connection's internal state.
I'm going to be a "small government" candidate. I'll be the government. Just me. No one else.
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |