메뉴 건너뛰기

목록
2022.09.17 19:46

quartz 기능 메모

profile
조회 수 16 댓글 1 예스잼 0 노잼 0

No Attached Image

구현할것 : DB 테이블에 cronexpression / 실행클래스 / 실행 method / 기타 데이터 저장 후 어플리케이션 구동시 스케쥴러 등록후 자동실행 처리

 

package com.example.quartz;

 

import org.quartz.JobDetail;

import org.quartz.Scheduler;

import org.quartz.impl.StdSchedulerFactory;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.boot.ApplicationArguments;

import org.springframework.boot.ApplicationRunner;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.scheduling.annotation.EnableScheduling;

import org.springframework.scheduling.quartz.CronTriggerFactoryBean;

import org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean;

 

import com.example.quartz.service.SchedulerService;

 

@SpringBootApplication

@EnableScheduling

public class QuartzApplication implements ApplicationRunner{

public static void main(String[] args) {

SpringApplication.run(QuartzApplication.class, args);

}

 

@Override

public void run(ApplicationArguments args) throws Exception {

Scheduler scheduler = new StdSchedulerFactory().getScheduler();

// Create JOB

        MethodInvokingJobDetailFactoryBean jobDetail = new MethodInvokingJobDetailFactoryBean();

        // Class.newInstance()

// 실행 패키지 내 클래스 지정

        jobDetail.setTargetObject(Class.forName("com.example.quartz.test.testClass").newInstance()); 

        

// Target Method

        jobDetail.setTargetMethod("test"); // TargetMethod : 실행할 프로세스가 정의된 method 명 지정

        jobDetail.setName("testSchedule"); // 스케쥴러의 이름 지정

        jobDetail.setConcurrent(false); //여러 작업을 동시에 실행해야 하는지 여부

        jobDetail.afterPropertiesSet();

        

        // Create CRON Trigger

// cronTrigger 설정

        CronTriggerFactoryBean cronTrigger = new CronTriggerFactoryBean();

        cronTrigger.setBeanName("CRON_" + "testSchedule");

 

        // Execute of CronExpression

        cronTrigger.setCronExpression("0 0/1 * 1/1 * ? *"); // cronexpression 지정

        cronTrigger.afterPropertiesSet();

 

        scheduler.scheduleJob((JobDetail) jobDetail.getObject(), cronTrigger.getObject());

scheduler.start();

}

 

}

 

 

나중에 써먹을수있게 메모해놔야지


List of Articles
번호 제목 글쓴이 날짜 조회 수 추천
공지 수용소닷컴 이용약관 file asuka 2020.05.16 1231 1
850 모질라, Manifest V3과 함께 기존의 익스텐션도 계속 지원 예정 file 히마와리 2022.09.30 18 0
849 jsp파일 갑자기 물음표뜰때 4 file 난교파티 2022.09.29 17 0
848 아이 씨 1 그리드 2022.09.26 22 0
847 아니 MFA 활성화 대체 왜안되는데 난교파티 2022.09.24 18 0
846 아이디어는 강제로 나오는데 3 그리드 2022.09.23 29 0
845 IOT 캡스톤으로 가야하나 그리드 2022.09.23 26 0
844 과제수행을 위한 대주제 확정 그리드 2022.09.23 69 0
843 AWS 자격증명 뭘로하는게낫냐 4 난교파티 2022.09.22 47 0
842 캡스톤디자인 아이디어 모집중 3 그리드 2022.09.21 57 0
841 목진지 원격검문소 1 그리드 2022.09.21 40 0
840 서블릿에서 out.println 난교파티 2022.09.21 48 0
839 라즈베리파이에 1 그리드 2022.09.20 44 0
838 *항공촬영사진을 3 그리드 2022.09.18 54 0
837 캡스톤 디자인 다시 생각해보겠음 그리드 2022.09.18 42 0
836 오늘 종이쪼가리 작성 끝내야함 그리드 2022.09.18 14 0
835 cosmos sdk 2 무메이 2022.09.17 19 0
» quartz 기능 메모 1 白上フブキ 2022.09.17 16 0
833 머신러닝으로 하겠음 그리드 2022.09.17 7 0
832 동적할당이던가 그리드 2022.09.17 7 0
831 C 기초 끝냈으면 1 그리드 2022.09.17 17 0
목록
Board Pagination Prev 1 ... 7 8 9 10 11 12 13 14 15 16 ... 54 Next
/ 54