//applicationContext.xml
<!--
* 定时器任务,用来处理:
* 每日凌晨0点Push消息缓存统计刷新、每日凌晨0点5分IP转运营商/地域范围信息
* 每日凌晨1点执行营销平台推送任务
*-->
<bean id="resetPushCntCacheJob" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass">
<value>com.lenovo.lps.psb.pb.ResetPushCntCacheJob
</value>
</property>
</bean>
<!-- <bean id="resetPushCntCacheTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">-->
<bean id="resetPushCntCacheTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="resetPushCntCacheJob" />
</property>
<property name="cronExpression">
<value>0 55 23 * * ?</value>
<!-- <value>0 0 0 * * ?</value>-->
</property>
<!-- 0 0 0 1 * ?
# 1.秒(0-59)
# 2.分钟(0-59)
# 3.小时(0-23)
# 4.月份中的日期(1-31)
# 5.月份(1-12或SUN-DEC)
# 6.星期中的日期(1-7或SUN-SAT)
# 7.年份(1970-2099)
表达式意义
"0 0 12 * * ?" 每天中午12点触发
"0 15 10 ? * *" 每天上午10:15触发
"0 15 10 * * ?" 每天上午10:15触发
"0 15 10 * * ? *" 每天上午10:15触发
"0 15 10 * * ? 2005" 2005年的每天上午10:15触发
"0 * 14 * * ?" 在每天下午2点到下午2:59期间的每1分钟触发
"0 0/5 14 * * ?" 在每天下午2点到下午2:55期间的每5分钟触发
"0 0/5 14,18 * * ?" 在每天下午2点到2:55期间和下午6点到6:55期间的每5分钟触发
"0 0-5 14 * * ?" 在每天下午2点到下午2:05期间的每1分钟触发
"0 10,44 14 ? 3 WED" 每年三月的星期三的下午2:10和2:44触发
"0 15 10 ? * MON-FRI" 周一至周五的上午10:15触发
"0 15 10 15 * ?" 每月15日上午10:15触发
"0 15 10 L * ?" 每月最后一日的上午10:15触发
"0 15 10 ? * 6L" 每月的最后一个星期五上午10:15触发
"0 15 10 ? * 6L 2002-2005" 2002年至2005年的每月的最后一个星期五上午10:15触发
"0 15 10 ? * 6#3" 每月的第三个星期五上午10:15触发
每天早上6点
0 6 * * *
每两个小时
0 */2 * * *
晚上11点到早上8点之间每两个小时,早上八点
0 23-7/2,8 * * *
每个月的4号和每个礼拜的礼拜一到礼拜三的早上11点
0 11 4 * 1-3
1月1日早上4点
0 4 1 1 *
-->
</bean>
<bean id="ipToperationAreaJob" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass">
<value>com.lenovo.lps.psb.pushmarketing.IpToperationAreaJob
</value>
</property>
</bean>
<bean id="ipToperationAreaTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="ipToperationAreaJob" />
</property>
<property name="cronExpression">
<value>0 10 0 * * ?</value>
<!-- <value>0 5 0 * * ?</value> -->
</property>
</bean>
<bean id="flushDeviceDimenJob" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass">
<value>com.lenovo.lps.psb.pushmarketing.FlushDeviceDimenJob
</value>
</property>
</bean>
<bean id="flushDeviceDimenTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="flushDeviceDimenJob" />
</property>
<property name="cronExpression">
<value>0 40 0 * * ?</value>
<!-- <value>0 0 1 * * ?</value> -->
</property>
</bean>
<bean id="executePushTaskJob" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass">
<value>com.lenovo.lps.psb.pushmarketing.ExecutePushTaskJob
</value>
</property>
</bean>
<bean id="executePushTaskTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="executePushTaskJob" />
</property>
<property name="cronExpression">
<value>0 0 1 * * ?</value>
<!-- <value>0 0 1 * * ?</value> -->
</property>
</bean>
<bean id="pushmarketingMonitor" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="applicationContextSchedulerContextKey" value="applicationContextKey" />
<property name="configLocation" value="/WEB-INF/quartz.properties" />
<property name="triggers">
<list>
<!-- 23:55 -->
<ref bean="resetPushCntCacheTrigger"></ref>
<!-- 00:10 -->
<ref bean="ipToperationAreaTrigger"></ref>
<!-- 00:40 -->
<ref bean="flushDeviceDimenTrigger"></ref>
<!-- 01:00 -->
<ref bean="executePushTaskTrigger"></ref>
</list>
</property>
</bean>
import java.util.Iterator;
import java.util.Map;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;
import com.lenovo.lps.log.Log;
import com.lenovo.lps.psb.common.log.reduce.dao.MysqlSpiderDSFacadeImpl;
import com.lenovo.lps.psb.common.util.IocUtils;
import com.lenovo.lps.psb.pb.cache.PushCntCache;
import com.lenovo.lps.psb.pb.cache.PushCntVO;
/**
*
*/
public class ResetPushCntCacheJob extends QuartzJobBean {
//private PushCntCache pushCntCache;
private static Log log = Log.getInstance(ResetPushCntCacheJob.class);
@Override
protected void executeInternal(JobExecutionContext context)
throws JobExecutionException {
System.out.println("ResetPushCntCacheJob=======================executeInternal-------------");
log.info("ResetPushCntCacheJob=======================executeInternal-------------");
PushCntCache pushCntCache= (PushCntCache) IocUtils.getBean("pushCntCache");
try {
if(pushCntCache!=null){
PushCntVO vo=pushCntCache.getPushCnt();
if(vo!=null&&(vo.getSidarrivedcntMap()!=null||vo.getSidreceivedcntMap()!=null)){
vo=new PushCntVO();
pushCntCache.savePushCnt(vo);
}
}
//将Push处理总量、到达量分布日报情况数据写入数据库
MysqlSpiderDSFacadeImpl mysqlSpiderDSFacadeImpl = (MysqlSpiderDSFacadeImpl) IocUtils.getBean(MysqlSpiderDSFacadeImpl.BEAN_NAME);
savePushmsgsIndicatorToDB(1,pushCntCache,mysqlSpiderDSFacadeImpl);
} catch (Exception e) {
log.warn(e);
}
}
public void savePushmsgsIndicatorToDB(int reportType,PushCntCache pushCntCache,MysqlSpiderDSFacadeImpl mysqlSpiderDSFacadeImpl){
//处理量统计
long tianqi_cnt_temp=0;
long neirong_cnt_temp=0;
long qiyeyoujian_cnt_temp=0;
long gexinghuapush_cnt_temp=0;
long leshangdian_cnt_temp=0;
long gerenyoujian_cnt_temp=0;
long qita_cnt_temp=0;
long rsys001_cnt_temp=0;
long pushtome_cnt_temp=0;
//到达量统计
long tianqi_arr_cnt_temp=0;
long neirong_arr_cnt_temp=0;
long qiyeyoujian_arr_cnt_temp=0;
long gexinghuapush_arr_cnt_temp=0;
long leshangdian_arr_cnt_temp=0;
long gerenyoujian_arr_cnt_temp=0;
long qita_arr_cnt_temp=0;
long rsys001_arr_cnt_temp=0;
long pushtome_arr_cnt_temp=0;
if(pushCntCache==null||pushCntCache.getPushCnt()==null){
return ;
}
System.out.println("ResetPushCntCacheJob::---pushCntCache.getPushCnt():"+pushCntCache.getPushCnt());
Map<String,Long> sidarrivedcntMap =pushCntCache.getPushCnt().getSidarrivedcntMap();
Map<String,Long> sidreceivedcntMap =pushCntCache.getPushCnt().getSidreceivedcntMap();
//处理接受服务消息量统计记录
if(sidreceivedcntMap!=null&&sidreceivedcntMap.entrySet().size()>0){
Iterator it = sidreceivedcntMap.entrySet().iterator();
while(it.hasNext()){
Map.Entry<String,Long> m=(Map.Entry<String,Long>)it.next();
System.out.println("++++++++++++++++++sidreceivedcntMap+++++++++++++++++++++" + m.getKey() + ":" + m.getValue());
long cntvalue=m.getValue();
if("rwthr01".equals(m.getKey())){
tianqi_cnt_temp=cntvalue;
//SidPushmsgCntFile.saveSidPushmsgCntValue(receive_key_prefix+m.getKey(), cntvalue+"");
//System.out.println("rwthr01::" +tianqi_cnt_temp);
}else if("rlpm001".equals(m.getKey() )){
gerenyoujian_cnt_temp=cntvalue;
//SidPushmsgCntFile.saveSidPushmsgCntValue(receive_key_prefix+m.getKey(), cntvalue+"");
//System.out.println("rlpm001::" +gerenyoujian_cnt_temp);
}else if("rlesesc".equals(m.getKey() )){
qiyeyoujian_cnt_temp=cntvalue;
//SidPushmsgCntFile.saveSidPushmsgCntValue(receive_key_prefix+m.getKey(), cntvalue+"");
//System.out.println("rlesesc::" +qiyeyoujian_cnt_temp);
}else if("rcntrss".equals(m.getKey() )){
gexinghuapush_cnt_temp=cntvalue;
//SidPushmsgCntFile.saveSidPushmsgCntValue(receive_key_prefix+m.getKey(), cntvalue+"");
//System.out.println("rcntrss::" +gexinghuapush_cnt_temp);
}else if("rapp001".equals(m.getKey() )){
leshangdian_cnt_temp=cntvalue;
//SidPushmsgCntFile.saveSidPushmsgCntValue(receive_key_prefix+m.getKey(), cntvalue+"");
//System.out.println("rapp001::" +leshangdian_cnt_temp);
}else if("rcntv01".equals(m.getKey() )){
neirong_cnt_temp+=cntvalue;
//SidPushmsgCntFile.saveSidPushmsgCntValue(receive_key_prefix+m.getKey(), cntvalue+"");
//System.out.println("rcntv01::" +cntvalue);
}else if("rcntn02".equals(m.getKey() )){
neirong_cnt_temp+=cntvalue;
//SidPushmsgCntFile.saveSidPushmsgCntValue(receive_key_prefix+m.getKey(), cntvalue+"");
//System.out.println("rcntn02::" +cntvalue);
}else if("rsys001".equals(m.getKey() )){
rsys001_cnt_temp+=cntvalue;
//SidPushmsgCntFile.saveSidPushmsgCntValue(receive_key_prefix+m.getKey(), cntvalue+"");
//System.out.println("rsys001::" +cntvalue);
}else if("rsys100".equals(m.getKey() )){
rsys001_cnt_temp+=cntvalue;
//SidPushmsgCntFile.saveSidPushmsgCntValue(receive_key_prefix+m.getKey(), cntvalue+"");
//System.out.println("rsys001::" +cntvalue);
}else if("1008".equals(m.getKey() )){
//pushtome_cnt_temp=cntvalue;
qita_cnt_temp=cntvalue;
//SidPushmsgCntFile.saveSidPushmsgCntValue(receive_key_prefix+m.getKey(), cntvalue+"");
//System.out.println("rsys001::" +cntvalue);
}else{
//其他应用大于10W推送总量时,记录到文件中.
//if(cntvalue>100000){
//SidPushmsgCntFile.saveSidPushmsgCntValue(receive_key_prefix+m.getKey(), cntvalue+"");
//System.out.println(m.getKey()+"::" +cntvalue);
//}
qita_cnt_temp+=cntvalue;
}
}
}
//处理量统计
// long tianqi_cnt_temp=0;
// long neirong_cnt_temp=0;
// long qiyeyoujian_cnt_temp=0;
// long gexinghuapush_cnt_temp=0;
// long leshangdian_cnt_temp=0;
// long gerenyoujian_cnt_temp=0;
// long qita_cnt_temp=0;
// long rsys001_cnt_temp=0;
// long pushtome_cnt_temp=0;
String[] recepushindicators=new String[15];
recepushindicators[0]="0";
recepushindicators[1]="0";
recepushindicators[2]="0";
recepushindicators[3]="0";
recepushindicators[4]="0";
recepushindicators[5]="0";
recepushindicators[6]=tianqi_cnt_temp+"";
recepushindicators[7]=neirong_cnt_temp+"";
recepushindicators[8]=qiyeyoujian_cnt_temp+"";
recepushindicators[9]=gexinghuapush_cnt_temp+"";
recepushindicators[10]=leshangdian_cnt_temp+"";
recepushindicators[11]=gerenyoujian_cnt_temp+"";
recepushindicators[12]=rsys001_cnt_temp+"";
recepushindicators[13]=qita_cnt_temp+"";
recepushindicators[14]="0";
//sid接受消息分布统计
mysqlSpiderDSFacadeImpl.savePushIncatorToDB(10,recepushindicators);
//处理到达服务消息量统计记录
if(sidarrivedcntMap!=null&&sidarrivedcntMap.entrySet().size()>0){
Iterator arrivedit = sidarrivedcntMap.entrySet().iterator();
while(arrivedit.hasNext()){
Map.Entry<String,Long> m=(Map.Entry<String,Long>)arrivedit.next();
System.out.println("++++++++++++++++++sidarrivedcntMap++++++++++++++++++" + m.getKey() + ":" + m.getValue());
long cntvalue=m.getValue();
if("rwthr01".equals(m.getKey())){
tianqi_arr_cnt_temp=cntvalue;
//SidPushmsgCntFile.saveSidPushmsgCntValue(arrived_key_prefix+m.getKey(), cntvalue+"");
}else if("rlpm001".equals(m.getKey() )){
gerenyoujian_arr_cnt_temp=cntvalue;
//SidPushmsgCntFile.saveSidPushmsgCntValue(arrived_key_prefix+m.getKey(), cntvalue+"");
}else if("rlesesc".equals(m.getKey() )){
qiyeyoujian_arr_cnt_temp=cntvalue;
//SidPushmsgCntFile.saveSidPushmsgCntValue(arrived_key_prefix+m.getKey(), cntvalue+"");
}else if("rcntrss".equals(m.getKey() )){
gexinghuapush_arr_cnt_temp=cntvalue;
//SidPushmsgCntFile.saveSidPushmsgCntValue(arrived_key_prefix+m.getKey(), cntvalue+"");
}else if("rapp001".equals(m.getKey() )){
leshangdian_arr_cnt_temp=cntvalue;
//SidPushmsgCntFile.saveSidPushmsgCntValue(arrived_key_prefix+m.getKey(), cntvalue+"");
}else if("rcntv01".equals(m.getKey() )){
neirong_arr_cnt_temp+=cntvalue;
//SidPushmsgCntFile.saveSidPushmsgCntValue(arrived_key_prefix+m.getKey(), cntvalue+"");
}else if("rcntn02".equals(m.getKey() )){
neirong_arr_cnt_temp+=cntvalue;
//SidPushmsgCntFile.saveSidPushmsgCntValue(arrived_key_prefix+m.getKey(), cntvalue+"");
}else if("rsys001".equals(m.getKey() )){
rsys001_arr_cnt_temp+=cntvalue;
//SidPushmsgCntFile.saveSidPushmsgCntValue(arrived_key_prefix+m.getKey(), cntvalue+"");
}else if("rsys100".equals(m.getKey() )){
rsys001_arr_cnt_temp+=cntvalue;
//SidPushmsgCntFile.saveSidPushmsgCntValue(arrived_key_prefix+m.getKey(), cntvalue+"");
}else if("1008".equals(m.getKey() )){
//pushtome_arr_cnt_temp+=cntvalue;
qita_arr_cnt_temp+=cntvalue;
//SidPushmsgCntFile.saveSidPushmsgCntValue(arrived_key_prefix+m.getKey(), cntvalue+"");
}else{
//其他应用大于10W推送总量时,记录到文件中.
//其他应用大于10W推送总量时,记录到文件中.
//if(cntvalue>100000){
//SidPushmsgCntFile.saveSidPushmsgCntValue(arrived_key_prefix+m.getKey(), cntvalue+"");
//}
qita_arr_cnt_temp+=cntvalue;
}
}
}
/*
*
//到达量统计
long tianqi_arr_cnt_temp=0;
long neirong_arr_cnt_temp=0;
long qiyeyoujian_arr_cnt_temp=0;
long gexinghuapush_arr_cnt_temp=0;
long leshangdian_arr_cnt_temp=0;
long gerenyoujian_arr_cnt_temp=0;
long qita_arr_cnt_temp=0;
long rsys001_arr_cnt_temp=0;
long pushtome_arr_cnt_temp=0;
*/
String[] arripushindicators=new String[15];
arripushindicators[0]="0";
arripushindicators[1]="0";
arripushindicators[2]="0";
arripushindicators[3]="0";
arripushindicators[4]="0";
arripushindicators[5]="0";
arripushindicators[6]=tianqi_arr_cnt_temp+"";
arripushindicators[7]=neirong_arr_cnt_temp+"";
arripushindicators[8]=qiyeyoujian_arr_cnt_temp+"";
arripushindicators[9]=gexinghuapush_arr_cnt_temp+"";
arripushindicators[10]=leshangdian_arr_cnt_temp+"";
arripushindicators[11]=gerenyoujian_arr_cnt_temp+"";
arripushindicators[12]=rsys001_arr_cnt_temp+"";
arripushindicators[13]=qita_arr_cnt_temp+"";
arripushindicators[14]="0";
//sid到达消息分布统计
mysqlSpiderDSFacadeImpl.savePushIncatorToDB(11,arripushindicators);
}
}