如題,怎麼回事啊?我寫的main方法測試的,第一遍能運行出來,第二次就不行了
public class MessageSendAndReceive {
public static void main(String[] args) throws JMSException {
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
"vm://localhost");
Connection connection = connectionFactory.createConnection();
connection.start();
Queue queue = new ActiveMQQueue("testQueue");
Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
MessageProducer messageProducer = session.createProducer(queue);
messageProducer.send(session.createTextMessage("Message"));
MessageConsumer messageConsumer = session.createConsumer(queue);
messageConsumer.setMessageListener(new MessageListener() {
public void onMessage(Message msg) {
TextMessage message = (TextMessage) msg;
try {
System.out.println(message.getText());
} catch (JMSException e) {
e.printStackTrace();
}
}
});
這個只執行一次,第二次就沒反應了,也不報錯,要把MyEclipse關了在打開才能運行一次。。怎麼回事啊
沒人啊。。。。求助啊。。。。