tair.dev
← Blog

pgjdbc gets ready for virtual threads

· #java#concurrency#loom#postgres

I somehow managed to miss the release of the PostgreSQL JDBC driver 42.6.0. This release contains a refactoring of the code for Project Loom — i.e. Java Virtual Threads.

As is known, the Achilles’ heel of virtual threads is so-called thread-pinning: a virtual thread blocked inside a synchronized block (for now) cannot be unmounted from the underlying OS thread. That hurts the scalability of code with frequent synchronized blocks.

This limitation applied to pgjdbc in particular. The situation was made trickier by the fact that the pgjdbc maintainers are fairly conservative and don’t like chasing shiny new things without good reason (for contrast, the mariadb/oracle/mssql drivers improved Loom compatibility more promptly).

But things seem to have changed once the Java developers announced that Virtual Threads would be finalized in the upcoming Java 21 LTS release. That turned out to be reason enough to rework pgjdbc: all synchronized blocks around IO operations were replaced with code using ReentrantLock, as the platform recommends.

And so the Java community took another step closer to the long-held dream of simple, scalable code with “green” threads.


Originally posted on my Telegram channel Ламповый ТехДир.