一、前言
通过oswego的concurrent-1.3.2.jar包EDU.oswego.cs.dl.util.concurrent.PooledExecutor多线并发任务池执行器定义简单Executor任务调度器,实现简单定时任务及线程数配置进行调度执行任务。
二、代码示例
package net.jforum.util.concurrent;@b@@b@import org.apache.log4j.Logger;@b@@b@import EDU.oswego.cs.dl.util.concurrent.PooledExecutor;@b@@b@/**@b@ * @author Rafael Steil@b@ * @version $Id: Executor.java,v 1.6 2007/03/18 16:56:56 rafaelsteil Exp $@b@ */@b@public class Executor@b@{@b@ private static Logger logger = Logger.getLogger(Executor.class);@b@ private static PooledExecutor executor = new PooledExecutor(5);@b@ @b@ static {@b@ executor.setMinimumPoolSize(2);@b@ executor.setMaximumPoolSize(10);@b@ executor.setKeepAliveTime(1000 * 60 * 10);@b@ }@b@ @b@ public static void execute(Runnable runnable) {@b@ try {@b@ executor.execute(runnable);@b@ }@b@ catch (Exception e) {@b@ logger.error("Exception while running task: " + e, e);@b@ }@b@ }@b@}