本帖最后由 huahuagongzi9999 于 2013-09-11 15:31:49 编辑

解决方案 »

  1.   

    工具内存方面出现为了,找到eclipse.ini文件,
    --launcher.defaultAction
    openFile
    -vmargs
    -Xms40m
    -Xmx384m
    找到最后一行,改为256m试试
      

  2.   


    改了,没用的,估计是上面代码有问题,没有及时释放内存,,我这没报错代码和你的差不多
    我改良了一下,不过感觉MQ不是这么用的。package test;import javax.jms.Connection;
    import javax.jms.ConnectionFactory;
    import javax.jms.DeliveryMode;
    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 javax.jms.TextMessage;
    import javax.jms.Topic;import org.apache.activemq.ActiveMQConnection;
    import org.apache.activemq.ActiveMQConnectionFactory;/**
     * @author Mr.hu
     * @version crateTime:2013-9-11 下午7:15:36
     * Class Explain:
     */
    public class MQTest1 { private static String user = ActiveMQConnection.DEFAULT_USER;  
        private static String password =ActiveMQConnection.DEFAULT_PASSWORD;  
        private static String url =  "tcp://localhost:61616"; 
    private static Connection connection=null;
    private static Session session=null;
    private static MessageProducer producer=null;
    private static MessageConsumer consumer=null;
    private static Topic  destination=null;
    private static  TextMessage textMessage=null;
        
    /**
     * 初始化
     * @throws JMSException
     */
    public static void init() throws JMSException{
     // ConnectionFactory :连接工厂,JMS 用它创建连接  
            ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(user,password,url);  
            // Connection :JMS 客户端到JMS Provider 的连接  
            connection = connectionFactory.createConnection();  
            // Connection 启动  
            connection.start();  
            System.out.println("Connection is start...");  
            // Session: 一个发送或接收消息的线程  
            session = connection.createSession(Boolean.TRUE,Session.AUTO_ACKNOWLEDGE);  
            // Topicr :消息的目的地;消息发送给谁.  
            destination = session.createTopic("exampleA");  
           // destination = session.createQueue("example.A");   
            // MessageProducer:消息发送者  
            producer = session.createProducer(destination); 
     // 设置不持久化,此处学习,实际根据项目决定  
            producer.setDeliveryMode(DeliveryMode.PERSISTENT);  
            consumer = session.createConsumer(destination);
            consumer.setMessageListener(getMessageListener());  
            System.out.println("init ok ..."); 
     }

     /**
      * 发送
      * @throws JMSException
      */
     public static void send() throws JMSException{  
       textMessage = session.createTextMessage();  
       for (int i = 1; i <= 10; i++)  
        {//有限制,达到1000就不行  
         textMessage.setText("ActiveMq 发送的消息" + i);
                // 发送消息到目的地方  
                System.out.println("发送:" + "ActiveMq 发送的消息" + i);  
                producer.send(textMessage);      }   
       session.commit(); 
     }

     /**
      * 接收
      * @return
      */
     public static MessageListener  getMessageListener(){ 
        System.out.println("begin get");
    return  new MessageListener(){//有事务限制  
                @Override  
                public void onMessage(Message message) {   
                    try { 
                     // System.out.println("msg:"+message); 
                        textMessage=(TextMessage)message;  
                        System.out.println("接收:"+textMessage.getText());  
                        session.commit();
                        System.gc();  
                    } catch (JMSException e1) {  
                        e1.printStackTrace();  
                    }
                } 
               
            }; 
    }

     
     /**
      * 关闭 
      */
     public static void close(){
     try {
     if(connection!=null){
       connection.close();
     }
     if(session!=null){
     session.close();
      }
       } catch (JMSException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
     }

     public static void main(String[] args) {

     try {
    init();
    send();
    // close();      
    } catch (JMSException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
     
     
    }
     
     
    }
      

  3.   

    LZ 是应该是你代码写的有问题,我写的用了快一年了都没出现过问题,你的说的发送限制是因为MQ也有连接数量限制的,不知道LZ是否需要代码,跟MQ的有关信息配置
      

  4.   


    应该是吧,可以发您的博客地址给我,或者发我邮箱里面:[email protected],谢谢哦
      

  5.   


    应该是吧,可以发您的博客地址给我,或者发我邮箱里面:[email protected],谢谢哦
    没博客诶,我只是自己研究下,弄到网上怕误人子弟
    程序已发送到你邮箱