package com.gctx.schedule;
import java.util.ArrayList;
import java.util.List;
import com.gctx.business.interfaces.IGreetExpService;
import com.gctx.business.interfaces.IGreetPlanService;
import com.gctx.framework.logs.Logit;
import com.zr.pojo.aged.home.ZaghGreetExp;
import com.zr.pojo.aged.home.ZaghGreetPlanExp;
/*********************************************************
* 生成短信任务主线程
*@author zhanjunwei
*
*@since Nov 14, 2011 3:42:12 PM
*
*********************************************************/
public class CreateMessageRootThread implements Runnable {
private Long defPollingTime = 30 * 60 * 1000L;//默认轮询时间
private Integer defMaxvectorLength = 1000;//默认队列大小
private Integer defMaxvectorNum = 10; //默认队列个数
/**---
* 新加
*/
private IGreetExpService igreetexpservice;
private IGreetPlanService igreetplanservice;
public IGreetPlanService getIgreetplanservice() {
return igreetplanservice;
}
public void setIgreetplanservice(IGreetPlanService igreetplanservice) {
this.igreetplanservice = igreetplanservice;
}
public IGreetExpService getIgreetexpservice() {
return igreetexpservice;
}
public void setIgreetexpservice(IGreetExpService igreetexpservice) {
this.igreetexpservice = igreetexpservice;
}
/**---
* 新加
*/
CreateMessageSlaveThread[] createMessageSlaveThreads;
/**
* 构造函数
* @param pollingTime
* @param maxvectorLength
* @param maxvectorNum
*/
public CreateMessageRootThread(Long pollingTime, Integer maxvectorLength,
Integer maxvectorNum ){
this.defPollingTime = pollingTime;
this.defMaxvectorLength = maxvectorLength;
this.defMaxvectorNum = maxvectorNum;
init();
}
public void init() {
createMessageSlaveThreads = new CreateMessageSlaveThread[this.defMaxvectorNum];
for (int i = 0; i < this.defMaxvectorNum; i++) {
CreateMessageSlaveThread createMessageSlaveThread = new CreateMessageSlaveThread();
this.createMessageSlaveThreads[i] = createMessageSlaveThread;
createMessageSlaveThread.start();
}
}
public List<Object> polling() {
//轮询待生成报告列表
// List<Object> list = new ArrayList<Object>();
//
// list.add("111");
// list.add("112");
// list.add("113");
// list.add("114");
List<Object> list = new ArrayList<Object>();
/**
* 获取无计划的列表
*/
List<ZaghGreetExp> greetExpList=igreetexpservice.getAllSendRecordList();
for (ZaghGreetExp zaghGreetExp : greetExpList) {
list.add(zaghGreetExp);
}
System.out.println(greetExpList.size());
List<ZaghGreetPlanExp> greetPlanList=igreetplanservice.getSendGreetPlanList();
for (ZaghGreetPlanExp zaghGreetPlanExp : greetPlanList) {
list.add(zaghGreetPlanExp);
}
System.out.println("--------------------------------------");
return list;
}
public void distributeTask() {
//分发任务
List<Object> list = polling();
if (list == null) {
return;
}
for (Object geu : list) {
int vectorNum = getModuleValue(geu.toString());
if (this.createMessageSlaveThreads[vectorNum].getVectorCount() < defMaxvectorLength) {
this.createMessageSlaveThreads[vectorNum].addTask(geu);
}
}
}
private int getModuleValue(String key) {
long hashCode = (long) key.hashCode();
if (hashCode < 0)
hashCode = -hashCode;
return (int) hashCode % defMaxvectorNum;
}
public void run() {
while (true) {
try {
Logit.debugLog("CreateReportMailRootThread is runing");
distributeTask();
Thread.sleep(defPollingTime);
} catch (Exception e) {
Logit.debugLog("Exception is " + e.getMessage());
continue;
}
}
}
}
分享到:
相关推荐
C#线程运用C#线程运用C#线程运用C#线程运用C#线程运用
1. 建立三个线程,并且同时运行它们。当运行时输出线程的名称。 实验步骤: (1)、创建类sy6_1 (2)、创建三个线程,调用start()方法启动这三个线程 (3)、保存文件,调试并编译运行程序。 参考程序运行效果: 2....
里面有3个demo,各种多线程详解,以及多线程使用,为了帮助更多的人理解多线程
易语言多线程的运用源码,多线程的运用,开始,线程运作,销毁全部线程,线程全部暂停,线程全部恢复,取指定内容,挂起线程,恢复线程,创建线程,销毁线程
易语言多线程的运用例程源码,多线程的运用例程,开始,线程运作,销毁全部线程,线程全部暂停,线程全部恢复,取指定内容,挂起线程,恢复线程,创建线程,销毁线程
多线程 e语言多线程 e多线程e语言多线程 e多线程e语言多线程 e多线程
这是多线程的基本操作 ,适合新人,比较好的线程运用方法
嵌入式winCE中线程与消息机制的理解。在不同情况下的线程运用
易语言多线程的运用源码
mybaits 多线程 实现数据批量插入 (运用CountDownLatch实现闭锁) 1、mybatis批处理 2、数据分批量查询 3、数据分批量插入
利用C# WentClient异步编程的网络开发,多线程同时下载,资源附件是源码,VS2010开发的,使用于对网络学习编程,以及多线程运用的童鞋可以参考。
vs2012写的,c# winform程序. 运用线程池写的,查找文件winform, 多线程查找文件. 可以查看当前硬盘有哪些文件,每个文件对应的文件大小.文件路径. 运用listView显示结果.listView分开显示结果信息
从简单到复杂让你深刻了解C#线程的精髓知识,让你在以后的开发中线程运用娴熟。
《秒杀多线程第十六篇 多线程十大经典案例之一 双线程读写队列数据》 ...为了让大家更加熟练运用多线程,将会有十篇文章来讲解十个多线程使用案例,相信看完这十篇后会让你能更加游刃有余的使用多线程。
linux 下 线程编程的综合例子,帮你学好线程运用。
通过JAVA运用多线程控制球的运动,通过窗口中的滑条,对球的大小和颜色进行选择后,随机从窗口左右两方择一进入,小球在遇到障碍或边界后会折回。
运用 委托和事件解决UI线程和后台线程问题,运用 委托和事件解决UI线程和后台线程问题
利用mutex object编写的多线程运用程序, 可以直接运行,可以手动改变线程优先级, 很直观。
1.多线程的概念 2.操纵线程 3.线程的同步和通讯 4.线程池和定时器 5.互斥对象 6.小结