activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Viali <Vi...@163.COM>
Subject How to enlarge ActiveMQ'S capacity of concurrent?
Date Wed, 13 Sep 2006 15:49:37 GMT

I confiugre and xml file for ActiveMQ, and create a broker using Xbean as
followed: 
xbean.xml: 

<beans> 
  <bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/> 
  <broker useJmx="true" xmlns="http://activemq.org/config/1.0" > 
    <persistenceAdapter>     
           <journaledJDBC journalLogFiles="5"  dataDirectory="./Data" />           
   
    </persistenceAdapter> 
    <transportConnectors> 
        <transportConnector uri="tcp://localhost:61616" /> 
    </transportConnectors>     
  </broker> 
</beans> 

Java Code for creating a broker: 

URI uri=new URI("xbean:xbean.xml"); 
BrokerService broker = BrokerFactory.createBroker(uri); 
broker.start(); 

Then, Write a message provider: 

public static class HelloWorldProducer implements Runnable { 
        public void run() { 
            try { 
                // Create a ConnectionFactory 
                ActiveMQConnectionFactory connectionFactory = new
ActiveMQConnectionFactory("tcp://localhost:61616"); 
                // Create a Connection 
                Connection connection =
connectionFactory.createConnection(); 
                connection.start(); 
                // Create a Session 
                Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE); 
                // Create the destination (Topic or Queue) 
                Destination destination = session.createQueue("TEST.FOO"); 
                // Create a MessageProducer from the Session to the Topic or
Queue 
                MessageProducer producer =
session.createProducer(destination); 
                producer.setDeliveryMode(DeliveryMode.PERSISTENT); 
                // Create a messages 
                String text = "Hello world! From: " +
Thread.currentThread().getName() + " : " + this.hashCode(); 
                TextMessage message = session.createTextMessage(text); 
                // Tell the producer to send the message 
                System.out.println("Sent message: "+ message.hashCode() + "
: " + Thread.currentThread().getName()); 
                producer.send(message); 
                // Clean up 
                session.close(); 
                connection.close(); 
            } 
            catch (Exception e) 
            { 
                e.printStackTrace(); 
            } 
        } 
    } 

However, when I run the codes followed: 

      for(int i=0;i<500;i++)//create 500 connections at the same time.. 
        { 
        thread(new HelloWorldProducer(), false); 
        //   Thread.sleep(300); // everything works fine if sleep. 
        } 

Then some thread runs fine, but others not.  I can see Exceptions happens: 

javax.jms.JMSException: Could not connect to broker URL:
tcp://localhost:61616. Reason: java.net.ConnectException: Connection
refused: connect 
        at
org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:32) 
        at
org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:252)

        at
org.apache.activemq.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:165)

        at org.sigsit.ict.AppTest$HelloWorldProducer.run(AppTest.java:51) 
        at java.lang.Thread.run(Unknown Source) 
Caused by: java.net.ConnectException: Connection refused: connect 
..........balaballa.. 



-- 
View this message in context: http://www.nabble.com/How-to-enlarge-ActiveMQ%27S-capacity-of-concurrent--tf2266104.html#a6288355
Sent from the ActiveMQ - Dev forum at Nabble.com.


Mime
View raw message