sping的 Schedule實現定時任務

2022-07-20 10:24:09 字數 1882 閱讀 8014

1.配置檔案

在spring配置檔案中新增xmlns:task=""和在xsi:schemalocation新增和                 /spring-task-3.0.xsd">

2.定時任務類

package

cn.com.prac.controller;

import

org.springframework.scheduling.annotation.scheduled;

import

org.springframework.stereotype.component;

@component

public

class

scheduletest

@scheduled(cron="0/5 * * * * ?")

public

void

test2()

}

3.不用配置檔案,使用@enablescheduling,@component,@scheduled註解

@enablescheduling:啟對計畫任務的支援,@component:定義spring管理bean,@scheduled:該方法是計畫任務

package

cn.com.prac.controller;

import

org.springframework.scheduling.annotation.enablescheduling;

import

org.springframework.scheduling.annotation.scheduled;

import

org.springframework.stereotype.component;

@enablescheduling

@component

public

class

scheduletest

@scheduled(cron="0/5 * * * * ?")

public

void

test2()

}

Sping中的 Configuration註解

使用要求 configuration不可以是final型別。configuration不可以是匿名類。巢狀的configuration必須是靜態類。bean類 public class testbean public string tostring public void start public ...

job program和schedule的關係

job分成兩部分 schedule和program。schedule是定義job在什麼條件下啟用執行,條件分為 時間 time base 和事件 event base program定義job每次執行的程式。如 每天2 00執行備份。這個過程叫做job,而schedule定義好每天2 00啟用job...

Timer中schedule 的用法

finalintent intent newintent this,welactivity.class timer timer newtimer timertask task newtimertask timer.schedule 1 timer.schedule timertask task,da...