javax.imageio.ImageIO ThreadLocal use

Duncan Gittins duncan.gittins at gmail.com
Tue May 9 17:46:38 UTC 2023


Hi

I've been testing one of my applications in JDK20 preview mode on Windows -
conversion to use virtual threads has been very easy and works well - many
thanks to everyone involved. One bug I found turned out to be in my own
codebase.

I happened to be stripping out all my ThreadLocal code recently, and so
decided to check this work by adding "allowSetThreadLocals(false)" onto all
virtual thread builders to disable ThreadLocal use.

This is when I discover that javax.imageio.ImageIO initialisation depends
on ThreadLocal. The stack trace points at IIORegistry initialisation:

       at
java.desktop/javax.imageio.spi.IIORegistry.getDefaultInstance(Unknown
Source)
       at java.desktop/javax.imageio.ImageIO.<clinit>(Unknown Source)

Obviously I've got an easy workaround - "allowSetThreadLocals(true)" puts
it back to working reliably, plus it appears that using some call like
"ImageIO.getCache()" in main() also reduces likelyhood of this exception as
it initialises enough of ImageIO before use in multiple threads.

Are there any plans to unpick the ThreadLocal dependency
inside javax.imageio.ImageIO for future JDK work?

Kind regards

Duncan Gittins
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20230509/c0819491/attachment.htm>


More information about the loom-dev mailing list