PlanThreadPoolTask.java 2.8 KB
package com.espeed.plan;

import java.io.Serializable;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import com.espeed.yxy.pojo.YxyMarketingPlan;
import com.espeed.yxy.pojo.YxySendSmtpInfo;
import com.espeed.yxy.service.YxyMarketingPlanService;
import com.espeed.yxy.service.YxySendMailService;
/**
 * 程序名称:    	EspeedMail_时速邮箱
 * 程序版本:    	V1.0
 * 作    者:    	深圳市科飞时速网络技术有限公司(0755-88843776)
 * 版权所有:    	深圳市科飞时速网络技术有限公司
 * 技术支持:    	Tech@21gmail.com
 * 单元名称:    	手动收邮件后台线程池
 * 开始时间:    	2013.09.02
 * 程 序 员:    	谢勇
 * 最后修改:    
 * 备    注:		如需修改请通知程序员    
 */
public class PlanThreadPoolTask implements Runnable,Serializable{

	private static final long serialVersionUID = 0;	
	private static ThreadPoolExecutor threadPool=null;
	private static PlanThreadPoolTask threadpooltask=null;
	
	private YxyMarketingPlanService planservice;//计划service
	private YxySendMailService mailservice;//邮件service
	private YxySendSmtpInfo smtpinfo;//smtp集合
	private YxyMarketingPlan planinfo;//计划集合
	//无参构造方法
	PlanThreadPoolTask(){
	}
	//传递参数
	PlanThreadPoolTask(YxyMarketingPlanService planservice,YxySendMailService mailservice,YxySendSmtpInfo smtpinfo,YxyMarketingPlan planinfo){
		this.planservice=planservice;
		this.smtpinfo=smtpinfo;
		this.smtpinfo=smtpinfo;
		this.mailservice=mailservice;
	}
	
	//单例方法
	public static PlanThreadPoolTask getMethodInstance(){
		if(threadpooltask==null){
			//System.out.println("创建新对像了");
			threadpooltask=new PlanThreadPoolTask();
		}
		return threadpooltask;
	}
	
	//线程池
	public static ThreadPoolExecutor getInstance(int bigThread){
		if(threadPool==null){
			threadPool=new ThreadPoolExecutor(bigThread,bigThread+2,100,
    				TimeUnit.SECONDS,new ArrayBlockingQueue<Runnable>(4000),
    				new ThreadPoolExecutor.DiscardOldestPolicy());
		}
    	return threadPool;
    }
	//线程池运行方法
	public synchronized void getResult(YxyMarketingPlanService planservice,YxySendMailService mailservice,List<YxySendSmtpInfo> smtplist,List<YxyMarketingPlan> planlist) {
		threadPool=getInstance(10);
		//计划加入线程池
		for(int j=0;j<planlist.size();j++){
			try {
				threadPool.execute(new PlanThreadPoolTask(planservice,mailservice,smtplist.get(j),planlist.get(j)));
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	//获取线程量
	public int getThreadNum(){
		if(threadPool==null){
			return -1;
		}else{
			return threadPool.getActiveCount();
		}
	}
	
	//执行计划
	public void run(){
		try {
			
			
			
		} catch (Exception e) {
			e.printStackTrace();
		} 
	}

}