This is an automated email from the ASF dual-hosted git repository.

rzo1 pushed a commit to branch concurency
in repository https://gitbox.apache.org/repos/asf/tomee.git

commit a40d71b727d54566e995c7463c13a81077250ada
Author: Richard Zowalla <[email protected]>
AuthorDate: Thu Apr 2 21:33:35 2026 +0200

    Allow virtual thread factory to work with ForkJoinPool
    
    ForkJoinWorkerThread extends Thread (platform) and cannot be virtual.
    Fall back to a platform ManagedForkJoinWorkerThread instead of throwing
    UnsupportedOperationException. The TCK expects ForkJoinPool to function
    with virtual factories — the worker threads are platform but the pool
    still operates correctly.
    m>
---
 .../openejb/threads/impl/ManagedThreadFactoryImpl.java   |  5 ++---
 .../threads/impl/ManagedThreadFactoryVirtualTest.java    | 16 +++++++++++++---
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git 
a/container/openejb-core/src/main/java/org/apache/openejb/threads/impl/ManagedThreadFactoryImpl.java
 
b/container/openejb-core/src/main/java/org/apache/openejb/threads/impl/ManagedThreadFactoryImpl.java
index 0fb5b6efc2..b92d1c5355 100644
--- 
a/container/openejb-core/src/main/java/org/apache/openejb/threads/impl/ManagedThreadFactoryImpl.java
+++ 
b/container/openejb-core/src/main/java/org/apache/openejb/threads/impl/ManagedThreadFactoryImpl.java
@@ -75,9 +75,8 @@ public class ManagedThreadFactoryImpl implements 
ManagedThreadFactory {
 
     @Override
     public ForkJoinWorkerThread newThread(final ForkJoinPool pool) {
-        if (virtual) {
-            throw new UnsupportedOperationException("Virtual thread factory 
does not support ForkJoinPool threads");
-        }
+        // ForkJoinWorkerThread extends Thread (platform) — cannot be virtual.
+        // For virtual factories, fall back to a platform ForkJoinWorkerThread.
         return new ManagedForkJoinWorkerThread(pool, priority, contextService);
     }
 
diff --git 
a/container/openejb-core/src/test/java/org/apache/openejb/threads/impl/ManagedThreadFactoryVirtualTest.java
 
b/container/openejb-core/src/test/java/org/apache/openejb/threads/impl/ManagedThreadFactoryVirtualTest.java
index 0729d9c836..2be1789cd2 100644
--- 
a/container/openejb-core/src/test/java/org/apache/openejb/threads/impl/ManagedThreadFactoryVirtualTest.java
+++ 
b/container/openejb-core/src/test/java/org/apache/openejb/threads/impl/ManagedThreadFactoryVirtualTest.java
@@ -29,6 +29,7 @@ import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ForkJoinPool;
 import java.util.concurrent.TimeUnit;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
@@ -91,14 +92,23 @@ public class ManagedThreadFactoryVirtualTest {
         }
     }
 
-    @Test(expected = UnsupportedOperationException.class)
-    public void virtualFactoryRejectsForkJoinPool() {
+    @Test
+    public void virtualFactoryFallsBackToPlatformForForkJoinPool() {
         Assume.assumeTrue("Virtual threads require Java 21+", 
VirtualThreadHelper.isSupported());
 
         final ContextServiceImpl contextService = 
ContextServiceImplFactory.newDefaultContextService();
         final ManagedThreadFactoryImpl factory = new 
ManagedThreadFactoryImpl("test-vt-", null, contextService, true);
 
-        factory.newThread(new ForkJoinPool());
+        // ForkJoinWorkerThread cannot be virtual — should fall back to 
platform thread
+        final ForkJoinPool pool = new ForkJoinPool(1, factory, null, false);
+        try {
+            final java.util.concurrent.Future<String> result = pool.submit(() 
-> "ok");
+            assertEquals("ForkJoinPool should work with virtual factory", 
"ok", result.get(5, java.util.concurrent.TimeUnit.SECONDS));
+        } catch (final Exception e) {
+            fail("ForkJoinPool with virtual factory should not throw: " + e);
+        } finally {
+            pool.shutdown();
+        }
     }
 
     @Test

Reply via email to