Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
[email protected] web/email now available. Want one? Go here.
Cannot use outlook/hotmail/live here to register as they blocking our mail servers. #microsoftdeez
Obey the Epel!

Paste

Pasted as Java by glen ( 1 year ago )
@Test
void ThreadPoolExecutor의_maxPool은_queue의_작업이_전부_차면_생성된다() throws InterruptedException {
    // 최대 7개의 스레드풀, 나머지 3개의 작업은 대기
    // 하지만 예측과 다르게 큐 작업이 우선된다.
    // 큐 작업이 꽉 차면 그제서야 새로운 스레드가 생성된다.
    ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
        2,
        7,
        0,
        TimeUnit.MILLISECONDS,
        new LinkedBlockingQueue<>(3)
    );
    threadPoolExecutor.execute(logWithSleep("core job")); // core thread
    threadPoolExecutor.execute(logWithSleep("core job")); // core thread

    threadPoolExecutor.execute(logWithSleep("max pool job")); // queue
    threadPoolExecutor.execute(logWithSleep("max pool job")); // queue
    threadPoolExecutor.execute(logWithSleep("max pool job")); // queue

    threadPoolExecutor.execute(logWithSleep("queue job")); // new thread
    threadPoolExecutor.execute(logWithSleep("queue job")); // new thread
    threadPoolExecutor.execute(logWithSleep("queue job")); // new thread
    threadPoolExecutor.execute(logWithSleep("queue job")); // new thread
    threadPoolExecutor.execute(logWithSleep("queue job")); // new thread

    Thread.sleep(1000);
}

 

Revise this Paste

Your Name: Code Language: