-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 Yuval,
On 9/19/16 2:55 AM, Yuval Schwartz wrote: > Hello Chris, > > On Sat, Sep 17, 2016 at 7:40 PM, Christopher Schultz < > ch...@christopherschultz.net> wrote: > > Yuval, > > On 9/16/16 2:33 PM, Yuval Schwartz wrote: >>>> Hey Chris, >>>> >>>> You have a line in your link that reads: >>>> >>>> // if you want to issue multiple queries and/or // work with >>>> multiple result sets, either declare more Statement // and >>>> ResultSet locals above and duplicate all cleanup logic for >>>> them, // or make sure you close each object along the way >>>> before you // try to re-use the reference >>>> >>>> I have the following code in one of my data accessing >>>> methods: >>>> >>>> [same ps and rs instantiating as you] >>>> >>>> try { ps = connection.prepareStatement(query1); rs = >>>> ps.executeQuery(); >>>> >>>> ...[process rs. (I dont close the ps or the rs at this >>>> point)] >>>> >>>> ps = connection.prepareStatement(query2); rs = >>>> ps.executeQuery(); .... } >>>> >>>> [catch and finally blocks as you specify] >>>> >>>> As you can see I simply reuse the ps and rs variables, >>>> without closing them beforehand. Is this a problem? > > That depends upon your database driver. I seem to recall Oracle > specifically being very unforgiving when it comes to failing to > close resources. I would add explicit "close" calls to every object > you are expecting to be finished with. > >>>> The reason this never raised a flag before is because I have >>>> another database accessing method that executes two queries >>>> in the same fashion and it never caused any issues. > > Are there any other factors involved? Maybe that other accessing > method doesn't get called very often? Is it in a separate process > where cleanup happens when the process completes? Do you have some > other kind of pooling mechanism that will auto-close resources? > > I think it's always a good idea to follow the API's > recommendations about closing resources when you are done with > them. In the worst case, the close() method is a no-op and it will > eventually be JIT'd away. In the best case, you get clean resource > management. > > >> Thanks, I found information about this in forums and made the >> change. I'll also look for it in formal documentation when I have >> some more time. Thanks for your help, this was most likely the >> issue. The best advice I can give you is to run your connection pool with exactly 1 connection in the pool in development. You'll find all kinds of problems with your app very quickly if it hasn't been written with careful attention to resource-management. - -chris -----BEGIN PGP SIGNATURE----- Comment: GPGTools - http://gpgtools.org Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQIcBAEBCAAGBQJX4EfvAAoJEBzwKT+lPKRYygIQAIt6kVOIUuJ0f9/e5mUyRFCG G0ZczqsZ5BC68ebL6pB/LzxcDdxKVii6mnBjG0MuAXsiy8tnJXl8nlP6WFfmf8+L 0wIws3sSjLzW/VXlLnHsW0d4SUC88qgZh/MkeZvO63uL+hyw6TG3sbClaS1kUh0O HI1KIIoCOQbr/pcS6Uu4xQ+bUuiWMAOpq+nVSFSUU04nRmcyAtemDm539RRq1GBY pyfgE9P3IZix5ZvjAN/r0WVV2Mwmuk45YDKSoSjeOyB3SJTWHxIj3z0aod0NJQCW XU+OVdozpAXjyH8s7ydlDYSHFtsXsOIy66xei0DEV6zKqvsBQUBha00ew6cYjYqx 2dMUoKY6wNwR02AbwzmVP5Yvzlpv8q/VKMBwAoTHYYpRRdJVIlPPDVll0ldW0wKO n/PbpcWtZLDeOFDHh3I1mR1eRg0h8iQKfDNeeIIRxV8tFU1V3xG+B2CiWp1kGRy7 Gnkup9kCu8RnnPBpvhDW/Z7EPt78qgUrhL2gnFVqUvRAWXkPmnwPUrHs4kOdPtg7 ZkyWOZlu7cGXA6kV8hqY9OkmDUYjVrNAbLcWc917twVUe7NM4KnY3LOmclPbV0Uq dxxaSgPjgVlB23dmCp43OyJkbXwlZR5QmtI2JvSeNBZNINZTs7OgbjSYZ8UqCXTG TnRKvI5crM9XNp8B5yTh =Ueel -----END PGP SIGNATURE----- --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org