2021-08-18

This commit is contained in:
2021-08-18 12:25:27 +09:00
parent 1a7710b100
commit b0d3615378
5 changed files with 97 additions and 1 deletions

16
quartz/build.gradle.kts Normal file
View File

@@ -0,0 +1,16 @@
/*
* Examples for Java
*
* Copyright (c) 2021. Elex. All Rights Reserved.
* https://www.elex-project.com/
*/
plugins {
id("elex-java")
}
dependencies {
// https://mvnrepository.com/artifact/org.quartz-scheduler/quartz
implementation("org.quartz-scheduler:quartz:2.3.2")
}

20
quartz/logback.xml Normal file
View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Examples for Java
~
~ Copyright (c) 2021. Elex. All Rights Reserved.
~ https://www.elex-project.com/
-->
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="TRACE">
<appender-ref ref="CONSOLE" />
</root>
</configuration>

View File

@@ -0,0 +1,20 @@
/*
* Examples for Java
*
* Copyright (c) 2021. Elex. All Rights Reserved.
* https://www.elex-project.com/
*/
package kr.pe.elex.examples;
import org.quartz.*;
public class MyJob implements Job {
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
JobKey jobKey = context.getJobDetail().getKey();
System.out.println(jobKey);
JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
System.out.println(jobDataMap.getString("myVar1"));
}
}

View File

@@ -0,0 +1,40 @@
/*
* Examples for Java
*
* Copyright (c) 2021. Elex. All Rights Reserved.
* https://www.elex-project.com/
*/
package kr.pe.elex.examples;
import lombok.extern.slf4j.Slf4j;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
@Slf4j
public class Quartz {
public static void main(String... args) throws SchedulerException {
SchedulerFactory schedulerFactory = new StdSchedulerFactory();
Scheduler scheduler = schedulerFactory.getScheduler();
scheduler.start();
// 잡을 정의합니다.
JobDetail job = JobBuilder.newJob(MyJob.class)
.withIdentity("myJob", "group1")
.usingJobData("myVar1", "Hello")
.build();
// 트리거를 정의합니다.
Trigger trigger = TriggerBuilder.newTrigger()
.withIdentity("myTrigger", "group1")
.startNow()
.withSchedule(SimpleScheduleBuilder.simpleSchedule()
.withIntervalInSeconds(30)
.repeatForever())
.build();
// 잡과 트리거를 사용해서 스케쥴러에 전달합니다.
scheduler.scheduleJob(job, trigger);
}
}

View File

@@ -14,5 +14,5 @@ include(
"thread", "hibernate", "jdbc-sqlite", "thread", "hibernate", "jdbc-sqlite",
"xml", "jackson", "jsoup", "markdown", "network", "httpd", "xml", "jackson", "jsoup", "markdown", "network", "httpd",
"swing", "java-fx", "properties", "swing", "java-fx", "properties",
"mustache", "thymeleaf", "locale" "mustache", "thymeleaf", "locale", "quartz"
) )