Преглед изворни кода

修改线程池使用方式

李进 пре 2 година
родитељ
комит
5bd01b5576

+ 3 - 14
device-api-service/src/main/java/com/xy/service/DeviceCreateIdsServiceImpl.java

@@ -34,7 +34,6 @@ import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.concurrent.CountDownLatch;
 
 import static com.xy.utils.Beans.copy;
 import static com.xy.utils.PlusBeans.toIPage;
@@ -96,19 +95,9 @@ public class DeviceCreateIdsServiceImpl extends ServiceImpl<DeviceCreateIdsMappe
             deviceCreateIdss.add(deviceCreateIdsInfo);
         }
         JList<JList<DeviceCreateIds>> partition = deviceCreateIdss.partition(20);
-        CountDownLatch latch = new CountDownLatch(partition.size());
-        for (JList<DeviceCreateIds> createIds : partition) {
-            executor.execute(() -> {
-                try {
-                    saveBatch(createIds);
-                } catch (Exception e) {
-                    log.error("", e);
-                } finally {
-                    latch.countDown();
-                }
-            });
-        }
-        latch.await();
+        ThreadPoolUtils.Execute execute = ThreadPoolUtils.excPoll(ThreadPoolConfig.DEVICE_CREATE_IDS_SAVE, partition.size());
+        partition.forEach(createIds -> execute.execute(() -> saveBatch(createIds)));
+        execute.end();
         return R.ok();
     }