메뉴 건너뛰기

목록
2022.09.17 19:46

quartz 기능 메모

profile
조회 수 19 댓글 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 1345 1
999 mysql이랑 mariadb랑 라이센스말곤 매 비슷한거임? 2 저능아 2022.11.08 6 0
998 NAS 서버 구축해주실 수붕이 구합니다. 3 그라드 2021.07.28 49 0
997 NHN 웹 호스팅 보고있는데 1 file 毛簿没区 2021.11.03 41 0
996 Password와 Passphrase의 차이? 3 file 히마와리 2020.06.24 108 0
995 php오버로딩 안되구나 file 저능아 2022.11.11 15 0
994 PS5 499, 399달러 / 11월 19일 전세계 출시 (한국 11월 12일) file shiho 2020.09.17 46 0
993 qemu 쓰기 어렵냐? file 積み 2022.03.02 43 0
992 qemu 어떻게 쓰는 거임 file 積み 2022.03.04 46 0
» quartz 기능 메모 1 白上フブキ 2022.09.17 19 0
990 RAID5 순차쓰기 성능이 너무 낮음... 1 아메 2021.12.29 247 0
989 React native expo 쓰지마라 4 MDR 2021.05.13 92 0
988 react-native 몇달 써보면서 느낀 점 3 MDR 2021.06.04 37 0
987 RN 초반에 개 역겨웠는데 5 MDR 2021.09.10 44 0
986 ROR로 API 만들기 file 하야한아이 2021.02.14 64 0
985 RTX 3090 예상가 1,499$ 맞냐? 1 file 땅크4호 2020.08.27 94 0
984 RuntimeError: asyncio.run() cannot be called from a running event loop 바보 2021.08.24 82 0
983 Rust가 미래다 1 무메이 2023.10.09 79 0
982 Selenium alert_is_present 작동 원리 2 우지챠 2021.01.04 623 1
981 Selenium 페이지 소스 가 눈에 보이는것과 다름 19 file 토깽이 2022.01.11 109 0
980 split 조차 없는 찐따언어 C++ 재기해 Pawn 2022.11.07 16 0
목록
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 11 ... 56 Next
/ 56