spring 13日目は@scheduled注解を使ってタイミングタスクを実行します。
私たちはspringの注釈@Schduledを使ってタイミングタスクを実行します。
spring-task.xmlファイルを作成します。
spring-task.xmlファイルを作成します。
<!--- :xmlns:task="http://www.springframework.org/schema/task"-->
<?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:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.2.xsd
">
<task:annotation-driven /> <!-- -->
<bean id="myTaskXml" class="com.spring.task.MyTaskXml"></bean>
<task:scheduled-tasks>
<!--
-->
<task:scheduled ref="myTaskXml" method="show" cron="*/5 * * * * ?" />
<task:scheduled ref="myTaskXml" method="print" cron="*/10 * * * * ?"/>
</task:scheduled-tasks>
<!-- -->
<context:component-scan base-package="com.spring.task" />
//私たちのタスクプログラムを作成する
public interface IMyTestService {
public void myTest();
}
@Component //import org.springframework.stereotype.Component;
public class MyTestServiceImpl implements IMyTestService {
@Scheduled(cron="0/5 * * * * ? ") // 5
@Override
public void myTest(){
System.out.println(" ");
}
}
cron-like表現
0-59 , - * /
0-59 , - * /
0-23 , - * /
1-31 , - * ? / L W C
1-12 JAN-DEC , - * /
1-7 SUN-SAT , - * ? / L C #
( ) , 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 *