jsr343-experts@jms-spec.java.net

[jsr343-experts] Re: Make Connection, Session and other interfaces implement AutoCodeable

From: Nigel Deakin <nigel.deakin_at_oracle.com>
Date: Thu, 15 Dec 2011 18:27:30 +0000

On 29/09/2011 15:24, Nigel Deakin wrote:
> I'd like to raise this as a discussion topic rather than a concrete proposal.
>
> I've also logged this in JIRA
> http://java.net/jira/browse/JMS_SPEC-53
>
> My question is: should we change all the JMS interfaces that currently implement a close() method to implement the
> java.lang.AutoCloseable interface?
>
> This would affect Connection, Session, MessageConsumer, MessageProducer, QueueBrowser.

This proposal received support and no objections when I raised it some time ago.

I've been looking at this in a bit more detail.

Making Connection, MessageConsumer, MessageProducer, QueueBrowser extend AutoCloseable seems straightforward.

However there's a problem with Session. This already extends Runnable, so I can't make it extend AutoCloseable. (I can't
think of an obvious way around this, but if I've missed something obvious please let me know)

This suggests two options:

1. Leave Session unchanged and make all the other interfaces extend AutoCloseable

2. Option (1) is confusing and inconsistent to users. It's better to simply make Connection extend AutoCloseable and
leave the other interfaces unchanged. In practice the only object that actually needs closing in practice is COnnection
anyway.

Any preferences? I'm inclined towards (2)...

Nigel