8dc246e94ff0dd7b108c35d573f05af8bd33f49b.svn-base 3.2 KB
package com.espeed.yxy.mail;

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.YxySendMailMaster;
import com.espeed.yxy.pojo.YxySendSmtpInfo;
import com.espeed.yxy.pojo.YxySmtpSendSet;
import com.espeed.yxy.pojo.YxySmtpSuffixSet;
import com.espeed.yxy.service.YxySendMailService;
import com.espeed.yxy.tool.GetRondom;
/**
 * 程序名称:    	EspeedMail_时速邮箱
 * 程序版本:    	V1.0
 * 作    者:    	深圳市科飞时速网络技术有限公司(0755-88843776)
 * 版权所有:    	深圳市科飞时速网络技术有限公司
 * 技术支持:    	Tech@21gmail.com
 * 单元名称:     发送邮件线程池创建(营销游)
 * 开始时间:    	2013.12.09
 * 程 序 员:    	谢勇
 * 最后修改:    
 * 备    注:		如需修改请通知程序员    
 */
public class YxythreadWork implements Runnable,Serializable{
    private static ThreadPoolExecutor threadPool=null;    
    private static YxythreadWork yxythreadwork=null;   
    private YxySendMailService YxySendMailService;//service
    private YxySendSmtpInfo SmtpInfo;//smtp服务器
    private YxySendMailMaster mailinfo;//邮件信息
    private List<YxySmtpSuffixSet> smtpsuffixsetList;//后缀信息
    /**无参构造方法*/
    YxythreadWork(){
    	
    }
    /**参数传递*/
    YxythreadWork(YxySendMailService YxySendMailService,YxySendSmtpInfo SmtpInfo,YxySendMailMaster mailinfo,List<YxySmtpSuffixSet> smtpsuffixsetList){
    	this.YxySendMailService=YxySendMailService;
    	this.SmtpInfo=SmtpInfo;
    	this.mailinfo=mailinfo;
    	this.smtpsuffixsetList=smtpsuffixsetList;
    }
 
    /**单例方法*/
    public static YxythreadWork getMethodInstance(){
    	if(yxythreadwork==null){
    		yxythreadwork=new YxythreadWork();
    	}
    	return yxythreadwork;
    }
    
    /**线程池*/
    public static ThreadPoolExecutor getInstance(int bigThread){
    		threadPool=new ThreadPoolExecutor(bigThread,bigThread+2,100,
    				TimeUnit.SECONDS,new ArrayBlockingQueue(4000),
    				new ThreadPoolExecutor.DiscardOldestPolicy());
    	return threadPool;
    }
    
    /**线程池任务*/
	public void getResult(YxySendMailService YxySendMailService,List<YxySendSmtpInfo> SmtpInfoList,List<YxySendMailMaster> mailinfoList,List<YxySmtpSuffixSet> smtpsuffixsetList,int bigThread) {
		threadPool=getInstance(bigThread);
		for(int i=0;i<mailinfoList.size();i++){
			try {
				threadPool.execute(new YxythreadWork(YxySendMailService,SmtpInfoList.get(i),mailinfoList.get(i),smtpsuffixsetList));	

			} catch (Exception e) {
				System.out.println("加入新线程失败!");
			}
		}
		
	}
	
	//获取线程量
	public int getThreadNum(){
		return threadPool.getActiveCount();
	}
	
    /**线程处理方法*/
    public void run(){
    	try {
    		//调用发邮件方法
    		//YxysendMethod.sendMethodImpl(YxySendMailService, SmtpInfo,mailinfo,smtpsuffixsetList);
		} catch (Exception e) {
			System.out.println("线程调用方法有问题!");
		}
	 
	   //此线程任务完成后重新获取线程池的数量
	   synchronized (this) {  
		   threadPool.shutdown();
  	 }
   }
}