Received: from postgresql.org.org (webmail.postgresql.org [216.126.85.28]) by postgresql.org (8.11.3/8.11.1) with SMTP id f5MCgVa50784 for ; Fri, 22 Jun 2001 08:42:31 -0400 (EDT) (envelope-from pgsql-jdbc-owner@postgresql.org) Received: from www.vgkk.com ([64.56.164.18]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f5M4vla22213 for ; Fri, 22 Jun 2001 00:57:47 -0400 (EDT) (envelope-from rmager@vgkk.com) Received: from [61.202.206.130] (helo=rmagervm) by www.vgkk.com with smtp (Exim 3.22 #7) id 15DJ0g-0001zJ-00; Fri, 22 Jun 2001 13:57:34 +0900 From: "Rainer Mager" To: "Dave Cramer" , "Bruce Momjian" Cc: "PostgreSQL jdbc list" Subject: RE: Re: [ADMIN] High memory usage [PATCH] Date: Fri, 22 Jun 2001 13:56:17 +0900 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 In-Reply-To: <018601c0fab3$082dc080$0201a8c0@INSPIRON> Importance: Normal X-Archive-Number: 200106/72 X-Sequence-Number: 813 Good questions, I'll answer what I can... > 1) what is the problem that this is trying to solve, I assume from the > subject that it is some sort of high memory usage? Yes it involves memory usage and a memory leak. Basically, the way the code was before the patch, each instantiation of a PreparedStatement created 2 new ThreadLocal objects. According to Sun's Javadocs, these objects are not freed until the thread is completed. For a single thread app or main thread of an application (in our case a server) the thread NEVER goes away. Therefore these ThreadLocal objects just keep adding up and using memory, forever. The patch removes the use of these ThreadLocals. > 2) I am trying to understand how a statement would ever be used > by more than > one thread at a time? I would think that it would be impossible to share > statements across threads. This I can't really answer. The code appeared to be written to be thread safe so I attempted to continue that. Whether thread safe for a Statement is necessary or not I can't directly say. Although, I agree with you, I can't imagine a need to use a single Statement in multiple threads. > 3) The double locking method used is alledgedly unsafe on SMP machines > http://www.javaworld.com/javaworld/jw-02-2001/jw-0209-double_p.html. 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. > Dave --Rainer