Re: PGPoolingDataSource problem.
От | Radosław Smogura |
---|---|
Тема | Re: PGPoolingDataSource problem. |
Дата | |
Msg-id | f183f2afe5e7eb25e9c6b1059bbee806@mail.softperience.eu обсуждение исходный текст |
Ответ на | Re: PGPoolingDataSource problem. (Craig Ringer <craig@postnewspapers.com.au>) |
Ответы |
Re: PGPoolingDataSource problem.
|
Список | pgsql-jdbc |
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
В списке pgsql-jdbc по дате отправления: