(Getting SpringBoot) SpringBoot combined with regular tasks task (X)

SpringBoot integrate regular tasks task

  1. Use annotations EnableScheduling on startup class .
  2. Defined @Component as a component of the container is scanned .
  3. 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 = "" )

 

Guess you like

Origin www.cnblogs.com/historylyt/p/10934928.html