Hash: SHA256


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
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/


To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to