You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Jigar Naik <ji...@interactcrm.com> on 2008/08/30 11:15:00 UTC
Producer stops producing messages after producing 1542 messages.
hi
i am facing problem with producer,
My producer stops producing messages after producing 1542 messages on active
mq
bellow is my output after running producer thread
OUTPUT
Message Sent : Hello This is a text message on active MQ : 1542
Exception in thread "ActiveMQ Transport: tcp://localhost/127.0.0.1:61616"
java.lang.OutOfMemoryError: Java heap space
Exception in thread "InactivityMonitor ReadCheck"
java.lang.OutOfMemoryError: Java heap space
What could be the possible reason for this error..
bellow is my producer code...
Producer.java
---------------------
package org.icrm;
import javax.jms.Connection;
import javax.jms.DeliveryMode;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.apache.activemq.ActiveMQConnectionFactory;
public class Producer {
private MessageProducer producer;
ActiveMQConnectionFactory connectionFactory;
Connection connection;
Session session;
Destination destination;
public static void main(String[] args) {
Producer p = new Producer();
for(int i=0;i<100000;i++){
p.sendMessageToActiveMQ("Hello This is a text message on active MQ : " +
i, "TestQueue");
}
}
/**
* Send Message to ActiveMQ
* @param message
* @param queueName
*/
public void sendMessageToActiveMQ(String message,String queueName){
try {
connectionFactory = new
ActiveMQConnectionFactory("tcp://localhost:61616");
connection = connectionFactory.createConnection();
connection.start();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
destination = session.createQueue(queueName);
this.producer = session.createProducer(destination);
this.producer.setDeliveryMode(DeliveryMode.PERSISTENT);
TextMessage textMessage = session.createTextMessage();
textMessage.setText(message);
this.producer.send(textMessage);
System.out.println("Message Sent : " + message);
} catch (JMSException e) {
e.printStackTrace();
} catch (Exception e){
e.printStackTrace();
}finally{
producer = null;
connectionFactory = null;
connection = null;
session = null;
destination = null;
}
}
}
--
View this message in context: http://www.nabble.com/Producer-stops-producing-messages-after-producing-1542-messages.-tp19231685p19231685.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.
Re: Producer stops producing messages after producing 1542
messages.
Posted by Jigar Naik <ji...@interactcrm.com>.
yes you were right.....
connection.close(); was missing in finally block... and now the program is
working fine...
}finally{
producer = null;
connectionFactory = null;
connection = null;
session = null;
destination = null;
}
Mario Siegenthaler-2 wrote:
>
> I'd say you run out of memory on the broker due to a memory leak in
> the connection handling, every closed connection leaves a thread open
> and still hogs some memory. You can check that with jConsole.
> Can you try reusing or pooling the connections? There's a
> PooledConnectionFactory that does this. It's advisable to do this
> anyway as the constant open/close of connection uses a lot of system
> resources and slows down your producer quite a bit.
>
> --Mario
>
> On Sat, Aug 30, 2008 at 11:15 AM, Jigar Naik <ji...@interactcrm.com>
> wrote:
>>
>> hi
>>
>> i am facing problem with producer,
>>
>> My producer stops producing messages after producing 1542 messages on
>> active
>> mq
>>
>> bellow is my output after running producer thread
>>
>> OUTPUT
>> Message Sent : Hello This is a text message on active MQ : 1542
>> Exception in thread "ActiveMQ Transport: tcp://localhost/127.0.0.1:61616"
>> java.lang.OutOfMemoryError: Java heap space
>> Exception in thread "InactivityMonitor ReadCheck"
>> java.lang.OutOfMemoryError: Java heap space
>>
>> What could be the possible reason for this error..
>>
>> bellow is my producer code...
>> Producer.java
>> ---------------------
>> package org.icrm;
>>
>> import javax.jms.Connection;
>> import javax.jms.DeliveryMode;
>> import javax.jms.Destination;
>> import javax.jms.JMSException;
>> import javax.jms.MessageProducer;
>> import javax.jms.Session;
>> import javax.jms.TextMessage;
>>
>> import org.apache.activemq.ActiveMQConnectionFactory;
>>
>>
>> public class Producer {
>> private MessageProducer producer;
>> ActiveMQConnectionFactory connectionFactory;
>> Connection connection;
>> Session session;
>> Destination destination;
>>
>> public static void main(String[] args) {
>> Producer p = new Producer();
>>
>> for(int i=0;i<100000;i++){
>> p.sendMessageToActiveMQ("Hello This is a text
>> message on active MQ : " +
>> i, "TestQueue");
>> }
>>
>> }
>> /**
>> * Send Message to ActiveMQ
>> * @param message
>> * @param queueName
>> */
>> public void sendMessageToActiveMQ(String message,String
>> queueName){
>> try {
>> connectionFactory = new
>> ActiveMQConnectionFactory("tcp://localhost:61616");
>> connection =
>> connectionFactory.createConnection();
>> connection.start();
>> session =
>> connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
>> destination =
>> session.createQueue(queueName);
>> this.producer =
>> session.createProducer(destination);
>>
>> this.producer.setDeliveryMode(DeliveryMode.PERSISTENT);
>> TextMessage textMessage =
>> session.createTextMessage();
>> textMessage.setText(message);
>> this.producer.send(textMessage);
>> System.out.println("Message Sent : " + message);
>> } catch (JMSException e) {
>> e.printStackTrace();
>> } catch (Exception e){
>> e.printStackTrace();
>> }finally{
>> producer = null;
>> connectionFactory = null;
>> connection = null;
>> session = null;
>> destination = null;
>> }
>>
>> }
>> }
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Producer-stops-producing-messages-after-producing-1542-messages.-tp19231685p19231685.html
>> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>>
>>
>
>
--
View this message in context: http://www.nabble.com/Producer-stops-producing-messages-after-producing-1542-messages.-tp19231685p19233052.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.
Re: Producer stops producing messages after producing 1542 messages.
Posted by Mario Siegenthaler <ms...@inventsoft.ch>.
I'd say you run out of memory on the broker due to a memory leak in
the connection handling, every closed connection leaves a thread open
and still hogs some memory. You can check that with jConsole.
Can you try reusing or pooling the connections? There's a
PooledConnectionFactory that does this. It's advisable to do this
anyway as the constant open/close of connection uses a lot of system
resources and slows down your producer quite a bit.
--Mario
On Sat, Aug 30, 2008 at 11:15 AM, Jigar Naik <ji...@interactcrm.com> wrote:
>
> hi
>
> i am facing problem with producer,
>
> My producer stops producing messages after producing 1542 messages on active
> mq
>
> bellow is my output after running producer thread
>
> OUTPUT
> Message Sent : Hello This is a text message on active MQ : 1542
> Exception in thread "ActiveMQ Transport: tcp://localhost/127.0.0.1:61616"
> java.lang.OutOfMemoryError: Java heap space
> Exception in thread "InactivityMonitor ReadCheck"
> java.lang.OutOfMemoryError: Java heap space
>
> What could be the possible reason for this error..
>
> bellow is my producer code...
> Producer.java
> ---------------------
> package org.icrm;
>
> import javax.jms.Connection;
> import javax.jms.DeliveryMode;
> import javax.jms.Destination;
> import javax.jms.JMSException;
> import javax.jms.MessageProducer;
> import javax.jms.Session;
> import javax.jms.TextMessage;
>
> import org.apache.activemq.ActiveMQConnectionFactory;
>
>
> public class Producer {
> private MessageProducer producer;
> ActiveMQConnectionFactory connectionFactory;
> Connection connection;
> Session session;
> Destination destination;
>
> public static void main(String[] args) {
> Producer p = new Producer();
>
> for(int i=0;i<100000;i++){
> p.sendMessageToActiveMQ("Hello This is a text message on active MQ : " +
> i, "TestQueue");
> }
>
> }
> /**
> * Send Message to ActiveMQ
> * @param message
> * @param queueName
> */
> public void sendMessageToActiveMQ(String message,String queueName){
> try {
> connectionFactory = new
> ActiveMQConnectionFactory("tcp://localhost:61616");
> connection = connectionFactory.createConnection();
> connection.start();
> session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
> destination = session.createQueue(queueName);
> this.producer = session.createProducer(destination);
> this.producer.setDeliveryMode(DeliveryMode.PERSISTENT);
> TextMessage textMessage = session.createTextMessage();
> textMessage.setText(message);
> this.producer.send(textMessage);
> System.out.println("Message Sent : " + message);
> } catch (JMSException e) {
> e.printStackTrace();
> } catch (Exception e){
> e.printStackTrace();
> }finally{
> producer = null;
> connectionFactory = null;
> connection = null;
> session = null;
> destination = null;
> }
>
> }
> }
>
> --
> View this message in context: http://www.nabble.com/Producer-stops-producing-messages-after-producing-1542-messages.-tp19231685p19231685.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
>