8dc246e94ff0dd7b108c35d573f05af8bd33f49b.svn-base
3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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();
}
}
}