Received: from net2.micro-automation.com (net2.micro-automation.com [64.7.141.29]) by postgresql.org (8.11.3/8.11.1) with SMTP id f5MJBaa44361 for ; Fri, 22 Jun 2001 15:11:36 -0400 (EDT) (envelope-from Dave@micro-automation.net) Received: (qmail 18300 invoked from network); 22 Jun 2001 19:11:31 -0000 Received: from eboxwest.ebox.com (HELO INSPIRON) (206.51.23.194) by net2.micro-automation.com with SMTP; 22 Jun 2001 19:11:31 -0000 Reply-To: From: "Dave Cramer" To: "=?iso-8859-1?Q?'Gunnar_R=F8nning'?=" , "'Rainer Mager'" Cc: "'Bruce Momjian'" , "'PostgreSQL jdbc list'" Subject: RE: Re: [ADMIN] High memory usage [PATCH] Date: Fri, 22 Jun 2001 15:09:40 -0400 Organization: Micro Automation Inc. Message-ID: <000801c0fb4e$e32f4280$0201a8c0@INSPIRON> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0009_01C0FB2D.5C1DA280" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.2616 In-reply-to: X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 Importance: Normal X-AntiVirus: scanned for viruses by AMaViS 0.2.1 (http://amavis.org/) X-Archive-Number: 200106/78 X-Sequence-Number: 819 This is a multi-part message in MIME format. ------=_NextPart_000_0009_01C0FB2D.5C1DA280 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable 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=F8nning 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" 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=20 reference, 2 ed." from Addison Wesley ? This book contains a section for JDBC driver writers and explains this issue. regards,=20 Gunnar --=20 Gunnar R=F8nning - 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 ------=_NextPart_000_0009_01C0FB2D.5C1DA280 Content-Type: application/octet-stream; name="PreparedStatement.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="PreparedStatement.diff" *** PreparedStatement.java Fri Jun 22 14:52:45 2001 --- PreparedStatement.new Fri Jun 22 14:51:29 2001 *************** *** 41,48 **** =20=20 // 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 =3D new ThreadLocal(); // setDate() S= impleDateFormat ! private ThreadLocal tl_tsdf =3D new ThreadLocal(); // setTimestam= p() SimpleDateFormat =20=20 /** * Constructor for the PreparedStatement class. --- 41,48 ---- =20=20 // 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 =3D new ThreadLocal(); // setD= ate() SimpleDateFormat ! private static ThreadLocal tl_tsdf =3D new ThreadLocal(); // setT= imestamp() SimpleDateFormat =20=20 /** * Constructor for the PreparedStatement class. *************** *** 64,69 **** --- 64,78 ---- =20=20 this.sql =3D sql; this.connection =3D connection; +=20=09 + // might just as well create it here, so we don't take the hit later +=20 + SimpleDateFormat df =3D new SimpleDateFormat("''yyyy-MM-dd''= "); + tl_df.set(df); +=20=09=09 + df =3D new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + tl_tsdf.set(df); +=20=20=20=20=20=20=20=20=20=20=20 for (i =3D 0; i < sql.length(); ++i) { int c =3D sql.charAt(i); *************** *** 89,98 **** /** * New in 7.1 - overides Statement.close() to dispose of a few lo= cal objects */ ! public void close() throws SQLException { // free the ThreadLocal caches tl_df.set(null); !=20 super.close(); } =20=20 --- 98,108 ---- /** * New in 7.1 - overides Statement.close() to dispose of a few lo= cal objects */ ! public void close() throws SQLException ! { // free the ThreadLocal caches tl_df.set(null); ! tl_tsdf.set(null); super.close(); } =20=20 *************** *** 333,342 **** public void setDate(int parameterIndex, java.sql.Date x) throws SQLExcep= tion { SimpleDateFormat df =3D (SimpleDateFormat) tl_df.get(); - if(df=3D=3Dnull) { - df =3D new SimpleDateFormat("''yyyy-MM-dd''"); - tl_df.set(df); - } =20=20 set(parameterIndex, df.format(x)); =20=20 --- 343,348 ---- *************** *** 376,385 **** public void setTimestamp(int parameterIndex, Timestamp x) throws SQLExce= ption { SimpleDateFormat df =3D (SimpleDateFormat) tl_tsdf.get(); - if(df=3D=3Dnull) { - df =3D new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - tl_tsdf.set(df); - } df.setTimeZone(TimeZone.getTimeZone("GMT")); =20=20 // Use the shared StringBuffer --- 382,387 ---- ------=_NextPart_000_0009_01C0FB2D.5C1DA280--