Return-Path: Delivered-To: apmail-activemq-users-archive@www.apache.org Received: (qmail 49969 invoked from network); 24 Mar 2010 10:08:47 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 24 Mar 2010 10:08:47 -0000 Received: (qmail 43919 invoked by uid 500); 24 Mar 2010 10:08:47 -0000 Delivered-To: apmail-activemq-users-archive@activemq.apache.org Received: (qmail 43668 invoked by uid 500); 24 Mar 2010 10:08:47 -0000 Mailing-List: contact users-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@activemq.apache.org Delivered-To: mailing list users@activemq.apache.org Received: (qmail 43660 invoked by uid 99); 24 Mar 2010 10:08:46 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 24 Mar 2010 10:08:46 +0000 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=AWL,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of gary.tully@gmail.com designates 209.85.220.228 as permitted sender) Received: from [209.85.220.228] (HELO mail-fx0-f228.google.com) (209.85.220.228) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 24 Mar 2010 10:08:40 +0000 Received: by fxm28 with SMTP id 28so1579573fxm.16 for ; Wed, 24 Mar 2010 03:08:19 -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; bh=x3/JBtea0aE3H42Nr7GSBalyTietGGcs80PhMzOwpXE=; b=fzpt4KdSO8CrGmZopql9ctp8AJgPmTv1T4RfeWWsQcb6K80GXDpf9azPbm5dzZldyl 9dBMUfJ3xWztMMO/F+uv5S8fERrpvdqzsQMdGvm9Kb2RYPBa3RJ8xy+ndiLi/f4J7hi3 af1b8JuU2LzIuYPSlj4LqI1rYpDbeJ8pD19DI= 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; b=Ak2BJ9g2kAVzH/SGsh0X6JTq3m2rfUh7JZXUwt4sCp53qzcYAvtB09VUdmmIs06AfK OMb6GEgqPxY1ZrryutvV1FI46aL3b1LtZFhJ60I4+AdDOEL6v9w5oFT/emUYsGoNGa36 CGwIK0iU0Be2+vhYEz66/5Hl44f4g38t9zeqc= MIME-Version: 1.0 Received: by 10.223.73.82 with SMTP id p18mr738471faj.34.1269425298993; Wed, 24 Mar 2010 03:08:18 -0700 (PDT) In-Reply-To: <969231.54233.qm@web39607.mail.mud.yahoo.com> References: <969231.54233.qm@web39607.mail.mud.yahoo.com> Date: Wed, 24 Mar 2010 10:08:18 +0000 Message-ID: <3a73c17c1003240308p31b6173nc933255b3b5ca399@mail.gmail.com> Subject: Re: OutOfMemoryException in consumer From: Gary Tully To: users@activemq.apache.org Content-Type: multipart/alternative; boundary=0015174c0f3e03f30d0482891cd6 --0015174c0f3e03f30d0482891cd6 Content-Type: text/plain; charset=ISO-8859-1 try reducing the prefetch, you may be getting up to 1000 messages accumulated on your consumer: http://activemq.apache.org/what-is-the-prefetch-limit-for.html Also have a read of: http://activemq.apache.org/javalangoutofmemory.html On 24 March 2010 09:37, Milan Tomic wrote: > Is this consumer code OK? Sometimes I got OutOfMemoryException and I can't > find what resources I am not releasing... > > while (true) { > try { > Connection conn = oraPC.getConnection(); > Statement stmt = null; > try { > while ((message = mq_consumer.receive(10)) != null) { > if (message instanceof ObjectMessage) { > if (stmt == null) > stmt = conn.createStatement(); > ObjectMessage msg = (ObjectMessage)message; > String insert = getInsert(msg); > stmt.addBatch(insert); > sql += "\r\n"+insert; > } > } > if (stmt != null) { > stmt.executeBatch(); > conn.commit(); > mq_session.commit(); > } > } > } finally { > if (stmt != null) > try { > stmt.close(); > stmt = null; > } catch (SQLException e) {} > if (conn != null) > try { > conn.close(); > conn = null; > } catch (SQLException e) {} > } > } catch (Exception e) { > e.printStackTrace(); > try { mq_session.rollback(); } catch (JMSException e1) { > e1.printStackTrace(); } > } > // Sleep here... > } > > And this is how I init MQ session: > > mq_session = mq_connection.createSession(true, Session.AUTO_ACKNOWLEDGE); > > > > > -- http://blog.garytully.com Open Source Integration http://fusesource.com --0015174c0f3e03f30d0482891cd6--