I have managed to find a peace of code that hangs my clients.
Here is the situation :
1. a process starts , opening connections and a consumer
2. some producers send messages to the queue
3. the process terminates abruptly without closing the connection or the
consumer
4. when i try and open a consumer on the same queue - it hangs.

I have some code here that gets activemq stuck. I hope someone will try it
out :
(Please note that you have to run it twice in order to have it stuck...)

package dimes.taskloader.testing.manual;

import java.io.IOException;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;

import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;

/**
 * @author Ohad Serfaty
 *
 */
public class HangTest  {


        public void testMe() throws IOException, InterruptedException,
JMSException{
                ActiveMQConnectionFactory factory = new 
ActiveMQConnectionFactory();
                ActiveMQConnection connection = (ActiveMQConnection)
factory.createConnection();
                connection.setAlwaysSessionAsync(true);
                
                final Session session = connection.createSession(false ,
Session.AUTO_ACKNOWLEDGE);
                
                final Queue queue = session.createQueue("test.queue.1");
                
                
                System.out.println("Creating consumer...");
                MessageConsumer consumer = connection.createSession(true ,
Session.AUTO_ACKNOWLEDGE).createConsumer(queue);
                System.out.println("Setting message listener...");
                consumer.setMessageListener( new MessageListener()
                                {

                        public void onMessage(Message arg0) {
                                System.out.println("Hey!");
                        }
                        
                });
                
                
                Thread[] pool = new Thread[5];
                final MessageProducer[]  producers = new MessageProducer[5];
                
                for (int j=0; j<5; j++)
                {
                        producers[j] = session.createProducer(queue);
                        final int k = j;
                        pool[j] = new Thread(){
                        
                                public void run(){
                                        System.out.println("running ?");
                                        try 
                                        {
                                                 
                                                
                                                for (int i = 0; i < 1000; i++) 
                                                {
                                                        
producers[k].send(session.createTextMessage("Hello!"));
                                                        System.out.println(i + 
":Got here ?");
                                                }
                                        }
                                        catch (Exception e) 
                                        {
                                                e.printStackTrace();
                                        }
                                        System.out.println("Ended ?");
                                }
                };
                }
                        
                System.out.println("starting threads...");
                for (int i=0; i<5; i++)
                        pool[i].start();
                Thread.sleep(2000);
                for (int i=0; i<5; i++)
                        producers[i].close();
                //consumer.close();
                session.close();
                //connection.close();
        }       
        

        // Please note that this method has to be run twice ( from two different
processes...)
        public static void main(String[] args) throws IOException,
InterruptedException, JMSException 
        {
                HangTest tester = new HangTest();
                tester.testMe();
        }
}


-- 
View this message in context: 
http://www.nabble.com/activemq-clients-all-hang-tf1950608.html#a5454005
Sent from the ActiveMQ - User forum at Nabble.com.

Reply via email to