RFR: 8308310: HttpClient: Avoid logging or locking from within synchronized blocks

Andrey Turbanov aturbanov at openjdk.org
Thu May 18 09:44:51 UTC 2023


On Wed, 17 May 2023 18:46:35 GMT, Daniel Fuchs <dfuchs at openjdk.org> wrote:

> Please find here a change that revisits usage of monitors in the HttpClient.
> 
> With Virtual Threads now part of the platform it should be possible to pass a newVirtualThreadPerTaskExecutor to the HttpClient. Logging, when enabled, and when called from a synchronized block, can cause the carrier thread to get pinned in case of contention when printing through the underlying PrintStream.
> 
> This change aims at avoiding situations where the carrier threads might get pinned.

src/java.net.http/share/classes/jdk/internal/net/http/ConnectionPool.java line 61:

> 59:     // Pools of idle connections
> 60: 
> 61:     private final ReentrantLock stateLock =  new ReentrantLock();

Suggestion:

    private final ReentrantLock stateLock = new ReentrantLock();

src/java.net.http/share/classes/jdk/internal/net/http/Http1Response.java line 130:

> 128:         }
> 129: 
> 130:         public  boolean acquire() {

Suggestion:

        public boolean acquire() {

test/jdk/java/net/httpclient/AuthFilterCacheTest.java line 298:

> 296:             synchronized (this) {
> 297:                 count = ++this.count;
> 298:                 passwordAuthentication =  super.requestPasswordAuthenticationInstance(

Suggestion:

                passwordAuthentication = super.requestPasswordAuthenticationInstance(

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

PR Review Comment: https://git.openjdk.org/jdk/pull/14038#discussion_r1197618149
PR Review Comment: https://git.openjdk.org/jdk/pull/14038#discussion_r1197618347
PR Review Comment: https://git.openjdk.org/jdk/pull/14038#discussion_r1197617935


More information about the net-dev mailing list