Copilot commented on code in PR #8023:
URL: https://github.com/apache/incubator-seata/pull/8023#discussion_r3015632589


##########
seata-spring-boot-starter/src/main/java/org/apache/seata/spring/boot/autoconfigure/SeataSagaAutoConfiguration.java:
##########
@@ -118,20 +118,13 @@ public ThreadPoolExecutor sagaAsyncThreadPoolExecutor(
                 SagaAsyncThreadPoolProperties properties,
                 @Qualifier(SAGA_REJECTED_EXECUTION_HANDLER_BEAN_NAME)
                         RejectedExecutionHandler rejectedExecutionHandler) {
-            ThreadPoolExecutorFactoryBean threadFactory = new 
ThreadPoolExecutorFactoryBean();
-            
threadFactory.setBeanName("sagaStateMachineThreadPoolExecutorFactory");
-            threadFactory.setThreadNamePrefix("sagaAsyncExecute-");
-            threadFactory.setCorePoolSize(properties.getCorePoolSize());
-            threadFactory.setMaxPoolSize(properties.getMaxPoolSize());
-            threadFactory.setKeepAliveSeconds(properties.getKeepAliveTime());
-
-            return new ThreadPoolExecutor(
+            return ThreadPoolExecutorFactory.newThreadPoolExecutor(
+                    "sagaAsyncExecute",
                     properties.getCorePoolSize(),
                     properties.getMaxPoolSize(),
                     properties.getKeepAliveTime(),
                     TimeUnit.SECONDS,
                     new LinkedBlockingQueue<>(),
-                    threadFactory,
                     rejectedExecutionHandler);
         }

Review Comment:
   Switching from Spring's `ThreadPoolExecutorFactoryBean` to 
`ThreadPoolExecutorFactory` changes thread creation semantics (notably daemon 
status and thread naming). `ThreadPoolExecutorFactory` defaults to daemon 
threads, whereas Spring's default thread factory produces non-daemon threads 
unless explicitly configured. Please confirm this behavioral change is intended 
for saga async execution; otherwise, consider making daemon/naming configurable 
or explicitly preserving the previous behavior when running in platform-thread 
mode.



##########
threadpool-loom/src/test/java/org/apache/seata/common/thread/VirtualThreadPoolProviderTest.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.seata.common.thread;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+/**
+ * Tests for loom-backed thread pool providers.
+ */
+public class VirtualThreadPoolProviderTest {
+
+    @AfterEach
+    public void tearDown() {
+        ThreadPoolRuntimeEnvironment.reset();
+    }
+
+    @Test
+    public void testVirtualThreadPoolExecutorKeepsConfiguredBounds() {
+        ThreadPoolRuntimeEnvironment.setThreadPoolTypeSupplier(() -> 
"virtual");
+        ThreadPoolRuntimeEnvironment.setJdkFeatureSupplier(() -> 21);
+        LinkedBlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<>();
+
+        ThreadPoolExecutor executor =
+                ThreadPoolExecutorFactory.newThreadPoolExecutor("virtualPool", 
1, 2, 60, TimeUnit.SECONDS, workQueue);
+        try {
+            Thread thread = executor.getThreadFactory().newThread(() -> {});
+
+            assertThat(executor).isInstanceOf(VirtualThreadPoolExecutor.class);
+            assertThat(executor.getMaximumPoolSize()).isEqualTo(2);
+            
assertThat(executor.getKeepAliveTime(TimeUnit.SECONDS)).isEqualTo(60);
+            assertThat(executor.getQueue()).isSameAs(workQueue);
+            assertThat(thread.isVirtual()).isTrue();

Review Comment:
   This test asserts that the virtual-thread-backed executor keeps the 
configured `maximumPoolSize` and `keepAliveTime`. That expectation conflicts 
with the PR description stating virtual mode ignores those bounds and uses an 
effectively unbounded executor shape. Once the virtual executor behavior is 
finalized, please adjust the assertions here to match the intended contract to 
avoid locking in the wrong semantics.



##########
threadpool-loom/src/main/java/org/apache/seata/common/thread/VirtualThreadPoolExecutor.java:
##########
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.seata.common.thread;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.RejectedExecutionHandler;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Virtual-thread-backed thread pool implementation.
+ */
+public class VirtualThreadPoolExecutor extends ThreadPoolExecutor {
+
+    public VirtualThreadPoolExecutor(
+            String threadPrefix,
+            int corePoolSize,
+            int maximumPoolSize,
+            long keepAliveTime,
+            TimeUnit unit,
+            BlockingQueue<Runnable> workQueue,
+            boolean daemon,
+            RejectedExecutionHandler rejectedHandler) {
+        super(
+                corePoolSize,
+                maximumPoolSize,
+                keepAliveTime,
+                unit,
+                workQueue,
+                VirtualThreadFactoryHelper.newThreadFactory(threadPrefix, 
daemon),
+                rejectedHandler);

Review Comment:
   The implementation of the virtual-thread executor currently preserves the 
configured `maximumPoolSize`, `keepAliveTime`, and `workQueue`. This 
contradicts the PR description (and example) that virtual mode should ignore 
`maximumPoolSize`/`keepAliveTime` and use an unbounded max with a 
`SynchronousQueue` (thread-per-task style) to avoid artificial 
throttling/queuing on virtual threads. Align the virtual executor behavior with 
the documented rules (and update dependent tests accordingly), or update the PR 
description if the intent is to keep bounded/queued semantics for virtual 
threads.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to