메뉴 건너뛰기

목록
2022.09.17 19:46

quartz 기능 메모

profile
조회 수 61 댓글 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 4435 1
846 아이디어는 강제로 나오는데 3 그리드 2022.09.23 54 0
845 IOT 캡스톤으로 가야하나 그리드 2022.09.23 87 0
844 과제수행을 위한 대주제 확정 그리드 2022.09.23 104 0
843 AWS 자격증명 뭘로하는게낫냐 4 난교파티 2022.09.22 76 0
842 캡스톤디자인 아이디어 모집중 3 그리드 2022.09.21 113 0
841 목진지 원격검문소 1 그리드 2022.09.21 56 0
840 서블릿에서 out.println 난교파티 2022.09.21 67 0
839 라즈베리파이에 1 그리드 2022.09.20 60 0
838 *항공촬영사진을 3 그리드 2022.09.18 288 0
837 캡스톤 디자인 다시 생각해보겠음 그리드 2022.09.18 73 0
836 오늘 종이쪼가리 작성 끝내야함 그리드 2022.09.18 44 0
835 cosmos sdk 2 무메이 2022.09.17 60 0
» quartz 기능 메모 1 白上フブキ 2022.09.17 61 0
833 머신러닝으로 하겠음 그리드 2022.09.17 36 0
832 동적할당이던가 그리드 2022.09.17 40 0
831 C 기초 끝냈으면 1 그리드 2022.09.17 48 0
830 머신러닝기반 음향인식 그리드 2022.09.16 37 0
829 ㅈ라미드 그리드 2022.09.16 79 0
828 버블정렬 1 그리드 2022.09.16 37 0
827 니미시발 캡스톤디자인 1 그리드 2022.09.14 40 0
목록
Board Pagination Prev 1 ... 13 14 15 16 17 18 19 20 21 22 ... 60 Next
/ 60

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5