簡體   English   中英

為什么JMSProducer接口不擴展java.lang.Autocloseable?

[英]Why JMSProducer interface does not extend java.lang.Autocloseable?

按照經典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沒有實現。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM