pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dave Cramer <Dave@micro-automation.net>
To: 'Gunnar Rønning' <gunnar@polygnosis.com>
To: 'Rainer Mager' <rmager@vgkk.com>
Cc: 'Bruce Momjian' <pgman@candle.pha.pa.us>
Cc: 'PostgreSQL jdbc list' <pgsql-jdbc@postgresql.org>
Subject: RE: Re: [ADMIN] High memory usage [PATCH]
Date: Fri, 22 Jun 2001 15:09:40 -0400
Message-ID: <000801c0fb4e$e32f4280$0201a8c0@INSPIRON> (raw)
In-Reply-To: <m27ky4pppw.fsf@smaug.polygnosis.com>

Here is a patch which inspired by Michael Stephens that should work

Dave


-----Original Message-----
From: pgsql-jdbc-owner@postgresql.org
[mailto:pgsql-jdbc-owner@postgresql.org] On Behalf Of Gunnar Rønning
Sent: June 22, 2001 10:14 AM
To: Rainer Mager
Cc: Dave Cramer; Bruce Momjian; PostgreSQL jdbc list
Subject: Re: [JDBC] Re: [ADMIN] High memory usage [PATCH]

* "Rainer Mager" <rmager@vgkk.com> wrote:
|

| Interesting. I wasn't aware of this. If question #2 is answered such
that
| thread safe isn't necessary, then this problem goes away pretty
easily. If
| thread safety is needed then this would have to be rewritten, I can
look
| into doing this if you like.

Thread safety is required by the spec. Do you have "JDBC API tutorial
and 
reference, 2 ed." from Addison Wesley ? This book contains a section for

JDBC driver writers and explains this issue.

regards, 

        Gunnar

-- 
Gunnar Rønning - gunnar@polygnosis.com
Senior Consultant, Polygnosis AS, http://www.polygnosis.com/

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Attachments:

PreparedStatement.diff (application/octet-stream, 2.8K) download *** PreparedStatement.java Fri Jun 22 14:52:45 2001 --- PreparedStatement.new Fri Jun 22 14:51:29 2001 *************** *** 41,48 **** // We use ThreadLocal for SimpleDateFormat's because they are not that // thread safe, so each calling thread has its own object. ! private ThreadLocal tl_df = new ThreadLocal(); // setDate() SimpleDateFormat ! private ThreadLocal tl_tsdf = new ThreadLocal(); // setTimestamp() SimpleDateFormat /** * Constructor for the PreparedStatement class. --- 41,48 ---- // We use ThreadLocal for SimpleDateFormat's because they are not that // thread safe, so each calling thread has its own object. ! private static ThreadLocal tl_df = new ThreadLocal(); // setDate() SimpleDateFormat ! private static ThreadLocal tl_tsdf = new ThreadLocal(); // setTimestamp() SimpleDateFormat /** * Constructor for the PreparedStatement class. *************** *** 64,69 **** --- 64,78 ---- this.sql = sql; this.connection = connection; + + // might just as well create it here, so we don't take the hit later + + SimpleDateFormat df = new SimpleDateFormat("''yyyy-MM-dd''"); + tl_df.set(df); + + df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + tl_tsdf.set(df); + for (i = 0; i < sql.length(); ++i) { int c = sql.charAt(i); *************** *** 89,98 **** /** * New in 7.1 - overides Statement.close() to dispose of a few local objects */ ! public void close() throws SQLException { // free the ThreadLocal caches tl_df.set(null); ! super.close(); } --- 98,108 ---- /** * New in 7.1 - overides Statement.close() to dispose of a few local objects */ ! public void close() throws SQLException ! { // free the ThreadLocal caches tl_df.set(null); ! tl_tsdf.set(null); super.close(); } *************** *** 333,342 **** public void setDate(int parameterIndex, java.sql.Date x) throws SQLException { SimpleDateFormat df = (SimpleDateFormat) tl_df.get(); - if(df==null) { - df = new SimpleDateFormat("''yyyy-MM-dd''"); - tl_df.set(df); - } set(parameterIndex, df.format(x)); --- 343,348 ---- *************** *** 376,385 **** public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException { SimpleDateFormat df = (SimpleDateFormat) tl_tsdf.get(); - if(df==null) { - df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - tl_tsdf.set(df); - } df.setTimeZone(TimeZone.getTimeZone("GMT")); // Use the shared StringBuffer --- 382,387 ----

view thread (46+ messages)  latest in thread

Message-ID: <000801c0fb4e$e32f4280$0201a8c0@INSPIRON>
Permalink:  ../000801c0fb4e$e32f4280$0201a8c0@INSPIRON/
Also on:    postgresql.org/message-id/000801c0fb4e$e32f4280$0201a8c0@INSPIRON

 ·  · 

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-admin@postgresql.org
  Cc: Dave@micro-automation.net, gunnar@polygnosis.com, rmager@vgkk.com, pgman@candle.pha.pa.us, pgsql-jdbc@postgresql.org
  Subject: Re: [ADMIN] High memory usage [PATCH]
  In-Reply-To: <000801c0fb4e$e32f4280$0201a8c0@INSPIRON>
  References: <m27ky4pppw.fsf@smaug.polygnosis.com> <000801c0fb4e$e32f4280$0201a8c0@INSPIRON>

* 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