0

クラシック 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 を拡張しないのはなぜですか?

4

1 に答える 1

1

JMSProducer の javadoc の最後の段落

JMSProducer のインスタンスは、自由に作成でき、大量のリソースを消費しない軽量オブジェクトを意図しています。したがって、このインターフェースは close メソッドを提供しません。

はい、紛らわしいですが、MessageProducer は Autocloseable を実装していますが、JMSProducer は実装していないことに注意してください。

于 2013-12-27T08:50:02.110 に答える