fuyou001 commented on code in PR #5887:
URL: https://github.com/apache/rocketmq/pull/5887#discussion_r1097207514


##########
store/src/main/java/org/apache/rocketmq/store/DefaultMessageStore.java:
##########
@@ -2743,6 +2852,269 @@ public String getServiceName() {
 
     }
 
+    class MainBatchDispatchRequestService extends ServiceThread {
+
+        private final ExecutorService batchDispatchRequestExecutor;
+
+        public MainBatchDispatchRequestService() {
+            batchDispatchRequestExecutor = new ThreadPoolExecutor(
+                    
DefaultMessageStore.this.getBrokerConfig().getBatchDispatchRequestThreadPoolNums(),
+                    
DefaultMessageStore.this.getBrokerConfig().getBatchDispatchRequestThreadPoolNums(),
+                    1000 * 60,
+                    TimeUnit.MICROSECONDS,
+                    new LinkedBlockingQueue<>(4096),
+                    new 
ThreadFactoryImpl("BatchDispatchRequestServiceThread_"),
+                    new RejectedExecutionHandler() {
+                        @Override
+                        public void rejectedExecution(Runnable r, 
ThreadPoolExecutor executor) {
+                            try {
+                                LOGGER.warn("Task {} is blocking put into the 
workQueue", r);
+                                executor.getQueue().put(r);
+                            } catch (InterruptedException e) {
+                                LOGGER.error("Task {} failed to put into the 
workQueue", r);
+                            }
+                        }
+                    });
+        }
+
+        private void pollBatchDispatchRequest() {
+            if (!batchDispatchRequestQueue.isEmpty()) {
+                BatchDispatchRequest task = batchDispatchRequestQueue.poll();
+                batchDispatchRequestExecutor.execute(() -> {
+                    ByteBuffer tmpByteBuffer = task.byteBuffer.duplicate();

Review Comment:
   Give you the demo, you run it ,and  think about different
   
   ```
   package org.apache.rocketmq.test;
   
   import java.util.concurrent.ExecutorService;
   import java.util.concurrent.LinkedBlockingQueue;
   import java.util.concurrent.ThreadPoolExecutor;
   import java.util.concurrent.TimeUnit;
   
   import org.apache.rocketmq.common.ThreadFactoryImpl;
   
   public class Test {
   
       
       public static void main(String[] args) {
           good(false);
           good(true);
           bad(false);
           bad(true);
   
       }
   
       public static void good(boolean throwException) {
           ExecutorService executor = new ThreadPoolExecutor(1, 2,
                   1000 * 60,
                   TimeUnit.MICROSECONDS,
                   new LinkedBlockingQueue<>(2),
                   new 
ThreadFactoryImpl("GoodBatchDispatchRequestServiceThread_"),
                   new ThreadPoolExecutor.CallerRunsPolicy());
           for (int i = 0; i < 15; i++) {
               executor.execute(() -> {
                   try {
                       TimeUnit.SECONDS.sleep(1);
                       System.out.println("ThreadName:" + 
Thread.currentThread().getName());
                       if (throwException)
                           throw new RuntimeException("test");
                   } catch (Exception e) {
   
                   }
               });
           }
   
           for (int i = 0; i < 5; i++) {
               executor.execute(() -> {
                   System.out.println("testbb");
               });
           }
           System.out.println("test-cccccccc");
   
       }
   
       public static void bad(boolean throwException) {
           ExecutorService executor = new ThreadPoolExecutor(1, 2,
                   1000 * 60,
                   TimeUnit.MICROSECONDS,
                   new LinkedBlockingQueue<>(2),
                   new 
ThreadFactoryImpl("BadBatchDispatchRequestServiceThread_"));
           for (int i = 0; i < 15; i++) {
               executor.execute(() -> {
                   try {
                       TimeUnit.SECONDS.sleep(1);
                   } catch (InterruptedException e) {
   
                   }
                   System.out.println("ThreadName:" + 
Thread.currentThread().getName());
                   if (throwException)
                       throw new RuntimeException("test");
               });
           }
   
           for (int i = 0; i < 5; i++) {
               executor.execute(() -> {
                   System.out.println("testbb");
               });
           }
           System.out.println("test-cccccccc");
   
       }
   }
   ```
   



-- 
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]

Reply via email to