java启动和停止JMSContext
{
@Inject
JMSContext jmsContext;
this.jmsContext.start();
this.jmsContext.stop();
但是,我不允许使用这些方法,因为start()
的JavaDoc声明“如果JMSContext是容器管理(注入)的,则不得使用此方法。这样做将导致引发非法StateRuntimeException。”
(我试过了,这两种方法都会引发异常。)
那么,如果JMSContext
是容器管理的,我该如何启动和停止它呢
# 1 楼答案
容器管理的
JMSContext
的生命周期(start()
,stop()
)由容器管理。这意味着注入的JMSContext
在注入时已经启动,并且将由容器停止,具体取决于使用JMSContext
的上下文以下是JMS Specification 2.0(Download)对这个话题的看法:
它进一步描述了对
JMSContext
API的限制: