java set the start time, scheduled task

These days there is a demand to call an external timing interface, update the database to obtain the return value,

In fact, it has been very exclusive knowledge about the thread piece, probably because the foundation is weak,

To about this stuff are a bit foggy feeling, but directly by the people encapsulated in the final analysis it is quite simple.

Directly on the code better.

@Component
public class updateAISController implements ApplicationRunner {

    @Autowired
    Private BoatService boatService;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        startUpdate ();
    }

    public  void startUpdate () {

        // set the execution time 
        Calendar Calendar = Calendar.getInstance ();
         int year = Calendar.get (Calendar.YEAR);
         int month The = Calendar.get (the Calendar.MONTH);
         int Day = Calendar.get (Calendar.DAY_OF_MONTH);
         // set the start time 
        calendar.set (year, month The, Day, 00,00,02 );
        DATE DATE = calendar.getTime ();
         // set the timing interval 
        int period = 10 * 1000 * 60 * 24 ;
        H h = new Timer ( true );
        timer.schedule(new TimerTask() {
            @Override
            public  void RUN () {
                     // the code to be executed 
                    } the catch (Exception E) {
                        e.printStackTrace ();
                    }
                }

            }
        },date,period);

    }
}                

The specific effect of what you want can set up according to their needs, it is still very convenient,

I demand because there is a need to operate the database, as well as calling on the pit to fill part of the service,

In the next blog to write it.

Guess you like

Origin www.cnblogs.com/Crush123/p/12107367.html