Return-Path: Delivered-To: apmail-ibatis-user-java-archive@www.apache.org Received: (qmail 43834 invoked from network); 19 Oct 2009 20:55:18 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 19 Oct 2009 20:55:18 -0000 Received: (qmail 84739 invoked by uid 500); 19 Oct 2009 20:55:17 -0000 Delivered-To: apmail-ibatis-user-java-archive@ibatis.apache.org Received: (qmail 84711 invoked by uid 500); 19 Oct 2009 20:55:17 -0000 Mailing-List: contact user-java-help@ibatis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user-java@ibatis.apache.org Delivered-To: mailing list user-java@ibatis.apache.org Received: (qmail 84703 invoked by uid 99); 19 Oct 2009 20:55:17 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 19 Oct 2009 20:55:17 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of jeffgbutler@gmail.com designates 209.85.222.193 as permitted sender) Received: from [209.85.222.193] (HELO mail-pz0-f193.google.com) (209.85.222.193) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 19 Oct 2009 20:55:07 +0000 Received: by pzk31 with SMTP id 31so3919410pzk.28 for ; Mon, 19 Oct 2009 13:54:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=F85FYiPck2MioGJBAumARawS9RyLL3B0MoljuoCWZRM=; b=asAbXAVeF4ldWiR3OuEvwD7VGhKDczHIx5iEuLibcjTuV9pUIKkxl2IPMeDb3Sb9Vk cCWG32QOG2/7qo3r8Z11G7rMhd3n7H76yqGMLVqhv9336phfC8lxnGE7N64IzZTEuDGt lOR2B1Kh6tROpm0gOv4r7jLD/oayOYcwQQA9I= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=HQ3iLcgEVMk/MhVGFPfb0hP04bHoRiHkPFwVjYqvN1VaOROJGAT+MjWjg7rcFdECVF e4RyLPd4mRAAgOpTfvpOK+N0H+7Xrt6+TJ5irRzrUehJALoDVteOpNnxI5w2r7PbC7l7 x98T3xvc937pCa62HwBmskP4K47Nj/r8qwktI= MIME-Version: 1.0 Received: by 10.114.250.4 with SMTP id x4mr7275864wah.113.1255985685515; Mon, 19 Oct 2009 13:54:45 -0700 (PDT) In-Reply-To: <25965093.post@talk.nabble.com> References: <25943619.post@talk.nabble.com> <25962028.post@talk.nabble.com> <07094E40F055C34FA35BB28DB1670E7FB36A80@bibbmail.bibb.com> <25963938.post@talk.nabble.com> <4ADCBC63.9080000@gmail.com> <25964382.post@talk.nabble.com> <25965093.post@talk.nabble.com> Date: Mon, 19 Oct 2009 15:54:45 -0500 Message-ID: Subject: Re: iBatis - Connections to PostgreSQL Not Closing From: Jeff Butler To: user-java@ibatis.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org IIRC, Struts2 actions are not singletons. So this code is creating a new instance of the SqlMapClient (and it's associated connection pool) each time you hit the web page. They will eventually get cleaned up by the GC, but that might take a while. Better would be to implement ApplicationAware also, then write code like th= is: SqlMapClient sqlMap =3D (SqlMapClient) applicationMap.get("sqlMap"); if (sqlMap =3D=3D null) { try { sqlMap =3D SqlMapClientBuilder.buildSqlMapClient(Resources.getResourceAsReader("sqlMap= s.xml")); applicationMap.put("sqlMap", sqlMap); } catch (Exception e) { e.printStackTrace(); } } Make sure all other actions use this same code - a good use for a super class :). Then you know it's only created once. Jeff Butler On Mon, Oct 19, 2009 at 3:28 PM, Jim Borland wrote: > > Here it is. =A0Thanks for your interest in my situation. =A0Using Apache = Struts2 > - this is an action implementation. =A0The call is to "listOfArtists" in = class > "ListSwingCatAction" > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D > > public class ListSwingCatAction implements SessionAware > { > =A0 private SqlMapClient sqlMap; > =A0 private SwingCatIBatisDBHandler myDBHandler; > =A0 private Map sessionMap; > > =A0 public ListSwingCatAction() > =A0 { > =A0 =A0 =A0try > =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 sqlMap =3D > SqlMapClientBuilder.buildSqlMapClient(Resources.getResourceAsReader("sqlM= aps.xml")); > =A0 =A0 =A0} > =A0 =A0 =A0catch (Exception e) > =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 e.printStackTrace(); > =A0 =A0 =A0} > =A0 =A0 =A0myDBHandler =3D new SwingCatIBatisDBHandler(sqlMap); > =A0 } > > =A0 public String listOfArtists() > =A0 { > =A0 =A0 =A0ArrayList artists =3D myDBHandler.getArtistInfo(); > =A0 =A0 =A0sessionMap.put("artists", artists); > =A0 =A0 =A0return "success"; > =A0 } > } > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D > > > Jeff Butler-2 wrote: >> >> We should also see the Java code that creates the SqlMapClient. >> Without Spring you need to make sure that only a SINGLE instance of >> that object is created (it should be and stored either in a singleton >> or something like a web context). >> >> Jeff Butler >> >> On Mon, Oct 19, 2009 at 2:50 PM, Larry Meadors >> wrote: >>> Can you post the sqlmapconfig.xml? >>> >>> On Mon, Oct 19, 2009 at 1:44 PM, Jim Borland >>> wrote: >>>> >>>> No, I'm not smart enough to use a DAO implementation (I've read a litt= le >>>> about them). =A0Also, I keep reading about Spring -- a whole bunch of >>>> stuff on >>>> it comes up when I Google on these topics. =A0Someday I'm going to che= ck >>>> into >>>> Spring. >>>> >>>> My situation is very simple and it seems like plain old iBatis ought t= o >>>> be >>>> plenty for me in this application. =A0iBatis is supposed to take care = of >>>> all >>>> the background stuff and just let me write mapped statements. =A0I'm >>>> committed >>>> to making iBatis work without a bunch of extra stuff. =A0Thanks for yo= ur >>>> interest in my problem. >>>> >>>> >>>> Warren Bell-2 wrote: >>>>> >>>>> Are you using any DAO implementation ? Spring? Makes things much >>>>> simpler. >>>>> >>>>> Warren >>>>> >>>>> Jim Borland wrote: >>>>>> I've been fighting this issue for a long time now and am quite >>>>>> frustrated. =A0I >>>>>> originally started out with just: >>>>>> >>>>>> --> artists =3D (ArrayList) sqlMap.queryForList("getArtistInfo", lis= t ); >>>>>> -- >>>>>> but was getting all these connections. =A0So I tried adding >>>>>> start/commit/end transaction statements surrounding the query. =A0St= ill >>>>>> getting s so then I tried using : >>>>>> >>>>>> --> session =3D sqlMap.openSession(); -- and letting the session >>>>>> start/commit/end the transaction. =A0Still got s. =A0That's wh= en I >>>>>> tried >>>>>> creating, using and closing my own connection with the same sad >>>>>> result. >>>>>> >>>>>> One thing Rick Wellman said was especially interesting. =A0Every tim= e >>>>>> you >>>>>> create an instance of SqlMapClient you create an entirely new >>>>>> connection >>>>>> pool. =A0I hadn't thought about that before. =A0I guess the bottom l= ine is >>>>>> I >>>>>> don't really understand what is happening in a connection pool. >>>>>> =A0Still, >>>>>> my >>>>>> situation is so simple, yet the same bad outcome occurs no matter wh= at >>>>>> I >>>>>> try. =A0Help! >>>>>> >>>>>> >>>>>> Rick.Wellman wrote: >>>>>> >>>>>>> Since I have some time over lunch: >>>>>>> 1) I agree with Larry's reply below >>>>>>> 2) At the risk of embarrassing myself on this forum, see below for = my >>>>>>> reply to your comments and questions: >>>>>>> >>>>>>> [your-code-sample-was-here] >>>>>>> [your-comments-were-here] >>>>>>> I've been wrestling with this problem for a long time and right now >>>>>>> there are three things about which I wonder: >>>>>>> >>>>>>> (1) All the code examples I've seen show the sqlMapClient being >>>>>>> generated in the same try statement as the actual query. I'm creati= ng >>>>>>> it >>>>>>> in a separate class and passing it to another class. Could this be = a >>>>>>> problem? I'm not sure why it would matter, but that is something >>>>>>> unique >>>>>>> about my situation. >>>>>>> >>>>>>>>> Usually, your entire application would share a single instance of >>>>>>>>> >>>>>>> SqlMapClient. =A0It matters in the sense that it is un-necessary an= d >>>>>>> would, at a minimum, create an entirely new connection pool (see #3 >>>>>>> for >>>>>>> more) >>>>>>> >>>>>>> (2) In the above code I use the DataSource obtained from SqlMapClie= nt >>>>>>> -- >>>>>>> Is there something wrong with doing this? >>>>>>> >>>>>>>>> Well, probably... and it is un-necessary. =A0Use Larry's version. >>>>>>>>> (i.e. >>>>>>>>> >>>>>>> the "normal" way to use the SqlMapClient) >>>>>>> >>>>>>> (3) Have I somehow mis-configured the connection pool? >>>>>>> >>>>>>>>> I could be wrong but I still highly suspect that the connections >>>>>>>>> are >>>>>>>>> >>>>>>> a result of the connection pool and it seems to me that you're not >>>>>>> understanding the purpose of a connection pool. =A0i.e. You're tryi= ng >>>>>>> to >>>>>>> explicitly open a connection with code. =A0The connection pool will >>>>>>> usually expand and contract the number of connections to the databa= se >>>>>>> based on the load and its configuration (which is why it is called = a >>>>>>> "pool"). =A0You do not have "direct" control over which connection = your >>>>>>> iBatis SqlMapClient will use [nor do you probably want that]. =A0I >>>>>>> apologize in advance if I am way off base with this response; not m= y >>>>>>> intent to offend, but rather educate. >>>>>>> >>>>>>> To the masses... in regards to my comment #3, is there an >>>>>>> implementation >>>>>>> of a "pool" which is not a pool at all but a single connection that >>>>>>> someone can use to verify an instance like this? =A0Or maybe config= ure >>>>>>> the >>>>>>> "pool" to only have a size of one? =A0Just thinking out loud... I'v= e >>>>>>> never >>>>>>> had reason to look into something like this but it seems like this >>>>>>> question comes up every so often? (i.e. the question of connections >>>>>>> opened via iBatis) >>>>>>> >>>>>>> -----Original Message----- >>>>>>> From: Larry Meadors [mailto:larry.meadors@gmail.com] >>>>>>> Sent: Monday, October 19, 2009 12:56 PM >>>>>>> To: user-java@ibatis.apache.org >>>>>>> Subject: Re: iBatis - Connections to PostgreSQL Not Closing >>>>>>> >>>>>>> This looks to me like you are *way* overcomplicating this. :-) >>>>>>> >>>>>>> The method should be more like this: >>>>>>> >>>>>>> public List getArtistInfo(){ >>>>>>> =A0 return sqlMap.queryForList("getArtistInfo", list); >>>>>>> } >>>>>>> >>>>>>> Unless you have some really crazy wacky stuff going on, there shoul= d >>>>>>> never be a need for you to deal with connections at that level. >>>>>>> >>>>>>> Also, what's the purpose of passing in 'list' as the second paramet= er >>>>>>> there? I don't see where it would ever be non-null. >>>>>>> >>>>>>> Larry >>>>>>> >>>>>>> -------------------------------------------------------------------= -- >>>>>>> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org >>>>>>> For additional commands, e-mail: user-java-help@ibatis.apache.org >>>>>>> >>>>>>> >>>>>>> -------------------------------------------------------------------= -- >>>>>>> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org >>>>>>> For additional commands, e-mail: user-java-help@ibatis.apache.org >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> >>>>>> >>>>> >>>>> >>>>> -- >>>>> Thanks, >>>>> >>>>> Warren Bell >>>>> >>>>> >>>>> --------------------------------------------------------------------- >>>>> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org >>>>> For additional commands, e-mail: user-java-help@ibatis.apache.org >>>>> >>>>> >>>>> >>>> >>>> -- >>>> View this message in context: >>>> http://www.nabble.com/iBatis---Connections-to-PostgreSQL-Not-Closing-t= p25943619p25964382.html >>>> Sent from the iBATIS - User - Java mailing list archive at Nabble.com. >>>> >>>> >>>> --------------------------------------------------------------------- >>>> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org >>>> For additional commands, e-mail: user-java-help@ibatis.apache.org >>>> >>>> >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org >>> For additional commands, e-mail: user-java-help@ibatis.apache.org >>> >>> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org >> For additional commands, e-mail: user-java-help@ibatis.apache.org >> >> >> > > -- > View this message in context: http://www.nabble.com/iBatis---Connections-= to-PostgreSQL-Not-Closing-tp25943619p25965093.html > Sent from the iBATIS - User - Java mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org > For additional commands, e-mail: user-java-help@ibatis.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org For additional commands, e-mail: user-java-help@ibatis.apache.org