最初にスタートアップクラスに注釈を追加する:@enableSchedulingタイミングタスクを開始する
@springbootapplication@enableSchedulingpublic class application {public static void main(string [] args){springApplication.run(application.class、args); }}次に、新しいタイミングのタスククラスを作成します
@componentPublic class QuartzService {/** *時間式を使用してタイミングタスクを実行 */@scheduled(cron = "0 0/1 * *??")public void timertonow(){system.out.println( "now time:" + new simpledateformat( " + new-mm-dd hh:mm:mm:mm:mm:ss"; } / ***開始時点後に1回xミリ秒ごとに1回実行* / @scheduled(sixtrate = 5000)public void timertozzp(){system.out.println( "sixtrate:" + new random()。 } / ***終了時点の後に1回xミリ秒ごとに1回実行* / @scheduled(sixeddelay = 10000)public void timertoreportcount(){system.out.println( "sixeddelay:" + new random()。 } / ** *最初の遅延はx millisecondsであり、次にx millate rulied(initialdelay = 10000、sixedrate = 6000)public void timertoreport(){system.out.println( "hiirthdelay:" + new random()。 SimpleDateFormat( "HH:MM:SS")。format(new date())); }}プロジェクトを開始し、スケジュールされたタスクを開始します
要約します
上記は、編集者が紹介したスプリングブートタイミングタスク処理の実装コードです。それがあなたに役立つことを願っています。ご質問がある場合は、メッセージを残してください。編集者は時間内に返信します。 wulin.comのウェブサイトへのご支援ありがとうございます!