2013年(92)
分类: 信息化
2013-03-07 05:31:27
[代码] [Java]代码 public interface ExecutorPool { void execute(Runnable command); Future submit(Runnable task); Future submit(Callable task); } public class AppExecutorP implements ExecutorPool { //闲暇时需求坚持的线程个数 private int corePoolSize = 10; //线程池中答应的最大线程数 private int maximumPoolSize = 50; //闲暇线程数超越 corePoolSize ,坚持 keepAliveTime 时长后,线程数降到 corePoolSize 个 private long keepAliveTime = 20; //keepAliveTime 的时刻单位 private TimeUnit timeUnit = TimeUnit.SECONDS; //未被执行前的目标,进入该行列 BlockingQueue queue = new LinkedBlockingQueue(); // private ThreadPoolExecutor poolExecutor; public AppExecutorPool() { this.poolExecutor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, timeUnit, queue); } public void execute(Runnable command) { this.poolExecutor.execute(command); } public Future submit(Runnable task) { return this.poolExecutor.submit(task); } public Future submit(Runnable task, T result) { return this.poolExecutor.submit(task, result); } public Future submit(Callable task) { return this.poolExecutor.submit(task); } public int getCorePoolSize() { return corePoolSize; } public void setCorePoolSize(int corePoolSize) { this.poolExecutor.setCorePoolSize(corePoolSize); this.corePoolSize = corePoolSize; } public int getMaximumPoolSize() { return maximumPoolSize; } public void setMaximumPoolSize(int maximumPoolSize) { this.poolExecutor.setMaximumPoolSize(maximumPoolSize); this.maximumPoolSize = maximumPoolSize; } public long getKeepAliveTime() { return keepAliveTime; } public void setKeepAliveTime(long keepAliveTime) { this.poolExecutor.setKeepAliveTime(keepAliveTime, timeUnit); this.keepAliveTime = keepAliveTime; } public TimeUnit getTimeUnit() { return timeUnit; } public void setTimeUnit(TimeUnit timeUnit) { this.timeUnit = timeUnit; } public BlockingQueue getQueue() { return queue; } public void setQueue(BlockingQueue queue) { this.queue = queue; } }