Why MySQL JDBC Stalls on Java Virtual Threads—and What to Do
The article examines how MySQL’s JDBC driver has been slow to adopt Java’s virtual thread (Loom) support compared with Oracle, PostgreSQL, MariaDB and SQL Server drivers, explains the technical reasons behind the delay, offers a workaround by replacing synchronized with ReentrantLock, and recommends upgrading to the 9.x driver for optimal performance and security.
MySQL’s JDBC driver has been the last major driver to fully support Java’s virtual threads (Project Loom), causing compatibility issues for developers using JDK 21.
Oracle’s JDBC driver (ojdbc11.jar and later) already supports virtual threads, as confirmed on the official Oracle JDBC page
https://www.oracle.com/cn/database/technologies/appdev/jdbc.html. PostgreSQL’s driver also added support early on, and both MariaDB Connector/J and Microsoft SQL Server JDBC driver have been updated to work with Loom.
In contrast, MySQL’s driver lagged behind, only achieving complete virtual‑thread support in the 9.x series after a prolonged delay. The earlier versions used synchronized heavily, which pins virtual threads during JDBC calls and degrades performance.
One practical workaround is to replace the synchronized blocks with ReentrantLock, which eliminates the pinning problem. The change was finally incorporated in the 9.x driver release.
Even though JDK 24 (JEP 491) introduces optimizations for synchronized, upgrading the driver to the 9.x version remains the safest approach.
Beyond virtual‑thread support, upgrading the JDK is advisable because Java 8 stopped receiving public updates in 2019, raising security risks. Moving to a newer Java version improves both performance and security.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Tech Enthusiast
Sharing computer programming language knowledge, focusing on Java fundamentals, data structures, related tools, Spring Cloud, IntelliJ IDEA... Book giveaways, red‑packet rewards and other perks await!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
