17db20e2e1d0340cd61fe4a3933733bd2274ee62.svn-base
2.8 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
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();
}
}
}