activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Strachan" <james.strac...@gmail.com>
Subject Re: Broker used up the memory
Date Wed, 27 Sep 2006 10:14:39 GMT
How long do you run your system for? Try send about 10,000 messages
through the system, then monitor the memory and see if there's a leak.

On 9/27/06, HU <gong_pu@hotmail.com> wrote:
>
> Hi, James.
>
> Thanks, I have had the broker run with Mysql DB.
>
> Then I run the broker and a sender on a PC and run a consumer on another PC,
> Send a message to a queue by the sender thread and receve the messsage by
> the consumer thread then reply a message to sender thread by the consumer,
> repeat the actions.
> I found the heap was used creep up and did not found the used memory be
> released by the consumer thread. I used GC to get tracing for the test.
> Following are the codes of my test, could you please help me to fix the
> issue.
>
> public class Newconsumer extends Thread{
>     private Session         session;
>     private Connection      connection;
>     private MessageConsumer consumer;
>     private Destination     destinetionQueue;
>     public Newconsumer(Connection con) {
>         this.connection = con;
>         try {
>             session = this.connection.createSession(true,
> Session.AUTO_ACKNOWLEDGE);
>             destinetionQueue = session.createQueue("RequestQueue");
>             consumer = session.createConsumer(destinetionQueue);
>         } catch (JMSException e) { }
>     }
>
>     public void close() {
>         try {
>                 if( consumer != null ) consumer.close();
>             if (session != null) session.close();
>         } catch (JMSException e) {  e.printStackTrace(); }
>     }
>
>     public void run() {
>         while(true){
>             try {
>                 Message msg = consumer.receive(10000);
>                 if ( msg == null ) continue;
>                 Destination destResp = ((MapMessage) msg).getJMSReplyTo() ;
>                 String sCorrelationID = ((MapMessage)
> msg).getJMSCorrelationID();
>                 String sAnkenID = ((MapMessage) msg).getString("ID");
>                 Session sessSend = this.connection.createSession( false,
> Session.AUTO_ACKNOWLEDGE);
>                 MapMessage msgTime = sessSend.createMapMessage();
>                 msgTime.setJMSCorrelationID( sCorrelationID);
>                 msgTime.setString( "ID",sAnkenID);
>                 msgTime.setLong("TIMEOUT",35000 );
>                 MessageProducer producer =
> sessSend.createProducer(destResp);
>                 producer.send(msgTime);
>                 MapMessage msgRes = session.createMapMessage();
>                 msgRes.setJMSCorrelationID( sCorrelationID);
>                 msgRes.setString( "ID",sAnkenID);
>                 msgRes.setString( "RESULT","SUCCESS");
>                 producer.send(msgRes);
>                 this.session.commit();
>                 producer.close();
>                 producer=null;
>                 sessSend.close();
>                 sessSend=null;
>
>             } catch (JMSException e) { e.printStackTrace(); }
>             break;
>         }
>         this.close();
>     }
> }
>
> public class ConsumerController {
>         public static Newconsumer consumer;
>
>     public static void main(String[] args) throws NamingException {
>         ActiveMQConnectionFactory factory;
>         Connection                connAnken;
>         factory = new ActiveMQConnectionFactory("tcp://localhost:61616");
>         try {
>             connAnken = factory.createQueueConnection();
>             connAnken.start();
>             consumer = new Newconsumer(connAnken);
>                 consumer.start() ;
>             try {
>                      while(true) {
>                          consumer.join();
>                          consumer =null;
>                          consumer = new Newconsumer(connAnken);
>                          consumer.start();
>                      }
>             } catch (Throwable e) {
>                 e.printStackTrace();
>             } finally{
>                 connAnken.close() ;
>                 connAnken=null;
>             }
>         } catch (Throwable e) { e.printStackTrace(); }
>     }
> }
>
>
> activemq.xml
> ------------------------------------------------------------------------------------------
> <!-- START SNIPPET: example -->
> <beans xmlns="http://activemq.org/config/1.0">
>   <bean
> class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
>   <broker useJmx="true">
>     <destinationPolicy>
>       <policyMap><policyEntries>
>           <policyEntry topic="FOO.>">
>             <dispatchPolicy>
>               <strictOrderDispatchPolicy />
>             </dispatchPolicy>
>             <subscriptionRecoveryPolicy>
>               <lastImageSubscriptionRecoveryPolicy />
>             </subscriptionRecoveryPolicy>
>           </policyEntry>
>       </policyEntries></policyMap>
>     </destinationPolicy>
>     <persistenceAdapter>
>       <journaledJDBC journalLogFiles="5"
> dataDirectory="../activemq-data-0926" dataSource="#mysql-ds"/>
>     </persistenceAdapter>
>     <transportConnectors>
>        <transportConnector name="default" uri="tcp://localhost:61616"
> discoveryUri="multicast://default"/>
>        <transportConnector name="stomp"   uri="stomp://localhost:61613"/>
>     </transportConnectors>
>     <networkConnectors>
>       <networkConnector name="default" uri="multicast://default"/>
>     </networkConnectors>
>   </broker>
>   <bean id="mysql-ds" class="org.apache.commons.dbcp.BasicDataSource"
> destroy-method="close">
>     <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
>     <property name="url"
> value="jdbc:mysql://localhost/activemq?relaxAutoCommit=true"/>
>     <property name="username" value="activemq"/>
>     <property name="password" value="activemq"/>
>     <property name="poolPreparedStatements" value="true"/>
>   </bean>
>
> </beans>
> <!-- END SNIPPET: example -->
>
> eclipse.ini
> ------------------------------------------------------------------------------------------
> -vmargs
> -Xms128M
> -Xmx512M
> -XX:PermSize=64M
> -XX:MaxPermSize=128M
>
> Thanks,
> Hu
> --
> View this message in context: http://www.nabble.com/Broker-used-up-the-memory-tf2316972.html#a6523894
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
>


-- 

James
-------
http://radio.weblogs.com/0112098/

Mime
View raw message