java - 为什么 JMSProducer 接口(interface)不扩展 java.lang.Autocloseable?

标签 java jms jms2

根据经典 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/

相关文章:

java - JMS 消息监听器调用程序失败,原因 : Identifier contains invalid JMS identifier character '-' : 'x-request-id'

java-8 - 对象消息上的 JMS 消息选择器

java - 将图像拖放到Jpanel中并将其放入应用程序目录中

java - 我该如何修复这个错误?需要双,双;发现双重;

java - 是否可以将泛型类型扩展到 Java 中的多个类?

java - 非法访问 - 该 Web 应用程序实例已被停止。

java - JMS 队列已满

java - JMS 消息存储在 WebLogic 9.2 服务器中的哪里?

java - 如何创建临时队列并在 JMS 2 中访问它