首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么JMSProducer接口不扩展java.lang.Autocloseable?

为什么JMSProducer接口不扩展java.lang.Autocloseable?
EN

Stack Overflow用户
提问于 2013-12-27 05:53:53
回答 1查看 1.2K关注 0票数 1

根据传统API的JMS规范

代码语言:javascript
复制
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

代码语言:javascript
复制
The new JMSContext and JMSConsumer interfaces also extend the
java.lang.Autocloseable interface.

问题是为什么JMSProducer不扩展AutoCloseable?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-12-27 08:50:02

JMSProducer javadoc的最后一段

JMSProducer的实例是轻量级对象,这些对象可以自由创建,并且不消耗大量资源。因此,此接口不提供关闭方法。

是的,这是令人困惑的,但请注意,MessageProducer确实实现了自动关闭,但JMSProducer没有。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20795561

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档