pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Radosław Smogura <rsmogura@softperience.eu>
To: Craig Ringer <craig@postnewspapers.com.au>
Cc: Benjamin.Galaviz@LSGSkyChefs.com
Cc: pgsql-jdbc@postgresql.org
Subject: Re: PGPoolingDataSource problem.
Date: Thu, 09 Jun 2011 09:30:41 +0200
Message-ID: <f183f2afe5e7eb25e9c6b1059bbee806@mail.softperience.eu> (raw)
In-Reply-To: <4DF04704.8070604@postnewspapers.com.au>
References: <E2435754E1952542B9E77BDDC3E83942076D9EA7@sw-adclsg-mbx01.americas.lsgsc.com>
	<4DF04704.8070604@postnewspapers.com.au>

 On Thu, 09 Jun 2011 12:07:32 +0800, Craig Ringer wrote:
> On 09/06/11 01:36, Benjamin.Galaviz@LSGSkyChefs.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




view thread (8+ messages)  latest in thread

Message-ID: <f183f2afe5e7eb25e9c6b1059bbee806@mail.softperience.eu>
Permalink:  ../f183f2afe5e7eb25e9c6b1059bbee806@mail.softperience.eu/
Also on:    postgresql.org/message-id/f183f2afe5e7eb25e9c6b1059bbee806@mail.softperience.eu

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: rsmogura@softperience.eu, craig@postnewspapers.com.au, Benjamin.Galaviz@LSGSkyChefs.com
  Subject: Re: PGPoolingDataSource problem.
  In-Reply-To: <f183f2afe5e7eb25e9c6b1059bbee806@mail.softperience.eu>
  References: <E2435754E1952542B9E77BDDC3E83942076D9EA7@sw-adclsg-mbx01.americas.lsgsc.com> <4DF04704.8070604@postnewspapers.com.au> <f183f2afe5e7eb25e9c6b1059bbee806@mail.softperience.eu>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox