按照经典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.
在用于经典API的JMS2之后
The new JMSContext and JMSConsumer interfaces also extend the
java.lang.Autocloseable interface.
问题是为什么JMSProducer不扩展AutoCloseable?
最佳答案
JMSProducer的javadoc的最后一段
JMSProducer的实例旨在成为轻量级对象,
可以自由创建,并且不会消耗大量资源。
因此,此接口不提供关闭方法。
是的,这很令人困惑,但是请注意,MessageProducer确实实现了Autocloseable,
但是JMSProducer没有。