Some people, when well-known sources tell them that fire will burn them, don't put their hands in the fire.
Some people, being skeptical, will put their hands in the fire, get burned, and learn not to put their hands in the fire.
And some people, believing that they know better than well-known sources, will claim it's a lie, put their hands in the fire, and continue to scream it's a lie even as their hands burn down to charred stumps.
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:
Some people, when well-known sources tell them that fire will burn them, don't put their hands in the fire.
Some people, being skeptical, will put their hands in the fire, get burned, and learn not to put their hands in the fire.
And some people, believing that they know better than well-known sources, will claim it's a lie, put their hands in the fire, and continue to scream it's a lie even as their hands burn down to charred stumps.
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.
Some people, when well-known sources tell them that fire will burn them, don't put their hands in the fire.
Some people, being skeptical, will put their hands in the fire, get burned, and learn not to put their hands in the fire.
And some people, believing that they know better than well-known sources, will claim it's a lie, put their hands in the fire, and continue to scream it's a lie even as their hands burn down to charred stumps.
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.
Some people, when well-known sources tell them that fire will burn them, don't put their hands in the fire.
Some people, being skeptical, will put their hands in the fire, get burned, and learn not to put their hands in the fire.
And some people, believing that they know better than well-known sources, will claim it's a lie, put their hands in the fire, and continue to scream it's a lie even as their hands burn down to charred stumps.
Hey! You're stepping on my hand! Help me tiny ad!
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
|