根据传统API的JMS规范
The Connection, Session, MessageProducer, MessageConsumer and
QueueBrowser interfaces have been modified to extend the
java.lang.Autocloseable interface. This means that applications can
create these objects using a Java SE 7 try-with-resources statement which
removes the need for applications to explicitly call close() when these
objects are no longer required.和JMS2之后的经典API
The new JMSContext and JMSConsumer interfaces also extend the
java.lang.Autocloseable interface.问题是为什么JMSProducer不扩展AutoCloseable?
发布于 2013-12-27 08:50:02
JMSProducer javadoc的最后一段
JMSProducer的实例是轻量级对象,这些对象可以自由创建,并且不消耗大量资源。因此,此接口不提供关闭方法。
是的,这是令人困惑的,但请注意,MessageProducer确实实现了自动关闭,但JMSProducer没有。
https://stackoverflow.com/questions/20795561
复制相似问题