본문 바로가기

Java/concurrent

[Java-concurrent] CompletableFuture 톺아보기 - OT

Async Pool fundamental


private static final boolean USE_COMMON_POOL = (ForkJoinPool.getCommonPoolParallelism() > 1);

/**
 * Default executor -- ForkJoinPool.commonPool() unless it cannot
 * support parallelism.
 */
private static final Executor ASYNC_POOL = USE_COMMON_POOL ?
    ForkJoinPool.commonPool() : new ThreadPerTaskExecutor();

static Executor screenExecutor(Executor e) {
    if (!USE_COMMON_POOL && e == ForkJoinPool.commonPool())
        return ASYNC_POOL;
    if (e == null) throw new NullPointerException();
    return e;
}

시스템이 병렬을 지원하지 않는데(USE_COMMON_POOL = false)

Executor가 CommonPool로 들어오면(e == ForkJoinPool.commonPool())

ASYNC_POOL을 통해 new ThreadPerTaskExecutor()가 실행

Async 메서드


1️⃣ 비동기실행 메서드 xAsync

  • runAsync, supplyAsync, completeAsync, handleAsync
    • parameter
      • Runnable
      • Runnable, Excecutor

2️⃣ 비동기 Stage asyncXStage

  • asyncRunStage, asyncSupplyStage,
    • CompletableFuture 생성
    • executor로 Runnable 실행
      d: CompletableFuture, f: Runnable
e.execute(new AsyncRun(d, f)));
e.execute(new AsyncSupply(d, f)));

3️⃣ Async 실행 Form AsyncX

  • AsyncSupply, AsyncRun

 

 

'Java > concurrent' 카테고리의 다른 글

[Java-concurrent] CompletableFuture 톺아보기 - AsyncSupply  (0) 2024.03.19