根据经典 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?
最佳答案
JMSProducer javadoc 的最后一段
Instances of JMSProducer are intended to be lightweight objects which can be created freely and which do not consume significant resources. This interface therefore does not provide a close method.
是的,这很令人困惑,但请注意 MessageProducer 确实实现了 Autocloseable, 但 JMSProducer 没有。
关于java - 为什么 JMSProducer 接口(interface)不扩展 java.lang.Autocloseable?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20795561/