Replace synchronized blocks with ReentrantLock; adopt virtual threads#718
Open
moqui-industrial wants to merge 1 commit into
Open
Replace synchronized blocks with ReentrantLock; adopt virtual threads#718moqui-industrial wants to merge 1 commit into
moqui-industrial wants to merge 1 commit into
Conversation
…ual threads All worker and job pools now use Thread.ofVirtual() via VirtualThreadExecutorService (replaces WorkerThreadPoolExecutor / WorkerThreadFactory / JobThreadFactory). allowCoreThreadTimeOut(true) prevents pooling so each task gets a fresh virtual thread. synchronized methods across CacheFacadeImpl, ContextJavaUtil (EntityRecordLock, ArtifactBinInfo), EntityDbMeta, EntityFacadeImpl, EntityFacadeImpl (statementExecutor), ExecutionContextFactoryImpl (compileGroovy, webappInfo), GroovyScriptRunner, MCache, MCacheManager, MEntry, MNode, ResourceFacadeImpl, ScheduledJobRunner, ScreenFacadeImpl, ScreenTestImpl, TransactionFacadeImpl, and ElasticRequestLogFilter are replaced with ReentrantLock to prevent carrier-thread pinning under virtual threads. Thread.start(...) / new Thread(...).start() replaced with Thread.ofVirtual().name(...).start() where applicable (XslFoTransform, RequireNewTx, EcfiReInit, ScreenTestRender). Adds VirtualThreadMoquiSuite and VirtualThreadStressTests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR makes the framework compatible with Java 21 virtual threads by eliminating carrier-thread pinning caused by
synchronizedblocks.Changes
synchronizedmethods and blocks withReentrantLockthroughout the framework (ExecutionContextFactoryImpl, EntityFacadeImpl, ServiceFacadeImpl, CacheFacadeImpl, and others)VirtualThreadExecutorService— a thin wrapper overExecutors.newVirtualThreadPerTaskExecutor()wired into the service facadeVirtualThreadMoquiSuiteandVirtualThreadStressTeststo verify correctness and throughput under concurrent virtual-thread loadWhy
Java 21 virtual threads are pinned to their carrier OS thread whenever they block inside a
synchronizedblock or method. On a busy Moqui instance this causes carrier starvation, negating the benefits of virtual threads. UsingReentrantLockreleases the carrier on block, allowing the JVM to schedule other virtual threads freely.Test results
VirtualThreadStressTests(4 tests) all pass. Existing test suite unaffected.