JMS(Jboss Messaging)的一点使用心得(十二)多线程的ClassLoader
来源:互联网 发布:人工智能 英文 最新 编辑:程序博客网 时间:2024/05/17 02:58
在可自动重连的JmsMessageListenerContainer中,有一个ClassLoader的属性值,请参见
[http://blog.csdn.net/supersue/archive/2008/04/02/2244727.aspx]
在JmsMessageListenerContainer被初始化的时候(afterPropertiesSet),该ClassLoader被赋值,代码如下:
而在发生异常启动线程重新连接的时候(onException),把该值赋给了重连线程,如下所示:
这样做的原因是因为启动JmsMessageListenerContainer的线程和执行onExcetion的线程不是同一个线程,ClassLoader也不一样,如果不把原来的ClassLoader保留的话,会导致重连前可以正常处理Jms消息,而重连后却发生NoClassFound错误。
[http://blog.csdn.net/supersue/archive/2008/04/02/2244727.aspx]
在JmsMessageListenerContainer被初始化的时候(afterPropertiesSet),该ClassLoader被赋值,代码如下:
@Override
public void afterPropertiesSet() ...{
super.afterPropertiesSet();
this.classLoader = Thread.currentThread().getContextClassLoader();
}
public void afterPropertiesSet() ...{
super.afterPropertiesSet();
this.classLoader = Thread.currentThread().getContextClassLoader();
}
而在发生异常启动线程重新连接的时候(onException),把该值赋给了重连线程,如下所示:
public void onException(JMSException e) ...{
this.logger.error(this.getBeanName() + " Connection Error: " + e.getMessage());
if (this.checker != null) ...{
this.checker.shutdown();
this.checker = null;
}
this.checker = new CheckConnectionThread();
this.checker.setDaemon(true);
this.checker.setContextClassLoader(this.classLoader);
this.checker.start();
}
this.logger.error(this.getBeanName() + " Connection Error: " + e.getMessage());
if (this.checker != null) ...{
this.checker.shutdown();
this.checker = null;
}
this.checker = new CheckConnectionThread();
this.checker.setDaemon(true);
this.checker.setContextClassLoader(this.classLoader);
this.checker.start();
}
这样做的原因是因为启动JmsMessageListenerContainer的线程和执行onExcetion的线程不是同一个线程,ClassLoader也不一样,如果不把原来的ClassLoader保留的话,会导致重连前可以正常处理Jms消息,而重连后却发生NoClassFound错误。
- JMS(Jboss Messaging)的一点使用心得(十二)多线程的ClassLoader
- JMS(Jboss Messaging)的一点使用心得(六)Messaging扩展应用-Message Bridge
- JMS(Jboss Messaging)的一点使用心得(八)JBoss invoke-动态修改Bridge
- JMS(Jboss Messaging)的一点使用心得(十六)复数JMS Server监听-JBoss Remoting里存在的问题
- JMS(Jboss Messaging)的一点使用心得(二)使用Spring
- JMS(Jboss Messaging)的一点使用心得(十)对IPv6的支持
- JMS(Jboss Messaging)的一点使用心得(一)环境配置
- JMS(Jboss Messaging)的一点使用心得(三)Spring扩展应用-Security
- JMS(Jboss Messaging)的一点使用心得(九)实例代码
- JMS(Jboss Messaging)的一点使用心得(四)Spring扩展应用-可修改的JMS ConnectionFactory
- JMS(Jboss Messaging)的一点使用心得(七)JBoss invoke-动态创建Queue或者Topic
- JMS(Jboss Messaging)的一点使用心得(五)Spring扩展应用-可自动重连的JmsMessageListenerContainer
- JMS(Jboss Messaging)的一点使用心得(十四)Spring扩展应用—用单线程接收Queue
- JMS(Jboss Messaging)的一点使用心得(十五)Spring扩展应用—延迟发送Message
- JMS(Jboss Messaging)的一点使用心得(十三)拔网线后的重连----JMS Connection原理浅析及应用
- JMS(Jboss Messaging)的一点使用心得(十一)Spring扩展应用-可自动重连的JmsMessageListenerContainer的另一种实现
- JMS(Jboss Messaging)
- JMS(Java Messaging Service)
- 快速查毒及电脑防毒的解决方案
- u-boot学习笔记三(启动汇编)
- 打算写一个C++程序(1)
- POJ 1088
- URLDownloadToFile函数
- JMS(Jboss Messaging)的一点使用心得(十二)多线程的ClassLoader
- javax.swing.JOptionPane.showMessageDialog() 方法
- 使用 C# 进行 label 打印 的两种方式
- ARM入门的好文章
- vc内嵌汇编问题集锦
- 银幕上的张爱玲式爱情
- 如何用编码实现文件下载
- 通过MSIL了解CLR的运行原理
- 中国男足为什么总是输(转)