Skip to Content.
Sympa Menu

freetds - Re: FreeTDS_JDBC doesn't close connections

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Eric Mountain" <e.mountain AT dev.amadeus.net>
  • To: "TDS Development Group" <freetds AT franklin.oit.unc.edu>
  • Subject: Re: FreeTDS_JDBC doesn't close connections
  • Date: Tue, 22 Jun 1999 17:58:52 +0200


OK, I've done a little more research into this (should have done that before
posting I guess, sorry - I'm guilty therefore of responding to my own post).

The first thing is, I've implemented a fix to close connections to the
server when Connection.close() is called. In fact, I close the Socket
instance variable of all unused Tds instances that are in the TdsPool after
all Statements for the connection have been closed (Statement.close() marks
corresponding Tds instance as unused.).

What I hadn't realised, was that for every Statement created using
Connection.createStatement(), you actually open a new connection to the
server (because you create a new Tds instance) (unless there are unused Tds
instances (=server connections) in the pool, in which case you get one of
those). I hadn't expected this behaviour and was wondering if it was
intended in the JDBC spec - it's great because it allows you to process
statements in parallel through a single connection object, but if you don't
know about it, it's also great at allocating loads of connections (which, as
some other threads in this list have shown, is causing a few people
problems) which is not really desirable. I'm a little bothered by the idea
of having multiple connections behind a single Connection object (maybe I
shouldn't be?). I prefer the opposite: pooling connections together for
multiple applications, like MS' ODBC driver does, i.e. minimising the number
of connections as these are costly.

The other thing is that while Connection.createStatement() opens a new
server connection every time, Statement.close() (in effect its counterpart),
does not close the connection (the Tds instance is freed and returned to the
pool for reuse). This is especially a problem in application servers where
the JVM "never dies" (well, almost).

I'm enclosing a patch which also includes an EscapeProcessor optimisation
which speeds things up considerably, my changes for accessing UniAccess on
mainframes (sorry about that, but I can't be bothered to filter them out)
and the Socket.close() changed I mentionned in paragraph 2 above.

Moral: think twice before calling createStatement() multiple times.

Cheers,
:E

-----Original Message-----
From: Eric Mountain <e.mountain AT dev.amadeus.net>
To: TDS Development Group <freetds AT franklin.oit.unc.edu>
Date: Tuesday, 22 June, 1999 09:51
Subject: [freetds] FreeTDS_JDBC doesn't close connections


>Hi,
>
>The Connection.close() method doesn't _really_ close connections to the
>server, it just flags them as closed (by setting the boolean isClosed
>instance variable to true).
>
>Does anyone have a fix for this? It is a real showstopper for me as my
>servlet based application floods the server with connections it is unable
to
>close... I've had to go back to JDBC-ODBC bridge.
>
>I'm sure it's really easy to fix if you have the relevant knowledge. (If I
>did, I'd do it! ;-) )
>
>Any help appreciated,
>:E
>
>
>---
>You are currently subscribed to freetds as: eric AT minouche.demon.co.uk
>To unsubscribe, forward this message to
$subst('Email.Unsub')
>





Archive powered by MHonArc 2.6.24.

Top of Page