Subject RE: [Firebird-Java] Re: Should (Could) FBStatements be held in WeakHashMap
Author Robert DiFalco
I just wanted to state my concern for adding memory and processor
overhead to benefit those whose code is in error. After all, closing a
statement is a requirement, not just "a good thing to do". I'm not crazy
about having to pay with the maintenance of Weak References, Reference
Queues, and casts for those whose code is in error.

If this is an issue (and I'm not sure why it should be), I would prefer
to have a DEBUG mode that tracks statements and their resource
consumption. By turning this flag on I could tell that I'm am not
properly closing resources without imposing a hit on those who are using
resources properly.

JMTC,

R.

-----Original Message-----
From: Mark O'Donohue [mailto:mark.odonohue@...]
Sent: Saturday, June 14, 2003 8:05 AM
To: Firebird-Java@yahoogroups.com
Subject: Re: [Firebird-Java] Re: Should (Could) FBStatements be held in
WeakHashMap



Hi Roman (and others)

Ok, I (finally) got time to implement a weak hash map of stmts in
Connection and it seems to works fine.

I used Branch_1_0 and have attached a code patch, the change turned out
to be quite simple. and it runs though the test suite, (and I've even
added an extra test for this case as well - not in the patch).


Recapping, briefly, the problem was if one forgot the close() on a
statement (and had long lasting Connections) then db resources were
consumed over time, compounding the problem was that it was difficult to

debug the cause, the program seems to work, but after a period of
operating it gets slower and eventually fails - also code written for
(some) other jdbc drivers do this cleanup, so using code from other
systems can give unexpected errors.


The weak references allows our driver work even if the user forgets the
close, in the following simulation of the forgotten close().

for (int i = 0; i < 40000; i++) {
Statement stmt = con.createStatement();
}

With weak references, even in this tight loop, the internal stmt count
was kept down to 4000 max.


But to still give the user an idea that he's perhaps consuming
resources, Im writing the following message to
DriverManager.getLogStream()


This Connection usage of Statement resources has just exceeded [ 500 ]
active connections
If this is unexpected then it is probably an indication of a missing
close() call in ResultSet or Statement objects

This msg is written as the size of activeStatements set in Connection
exceeds, 500, 1000, 2000, 4000, 8000, 16000, 32000, 64000 ..etc.


Roman, when (and how) is a good time to add this to the main branch, I
assume you want to fix the upgrade of the transaction stuff first.


Cheers

Mark

Yahoo! Groups Sponsor





To unsubscribe from this group, send an email to:
Firebird-Java-unsubscribe@yahoogroups.com



Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.