Should AbstractInterruptibleChannel.close() still use a synchronized block?
Alan Bateman
Alan.Bateman at oracle.com
Wed Oct 18 13:32:12 UTC 2023
On 18/10/2023 14:03, Mark Rotteveel wrote:
> Prompted by this Stack Overflow question
> [https://stackoverflow.com/q/77315894/466862], I'm wondering if the
> use of a synchronized block in AbstractInterruptibleChannel.close()
> as-of Java 21 is correct, and shouldn't be replaced with a
> ReentrantLock or something else.
>
> As shown in the question, closing of a channel derived from
> AbstractInterruptibleChannel can cause pinning of virtual threads.
We decided it wasn't worth doing because it's rare to set SO_LINGER.
Temporary pinning due to contention on the readLock or writeLock when
closing is okay.
In the mean-time, we are working to remove restriction on synchronized
blocks. We hope to have something in the loom repo soon.
-Alan
More information about the nio-dev
mailing list