스 레 드 탱크 에 대한 코드 는 자주 사 용 됩 니 다.

1465 단어 자바인터넷
package com.tuan.partner.client.impl;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import org.apache.commons.logging.Log;

import com.tuan.partner.client.util.WoWoLogger;

public class ThreadPoolManager {
private static Log logger = WoWoLogger.getLog(ThreadPoolManager.class);

private static final int CORE_POOL_SIZE = 20;

private static final int MAX_POOL_SIZE = 50;

private static final long KEEP_ALIVE_TIME = 0;

private static final int WORK_QUEUE_SIZE = 1000;

private static ThreadPoolManager threadPoolManager = new ThreadPoolManager();

final ThreadPoolExecutor threadPool = new ThreadPoolExecutor(
CORE_POOL_SIZE, MAX_POOL_SIZE, KEEP_ALIVE_TIME, TimeUnit.SECONDS,
new ArrayBlockingQueue(WORK_QUEUE_SIZE),
new ThreadPoolExecutor.CallerRunsPolicy());

public static ThreadPoolManager newInstance() {
return threadPoolManager;
}

public void execute(Runnable command) {
logger.debug("execute thread");
this.threadPool.execute(command);
}

public BlockingQueue getQueue() {
return this.threadPool.getQueue();
}

public ThreadPoolExecutor getPool() {
return this.threadPool;
}
}

좋은 웹페이지 즐겨찾기