On Thu, 14 Aug 2025 18:33:51 GMT, Volkan Yazici <vyaz...@openjdk.org> wrote:

> Make `ProxyServer` not extend from `Thread`.

test/jdk/java/net/httpclient/ProxyServer.java line 43:

> 41:  * intended for large numbers of parallel connections.
> 42:  */
> 43: public final class ProxyServer implements Closeable {

Added `final` to enhance the encapsulation

test/jdk/java/net/httpclient/ProxyServer.java line 100:

> 98:     }
> 99: 
> 100:     private ProxyServer(Integer port, Boolean debug, Credentials 
> credentials)

`Credentials` is a `private` class, this ctor should not be exposed.

test/jdk/java/net/httpclient/ProxyServer.java line 110:

> 108:         this.credentials = credentials;
> 109:         connections = new CopyOnWriteArrayList<Connection>();
> 110:         
> Thread.ofPlatform().name("ProxyListener").daemon().start(this::run);

No need to hold a reference to the `Thread`. It will terminate either at the 
JVM exit, or via `done` flag checked in the `run()` loop.

test/jdk/java/net/httpclient/ProxyServer.java line 650:

> 648:         boolean debug = args.length > 1 && args[1].equals("-debug");
> 649:         System.out.println("Debugging : " + debug);
> 650:         try (ProxyServer ps = new ProxyServer(port, debug)) {

If we want users to properly wrap `ProxyServer` in try-with-resources, we 
should be such an example too.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/26786#discussion_r2277439411
PR Review Comment: https://git.openjdk.org/jdk/pull/26786#discussion_r2277440573
PR Review Comment: https://git.openjdk.org/jdk/pull/26786#discussion_r2277443640
PR Review Comment: https://git.openjdk.org/jdk/pull/26786#discussion_r2277446274

Reply via email to