HttpServer should implement AutoCloseable?
David Alayachew
davidalayachew at gmail.com
Fri Oct 24 14:56:00 UTC 2025
Hello @net-dev at openjdk.org <net-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. Also, there appears to be prior precedent
with HttpExchange.
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
On Fri, Oct 24, 2025 at 10:51 AM David Alayachew <davidalayachew at gmail.com>
wrote:
> Thanks Alan, I'll reattempt this thread over there.
>
> On Fri, Oct 24, 2025 at 1:57 AM Alan Bateman <alan.bateman at oracle.com>
> wrote:
>
>> On 23/10/2025 23:09, David Alayachew 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.
>>
>> The net-dev mailing list is where networking and HTTP issues are usually
>> discussed. HttpExchange was retrofitted to implement AutoCloseable in JDK
>> 14 and there may have been discussed (can't remember) about HttpServer at
>> the time.
>>
>> -Alan
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/net-dev/attachments/20251024/69da7ba3/attachment.htm>
More information about the net-dev
mailing list