HttpServer should implement AutoCloseable?

David Alayachew davidalayachew at gmail.com
Wed Nov 5 10:39:01 UTC 2025


Oh yes, using Closeable would be much better, ty vm.

On Wed, Nov 5, 2025, 5:32 AM Volkan Yazıcı <volkan at yazi.ci> wrote:

> Given `close()` involves performing I/O, I suggest implementing
> `Closeable` instead of `AutoCloseable`. Also note that `Closeable::close`
> is required to be idempotent, which fits our bill.
>
> On Fri, Oct 24, 2025 at 12:11 AM David Alayachew <davidalayachew at gmail.com>
> wrote:
>
>> Hello @core-libs-dev <core-libs-dev at openjdk.org>,
>>
>> Would it be ok if we made HttpServer from the jdk.httpserver module
>> implement AutoCloseable? Having this would prevent people from forgetting
>> to close the server after use.
>>
>> The close() implementation could call stop(int delay) with a reasonable
>> default. This implementation should be a default one, so that existing
>> child classes that also implemented AutoCloseable lose no functionality.
>>
>> Thank you for your time and consideration.
>> David Alayachew
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20251105/1cea07bb/attachment-0001.htm>


More information about the core-libs-dev mailing list