package org.time;
import java.util.TimerTask;
public class MainTask extends TimerTask{
@Override
public void run() {
System.out.println("检测用户是否掉线");
}
}
<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="mainTask" class="org.time.MainTask"></bean>
<!-- 注册定时器信息 -->
<bean id="springTask" class="org.springframework.scheduling.timer.ScheduledTimerTask">
<!-- 延迟1秒执行首次任务 -->
<property name="delay" value="1000"></property>
<!-- 每隔2秒执行一次任务 -->
<property name="period" value="2000"></property>
<!-- 具体执行的任务 -->
<property name="timerTask" ref="mainTask"></property>
</bean>
<!-- 配置任务调度器工厂 -->
<bean id="timerFactory" class="org.springframework.scheduling.timer.TimerFactoryBean">
<property name="scheduledTimerTasks">
<list>
<ref bean="springTask"/>
</list>
</property>
</bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <display-name></display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> </web-app>
package org.time;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class MainTask01{
@Scheduled(cron = "0/3 * * * * ?")
public void run() {
System.out.println("推送消息来了");
}
}
|
字段 |
值 | 特殊表示字符 |
| 年 | 一般为空,1970-2099 | , - * / |
| 月 | 1-12 或者 JAN-DEC | , - * / |
| 星期 | 1-7 或者 SUN-SAT | , - * ? / L C # |
| 日 | 1-31 | , - * ? / L W C |
| 时 | 0-23 | , - * / |
| 分 | 0-59 | , - * / |
| 秒 | 0-59 | , - * / |
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:task="http://www.springframework.org/schema/task" xmlns="http://www.springframework.org/schema/beans" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd"> <context:annotation-config /> <!-- spring扫描注解的配置 --> <context:component-scan base-package="org.time" /> <task:annotation-driven scheduler="qbScheduler" mode="proxy"/> <task:scheduler id="qbScheduler" pool-size="10"/> </beans>
xmlns:task="http://www.springframework.org/schema/task" http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有