Java JMS:关闭命名上下文失败
此代码在Java JMS:关闭命名上下文失败,java,jboss,jms,handler,jndi,Java,Jboss,Jms,Handler,Jndi,此代码在上下文中引发异常。关闭(): 上下文的关闭作为异步任务传递给ThreadPoolExecutor。但是,ThreadPoolExecutor已终止并拒绝该任务。我不清楚为什么池会被终止,但我猜是有一个正在关闭的过程(或者一个bug?) 我可以想象,由上下文分配的资源最终会被清理掉,因此我唯一能提出的建议是,始终使用方法的finally块,在try/catch包装的代码中关闭上下文 public ConnectionFactory getConnectionFactory() { C
上下文中引发异常。关闭()
:
上下文的关闭作为异步任务传递给ThreadPoolExecutor。但是,ThreadPoolExecutor已终止并拒绝该任务。我不清楚为什么池会被终止,但我猜是有一个正在关闭的过程(或者一个bug?) 我可以想象,由上下文分配的资源最终会被清理掉,因此我唯一能提出的建议是,始终使用方法的finally块,在try/catch包装的代码中关闭上下文
public ConnectionFactory getConnectionFactory() {
Context context = null;
try {
// create context here
// lookup here
// return ConnFactory here
} catch (Exception e) {
// log error, throw exception etc.
} finally {
if(context!=null) try { context.close(); } catch (Exception ex} { /* No Op */ }
}
}
对于JNDI上下文,这通常是合法的,因为对于失败的关闭,您无能为力,并且在其他操作成功后,失败也没有意义。此外,如果JNDI服务中存在严重问题(例如异步线程池被错误终止),我认为确切的症状和诊断将在别处可用和可见。我不会用其他任何东西污染这个简单的代码
public ConnectionFactory getConnectionFactory() {
Context context = null;
try {
// create context here
// lookup here
// return ConnFactory here
} catch (Exception e) {
// log error, throw exception etc.
} finally {
if(context!=null) try { context.close(); } catch (Exception ex} { /* No Op */ }
}
}