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

时间:2013-12-27 05:53:54

标签: 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.

经典API的JMS2之后

The new JMSContext and JMSConsumer interfaces also extend the
java.lang.Autocloseable interface.

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

1 个答案:

答案 0 :(得分:1)

来自JMSProducer的javadoc的最后一段

  

JMSProducer的实例旨在成为轻量级对象   可以自由创建,不消耗大量资源。   因此,该接口不提供紧密的方法。

是的,它令人困惑,但请注意MessageProducer确实实现了Autocloseable, 但JMSProducer没有。