作者:LoveEmperor-王子様
Java 定时任务配置文件
- 配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<bean id="authSysLogsUpLoad" class="com.kingdom.digitalcity.esb.authentication.platform.service.DockAuthService" />
<bean id="authSysLogsUpLoadTask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="authSysLogsUpLoad" />
<property name="targetMethod" value="doGetSysLog" />
<property name="concurrent" value="false" />
</bean>
<bean id="authSysLogsUpLoadTaskDoTime" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="authSysLogsUpLoadTask" />
<property name="cronExpression">
<value>0 58 18 ? * *</value>
</property>
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="authSysLogsUpLoadTaskDoTime"/>
</list>
</property>
</bean>
</beans>
-
<value>0 58 18 ? * *</value>
每天18:58启动任务 -
<value>0 */2 * * * ?</value>
两分钟一次 -
Java代码:(代码里随意些打印,看效果就行)
public class DockAuthService {
public String doGetSysLog()throws Exception{
String str = "2018-08-15 11:26:30";
Timestamp time = Timestamp.valueOf(str);
String str2 = "2018-06-07 18:00:50";
Timestamp time2 = Timestamp.valueOf(str2);
SystemLogCondition systemLogCondition = new SystemLogCondition();
//new Timestamp(getTodayDate().getTime())
systemLogCondition.setStarttime(time2);
//new Timestamp((new Date()).getTime())
systemLogCondition.setEndtime(time);
System.out.print(time+"===");
System.out.print(time2);
PageVO<SystemUserLog> pageVO = iSystemLogService.findSystemLogCondition(systemLogCondition,0,23,null,null,null);
PageVO<AuthSysLogsDto> pageVO1 = new PageVO<AuthSysLogsDto>(0,
23);
AuthSysLogsDto sysLogsDto = null;
List<AuthSysLogsDto> resultList = new ArrayList<AuthSysLogsDto>();
if(pageVO.getList() != null && pageVO.getList().size() > 0){
for (SystemUserLog syslog : pageVO.getList()) {
sysLogsDto = new AuthSysLogsDto();
sysLogsDto.setSystemName(syslog.getChild_sys_name());
sysLogsDto.setRequesttime(syslog.getDo_time());
sysLogsDto.setSaction(syslog.getImport_file_name());
sysLogsDto.setFunctionModule(syslog.getMenu_name());
sysLogsDto.setUsername(syslog.getUser_id());
sysLogsDto.setClientIp(syslog.getOperate_ip());
resultList.add(sysLogsDto);
}
// pageVO1.setList(resultList);
}
boolean bool = TxtExport.doTxtExportFunc(resultList);
if (bool){
System.out.print("okkkkkkk");
// FtpUtils ftp =new FtpUtils();
// ftp.uploadFile("ftpFile/data", "123.docx", "E://123.docx");
}
return null;
}
}
- 其他定时:
<bean id="pollutantGasRealSyncDoTime" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail" ref="pollutantGasRealSync" />
<property name="startDelay" value="10000" />
<property name="repeatInterval" value="60000" />
</bean>
<property name="startDelay" value="10000" />
首次启动延迟10秒<property name="repeatInterval" value="60000" />
后续每次间隔60秒