Re: PGPoolingDataSource problem.

From: Radosław Smogura <rsmogura(at)softperience(dot)eu>
To: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
Cc: <Benjamin(dot)Galaviz(at)LSGSkyChefs(dot)com>, <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: PGPoolingDataSource problem.
Date: 2011-06-09 07:30:41
Message-ID: f183f2afe5e7eb25e9c6b1059bbee806@mail.softperience.eu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On Thu, 09 Jun 2011 12:07:32 +0800, Craig Ringer wrote:
> On 09/06/11 01:36, Benjamin(dot)Galaviz(at)LSGSkyChefs(dot)com wrote:
>> I am using the JDBC3 PGPoolingDataSource to create a pool of 5
>> connections (for test) to my database.
>
> I'd recommend using a proper connection pool like C3P0 or DBCP. It'll
> be
> less work in the long run, as PGPoolingDataSource is more of a
> toy/testing tool.
>
> What's your environment, anyway? Are you running in a standalone JVM
> (j2SE) or in an application server context? If you're in an appserver
> or
> servlet container you should be getting connections from the
> container
> environment.
>
> --
> Craig Ringer

From other posts, it looks like C3P0 is only JDBC2 aware. so you will
automatic mange them.

Actually PoolingDataSource could track leak and add auto-close, I was
sure it could do this, but I'm wrong.

Backing to original post...

From design point of view your implementation in not quite good, bad
not bad.

- You use singleton pattern to manage DataSource and it's good.
- But private static Connection conn = null; should it really be
static? getConnection is not static this causes leak.
- And one tip - when I make singleton pattern I, mainly, create for
class keeping this value private default constructor, so no one who use
my code will not accidental call new Singleton, instead of
Singleton.getInstance().
- Just fix pool, and if you have time wrap your connections managed by
pool in WeakReference (eventually adding pool to this reference). This
is how pools are implemented. Everyone know to close connection but
smart developers know that many forget it, and adding leaking support
may save your time in future on writing try / catch trees.

Have a luck.

Regards,
Radek

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Craig Ringer 2011-06-09 09:39:05 Re: PGPoolingDataSource problem.
Previous Message Craig Ringer 2011-06-09 04:07:32 Re: PGPoolingDataSource problem.