使用JMS发送消息在退出时挂起 [英] Sending message with JMS hangs on exit

查看:89
本文介绍了使用JMS发送消息在退出时挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



问题在于,在应用程序发送了一个JMS消息消息,它应该在退出时挂起。该消息传输成功,但由于某种原因,该应用程序不会退出。我试图调试应用程序,并且我可以一直步调到 static void main 的末尾,这就是挂起的位置。



以下是代码:

  import javax.jms。*; 
import javax.naming.InitialContext;


public class Main {

public void SendMessage()throws Exception {
InitialContext ctx = new InitialContext();
ConnectionFactory cf =(ConnectionFactory)ctx.lookup(jms / TestFactory);
队列队列=(队列)ctx.lookup(jms / TestQueue);
连接conn = cf.createConnection();
Session s = conn.createSession(false,Session.AUTO_ACKNOWLEDGE);
MessageProducer prod = s.createProducer(queue);

TextMessage txt = s.createTextMessage(testing);
prod.send(txt);

prod.close();
s.close();
conn.close();


public static void main(String [] args)throws Exception {
Main m = new Main();
m.SendMessage();
}

public Main(){
super();
}

}

如何让它停止悬挂

解决方案

这是Glassfish很长一段时间的错误。



这里记录了一个错误(在Sun App Server第9版中报告,早于Glassfish),但是我怀疑会有很多重复的报告: $ b

< a href =http://java.net/jira/browse/GLASSFISH-1429 =nofollow> http://java.net/jira/browse/GLASSFISH-1429



我唯一已知的修复方法是关闭所有线程的System.exit(0)(在finally块中)。



可怕,是的。


I am trying to create a Java Application Client project that sends a JMS message to a queue on a Glassfish server.

The problem is that after the app sends the message, it hangs when it's supposed to exit. The message is transmitted successfully, but for some reason the app doesn't exit. I have tried to debug the application, and I can step trough it all the way to the end of static void main, and that's where it hangs.

Here is the code:

import javax.jms.*;
import javax.naming.InitialContext;


public class Main {

public void SendMessage() throws Exception {
    InitialContext ctx = new InitialContext();
    ConnectionFactory cf = (ConnectionFactory) ctx.lookup("jms/TestFactory");
    Queue queue = (Queue)ctx.lookup("jms/TestQueue");
    Connection conn = cf.createConnection();
    Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer prod = s.createProducer(queue);

    TextMessage txt = s.createTextMessage("testing");
    prod.send(txt);

    prod.close();
    s.close();
    conn.close();
}

public static void main(String[] args) throws Exception {
    Main m = new Main();
    m.SendMessage();
}

public Main() {
    super();
}

}

How can I make it stop hanging?

解决方案

It's been a bug in Glassfish for a long time.

There is a bug recorded here (reported back in version 9 of Sun App Server, predating Glassfish), but I suspect there will be lots of duplicate reports:

http://java.net/jira/browse/GLASSFISH-1429

My only known fix is to System.exit(0) (in a finally block), which closes all threads.

Horrible, yes.

这篇关于使用JMS发送消息在退出时挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆