自己编译Mysql-Connector-J驱动
最近对虚拟线程比较感兴趣,发现在quarkus中使用@RunOnVirtualThread采用虚拟线程时,使用了Mysql-Connector-J驱动会有Thread-Pinned的问题,原因可以参考 Virtual Threads。 添加Jvm参数 -Djdk.tracePinnedThreads=short 可以辅助发现虚拟线程Pinned的问题。 于是在官方pull里发现了一个已经关闭的提交,这个提交将所有的synchronized关键字都替换成了java.util.concurrent.locks.ReentrantLock,可以参考PR-95
在截图里官方已经接收了这个提交,但是要等到9.0才能发布 
因此只能自己动手编译这个提交了,地址是Mysql-Connector-J#VirtualThread
1. 编译准备
参考官方的编译指南Compiling the Connector/J 需要的准备工作如下,原文:
A Git client, if you want to check out the sources from our GitHub repository (available from http://git-scm.com/downloads).
Apache Ant version 1.10.6 or newer (available from http://ant.apache.org/).
JDK 1.8.x (available from https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html).
The following third-party libraries:
JUnit 5.10 (see installation and download information in the JUnit 5 User Guide). The following JAR files are required:
junit-jupiter-api-5.10.1.jar (available from, for example, https://central.sonatype.com/artifact/org.junit.jupiter/junit-jupiter-api/5.10.1/jar).
junit-jupiter-engine-5.10.1.jar (available from, for example, https://central.sonatype.com/artifact/org.junit.jupiter/junit-jupiter-engine/5.10.1/jar).
junit-platform-commons-1.10.1.jar (available from, for example, https://central.sonatype.com/artifact/org.junit.platform/junit-platform-commons/1.10.1/jar).
junit-platform-engine-1.10.1.jar (available from, for example, https://central.sonatype.com/artifact/org.junit.platform/junit-platform-engine/1.10.1/jar).
junit-platform-launcher-1.10.1.jar (available from, for example, https://central.sonatype.com/artifact/org.junit.platform/junit-platform-launcher/1.10.1/jar).
These additional JAR files, which JUnit 5 depends on:
apiguardian-api-1.1.2.jar (available from, for example, https://central.sonatype.com/artifact/org.apiguardian/apiguardian-api/1.1.2/jar).
opentest4j-1.3.0.jar (available from, for example, https://central.sonatype.com/artifact/org.opentest4j/opentest4j/1.3.0/jar).
Javassist 3.29.2 (javassist-3.29.2-GA.jar, available from, for example, https://central.sonatype.com/artifact/org.javassist/javassist/3.29.2-GA/bundle).
Protocol Buffers Java API 3.25.1 (protobuf-java-3.25.1.jar, available from, for example, https://central.sonatype.com/artifact/com.google.protobuf/protobuf-java/3.25.1/bundle).
C3P0 0.9.5.5 or newer (c3p0-0.9.5.5.jar, available from, for example, https://central.sonatype.com/artifact/com.mchange/c3p0/0.9.5.5/jar).
Simple Logging Facade API 2.0.9 or newer (slf4j-api-2.0.9.jar, available from, for example, https://central.sonatype.com/artifact/org.slf4j/slf4j-api/2.0.9/jar).
Java Hamcrest 2.2 or newer (hamcrest-2.2.jar, available from, for example, https://central.sonatype.com/artifact/org.hamcrest/hamcrest/2.2/jar).
Oracle Cloud Infrastructure SDK for Java (oci-java-sdk-common-3.29.0.jar, available from, for example, https://central.sonatype.com/artifact/com.oracle.oci.sdk/oci-java-sdk-common/3.29.0/jar).
OpenTelemetry API (opentelemetry-api-1.35.0.jar, available from, for example, https://central.sonatype.com/artifact/io.opentelemetry/opentelemetry-api/1.35.0).
OpenTelemetry Context (opentelemetry-context-1.35.0.jar, available from, for example, https://central.sonatype.com/artifact/io.opentelemetry/opentelemetry-context/1.35.0).
Open Test Alliance for the JVM (opentest4j-1.3.0.jar, available from, for example, https://central.sonatype.com/artifact/org.opentest4j/opentest4j/1.3.0).
- git,用来克隆代码
- ant,用来编译代码
- jdk8,编译环境
- 下载需要的第三方依赖,放到项目lib目录下
需要注意限制的版本。 下载依赖是比较麻烦的,需要手动下载,这里提供下载好的版本,已更新: 链接: https://pan.baidu.com/s/1lGDmgI3Mu8lEByyccz20Pw?pwd=tmqm 提取码: tmqm
2. 编译
依赖处理完了以后,需要在项目根目录创建build.properties文件里面配置好lib路径和jdk路径
com.mysql.cj.build.jdk=path_to_jdk_1.8
com.mysql.cj.extra.libs=path_to_folder_for_extra_libraries
修改build.xml文件,将此配置改成 <property name="com.mysql.cj.build.driver.version.snapshot" value="-sf" /> 里面的-sf改成-virtual或者自己想要的,避免和官方的冲突。
配置好后,执行ant build 就可以编译了,编译完成后,在build/classes目录下会生成mysql-connector-j-8.0.32-sf.jar,这个就是编译好的jar包。 
执行ant package 可以在dist目录找到编译好的gz包,解压maven后缀的gz后放到本地maven仓库就可以供自己使用了。