You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Milan Tomic <to...@yahoo.com> on 2010/03/24 10:37:46 UTC

OutOfMemoryException in consumer

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);



      

Re: OutOfMemoryException in consumer

Posted by Rob Davies <ra...@gmail.com>.
What happens if you run that code without the database piece ? Also - have you reduced your prefetch to 100 ?  Are you receiving messages that aren't ObjectMessage types ?

On 25 Mar 2010, at 00:24, Milan Tomic wrote:

> 
> Memory consumed is growing slowly with a time... over 100 MB in one day and it never comes back... there must be something wrong with my code below? do I need message.acknowledge() or something?
> 
> TIA,
> Milan
> 
> 
> 
> 
> ----- Original Message ----
> From: Gary Tully <ga...@gmail.com>
> To: users@activemq.apache.org
> Sent: Wed, March 24, 2010 11:08:18 AM
> Subject: Re: OutOfMemoryException in consumer
> 
> 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 <to...@yahoo.com> 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
> 
> 
> 
> 


Re: OutOfMemoryException in consumer

Posted by Milan Tomic <to...@yahoo.com>.
Memory consumed is growing slowly with a time... over 100 MB in one day and it never comes back... there must be something wrong with my code below? do I need message.acknowledge() or something?

TIA,
Milan




----- Original Message ----
From: Gary Tully <ga...@gmail.com>
To: users@activemq.apache.org
Sent: Wed, March 24, 2010 11:08:18 AM
Subject: Re: OutOfMemoryException in consumer

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 <to...@yahoo.com> 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



      

Re: OutOfMemoryException in consumer

Posted by Gary Tully <ga...@gmail.com>.
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 <to...@yahoo.com> 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