Virtual Threads
Using ActiveMQ Classic > Configure version 6 Virtual Threads
Virtual Threads support
ActiveMQ Classic support for Virtual Threads is in Technology Preview stage.
Virtual Threads benefits
- Performance on-par with reactive coding approaches
- JDK-based option for peak concurrency performance
- Automatically scales based on need and detected CPU cores
- Less configuration tuning required for administrators
- Easier to code extensions
Virtual Threads warning
JDK 21 support for Virtual Threads can lead to thread pinning in synchronized code blocks, which negates the performance benefit from using virtual threads and may lead to other issues.
Technical factors:
- ActiveMQ currently (6.1.x) uses virtual thread-friendly locking for key data structures in the Queue class
- ActiveMQ currently (6.1.x) uses virtual thread-unfriendly synchronized code blocks in many areas in the client and broker code
- JDK 23 is slated to address the thread pinning in synchronized code blocks
- JDK 25 is the next planned LTS release after JDK 21
- Areas of ActiveMQ source code will need to be modernized to be more virtual thread friendly
- New virtual-thread first implementations may be added using extension points in the broker, vs refactoring the existing stable components
JDK thread pinning improvement: ref: https://mail.openjdk.org/pipermail/loom-dev/2024-May/006632.html
Configuration
To enable Virtual Threads in ActiveMQ Classic 6.x (and higher)
- Checkout activemq source code from git
- Build using JDK 21 (Virtual Thread support will be added automatically)
- Replace the lib/activemq-client_version_.jar with the lib/jdk21/activemq-client-jdk21-_version.jar
-
Edit conf/activemq.xml
<broker … virtualThreadTaskRunner=”true” .. >
-
Run ActiveMQ Classic and confirm with the following log message:
INFO VirtualThreadExecutor initialized name:ActiveMQ BrokerService[localhost] Task
NOTE: The log message may be removed in the future
ActiveMQ Classic Virtual Thread Implementation Progress
The implementation approach is subject to change. Be sure to verify features in Release notes.
User feedback is welcome! Please comment on the JIRAs with questions and comments.
JIRA | Status | Target Version | Completed Version | Feature | Notes |
---|---|---|---|---|---|
AMQ-9394 | PR #1172 | 6.2.0 | Task Runner Factory | Tech Preview support to allow Virtual Thread Executor Service |