我编写了一个简单的程序,ActiveMQ
如下所示:
public static void main(String[] args) throws Throwable
{
final ActiveMQConnectionFactory conFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
final QueueConnection connection = conFactory.createQueueConnection();
final Session session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
final Destination destination = new ActiveMQQueue("MJ_SAF");
final MessageProducer producer = session.createProducer(destination);
Message message = session.createTextMessage("test");
message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, 20);
message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_PERIOD, 1);
message.setIntProperty(ScheduledMessage.AMQ_SCHEDULED_REPEAT, 1);
producer.send(message);
}
当我执行此程序时,消息ActiveMQ
会正确发送给代理,但我的程序不会退出并继续运行。当我将connection.close();
语句添加到上述程序的末尾时,我的程序完成并正确退出。
我的问题是:这种行为的原因是什么?