jsr343-experts@jms-spec.java.net

[jsr343-experts] Re: [jms-spec users] Re: Re: Make TemporaryQueue/Topic AutoCloseable?

From: Nigel Deakin <nigel.deakin_at_oracle.com>
Date: Mon, 07 Jan 2013 12:57:20 +0000

Philippe,

On 04/01/2013 21:12, Philippe Marschall wrote:
>
> The way my code usually looks is like this:
>
> TemporaryQueue queue = session.createTemporaryQueue(…);
> try {
> // work with queue
> } finally {
> queue.delete();
> }
>
> with AutoCloseable it would look like this
>
> try (TemporaryQueue queue = session.createTemporaryQueue(…)) {
> // work with queue
> }
>
> Again, I'm not sure whether this is a good idea™ or a misuse of a
> language feature.

Thanks. So your proposal is that we make TemporaryQueue and
TemporaryTopic implement AutoCloseable. This would add new close()
methods which would do the same as the existing delete() methods.

I can see the advantage of this, but I think this is a bit of a misuse
as you suggest. The existing method is delete, not close, no doubt
because the original authors deliberately decided that this was
semantically a "delete" rather than a "close". We should probably not
try to override that just to allow us to use AutoCloseable. And having
two method that do the same thing is not a good design.

Nigel