Browse Source

feat:修改线程池中线程数

release_toaliyun_real
xmzhao71 2 years ago
parent
commit
3cd88443b0
2 changed files with 4 additions and 4 deletions
  1. +1
    -1
      mallinkService/src/main/java/com/iformall/service/thread/CompletableFutureWithExecutor.java
  2. +3
    -3
      mallinkService/src/main/java/com/iformall/service/thread/ThreadPoolService.java

+ 1
- 1
mallinkService/src/main/java/com/iformall/service/thread/CompletableFutureWithExecutor.java View File

@@ -27,7 +27,7 @@ public class CompletableFutureWithExecutor {
future = this; future = this;
} }


public static <U> CompletableFuture<U> supplyAsync(Supplier<U> supplier) {
public static <U> CompletableFuture<U> supplyAsync(Supplier<U> supplier) {
return CompletableFuture.supplyAsync(supplier, future.threadPoolService.getExecutorService(CORE_SIZE, MAX_SIZE)); return CompletableFuture.supplyAsync(supplier, future.threadPoolService.getExecutorService(CORE_SIZE, MAX_SIZE));
} }




+ 3
- 3
mallinkService/src/main/java/com/iformall/service/thread/ThreadPoolService.java View File

@@ -14,8 +14,8 @@ import java.util.concurrent.atomic.AtomicInteger;
@Component @Component
public class ThreadPoolService { public class ThreadPoolService {


private final Integer coreSize = 2;
private final Integer maxSize = 2 * Runtime.getRuntime().availableProcessors();
private static final Integer CORE_SIZE = 2;
private static Integer MAX_SIZE = 2 * Runtime.getRuntime().availableProcessors();
private final String prefix = "fm-thread-pool-"; private final String prefix = "fm-thread-pool-";


private final AtomicInteger nextId = new AtomicInteger(); private final AtomicInteger nextId = new AtomicInteger();
@@ -26,7 +26,7 @@ public class ThreadPoolService {
private volatile ThreadPoolExecutor service; private volatile ThreadPoolExecutor service;


private ThreadPoolService() { private ThreadPoolService() {
getExecutorService(Integer.MAX_VALUE, Integer.MAX_VALUE);
getExecutorService(CORE_SIZE, MAX_SIZE);
} }


/** /**


Loading…
Cancel
Save