Chinaunix首页 | 论坛 | 博客
  • 博客访问: 189359
  • 博文数量: 92
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1413
  • 用 户 组: 普通用户
  • 注册时间: 2013-02-04 21:12
文章分类
文章存档

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;
	}
		

}
阅读(330) | 评论(0) | 转发(0) |
0

上一篇:C 怎么获取cookie

下一篇:绕过waf写入

给主人留下些什么吧!~~