SpringBoot integrate regular tasks task
- Use annotations EnableScheduling on startup class .
- Defined @Component as a component of the container is scanned .
- Expression Builder Address : http: //cron.qqe2.com
Here is an example :
1. // opening timing tasks:
@EnableScheduling
public class DemoApplication {
2. / ** * regular tasks: * / @Component public class TestTask { Private static Final the SimpleDateFormat the dataFormat = new new the SimpleDateFormat ( "HH: mm: SS" ); // every 3 seconds is defined tasks: @Scheduled (fixedRate = 3000 ) public void reportCurrentTime () { . the System OUT .println ( "time now:" + the dataFormat .format ( new new a Date ())); } }
3. Start to get away .
Tip : Timing task can use cron expression: @Scheduled (cron = "" )