Skip to content

Commit 2c06221

Browse files
committed
upgrade version
1 parent 0851f93 commit 2c06221

File tree

9 files changed

+104
-37
lines changed

9 files changed

+104
-37
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="ExampleSpringQuartzApplication" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot" nameIsGenerated="true">
3+
<option name="FRAME_DEACTIVATION_UPDATE_POLICY" value="UpdateClassesAndResources" />
4+
<module name="example-spring-quartz" />
5+
<option name="SPRING_BOOT_MAIN_CLASS" value="io.github.toquery.example.quartz.ExampleSpringQuartzApplication" />
6+
<method v="2">
7+
<option name="Make" enabled="true" />
8+
</method>
9+
</configuration>
10+
</component>

docker-compose.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
services:
2+
postgres:
3+
image: 'postgres:16'
4+
ports:
5+
- '5432'
6+
environment:
7+
- 'POSTGRES_DB=example_spring_quartz'
8+
- 'POSTGRES_PASSWORD=postgres'

pom.xml

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,11 @@
1515
<description>Demo project for Spring Boot</description>
1616

1717
<properties>
18-
<java.version>1.8</java.version>
18+
<java.version>21</java.version>
1919
</properties>
2020

2121
<dependencies>
22-
<dependency>
23-
<groupId>org.springframework.boot</groupId>
24-
<artifactId>spring-boot-starter-quartz</artifactId>
25-
</dependency>
26-
<!-- mysql -->
27-
<dependency>
28-
<groupId>mysql</groupId>
29-
<artifactId>mysql-connector-java</artifactId>
30-
</dependency>
22+
3123
<!-- orm -->
3224
<dependency>
3325
<groupId>org.springframework.boot</groupId>
@@ -49,13 +41,54 @@
4941
<artifactId>spring-boot-starter-test</artifactId>
5042
<scope>test</scope>
5143
</dependency>
44+
45+
<dependency>
46+
<groupId>org.springframework.boot</groupId>
47+
<artifactId>spring-boot-docker-compose</artifactId>
48+
<scope>runtime</scope>
49+
</dependency>
50+
<dependency>
51+
<groupId>io.micrometer</groupId>
52+
<artifactId>micrometer-registry-prometheus</artifactId>
53+
<scope>runtime</scope>
54+
</dependency>
55+
<dependency>
56+
<groupId>org.springframework.boot</groupId>
57+
<artifactId>spring-boot-configuration-processor</artifactId>
58+
<scope>annotationProcessor</scope>
59+
</dependency>
60+
<dependency>
61+
<groupId>org.springframework.boot</groupId>
62+
<artifactId>spring-boot-starter-quartz</artifactId>
63+
</dependency>
64+
<dependency>
65+
<groupId>org.springframework.boot</groupId>
66+
<artifactId>spring-boot-starter-actuator</artifactId>
67+
</dependency>
68+
<dependency>
69+
<groupId>org.postgresql</groupId>
70+
<artifactId>postgresql</artifactId>
71+
<scope>runtime</scope>
72+
</dependency>
5273
</dependencies>
5374

5475
<build>
5576
<plugins>
77+
<plugin>
78+
<groupId>org.graalvm.buildtools</groupId>
79+
<artifactId>native-maven-plugin</artifactId>
80+
</plugin>
5681
<plugin>
5782
<groupId>org.springframework.boot</groupId>
5883
<artifactId>spring-boot-maven-plugin</artifactId>
84+
<configuration>
85+
<excludes>
86+
<exclude>
87+
<groupId>org.projectlombok</groupId>
88+
<artifactId>lombok</artifactId>
89+
</exclude>
90+
</excludes>
91+
</configuration>
5992
</plugin>
6093
</plugins>
6194
</build>

src/main/java/io/github/toquery/example/quartz/QuartzSchedulerConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.github.toquery.example.quartz;
22

3+
import io.github.toquery.example.quartz.job.JobSpringQuartz;
34
import org.quartz.JobDetail;
4-
import org.springframework.beans.factory.annotation.Qualifier;
55
import org.springframework.context.annotation.Bean;
66
import org.springframework.context.annotation.Configuration;
77
import org.springframework.scheduling.quartz.CronTriggerFactoryBean;

src/main/java/io/github/toquery/example/quartz/JobSpringQuartz.java renamed to src/main/java/io/github/toquery/example/quartz/job/JobSpringQuartz.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.github.toquery.example.quartz;
1+
package io.github.toquery.example.quartz.job;
22

33
import lombok.extern.slf4j.Slf4j;
44
import org.quartz.DisallowConcurrentExecution;

src/main/java/io/github/toquery/example/quartz/JobTwo.java renamed to src/main/java/io/github/toquery/example/quartz/job/JobTwo.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
package io.github.toquery.example.quartz;
1+
package io.github.toquery.example.quartz.job;
22

3+
import lombok.extern.slf4j.Slf4j;
34
import org.quartz.DisallowConcurrentExecution;
45
import org.quartz.Job;
56
import org.quartz.JobDataMap;
67
import org.quartz.JobExecutionContext;
78
import org.quartz.JobExecutionException;
89
import org.quartz.PersistJobDataAfterExecution;
910
import org.springframework.stereotype.Component;
10-
11+
@Slf4j
1112
@PersistJobDataAfterExecution
1213
@DisallowConcurrentExecution
1314
@Component
@@ -17,5 +18,6 @@ public void execute(JobExecutionContext context) throws JobExecutionException {
1718
JobDataMap data = context.getTrigger().getJobDataMap();
1819
String invokeParam = (String) data.get("invokeParam");
1920
//在这里实现业务逻辑
21+
log.info(" Job Two invokeParam : {} ", invokeParam);
2022
}
2123
}

src/main/java/io/github/toquery/example/quartz/AppJobListener.java renamed to src/main/java/io/github/toquery/example/quartz/listener/AppJobListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.github.toquery.example.quartz;
1+
package io.github.toquery.example.quartz.listener;
22

33
import lombok.extern.slf4j.Slf4j;
44
import org.quartz.JobExecutionContext;

src/main/java/io/github/toquery/example/quartz/ScheduledTask.java renamed to src/main/java/io/github/toquery/example/quartz/scheduled/ScheduledTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.github.toquery.example.quartz;
1+
package io.github.toquery.example.quartz.scheduled;
22

33
import org.springframework.scheduling.annotation.Scheduled;
44
import org.springframework.stereotype.Component;

src/main/resources/application.yml

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
server:
2-
port: 0
31

42
spring:
53
application:
64
name: example-spring-quartz
5+
76
jpa:
87
open-in-view: false
98
show-sql: true
@@ -13,34 +12,49 @@ spring:
1312
hibernate:
1413
format_sql: true
1514
use_sql_comments: true
15+
1616
#连接池配置
1717
datasource:
18-
driver-class-name: com.mysql.cj.jdbc.Driver
19-
url: jdbc:mysql://${DB_MYSQL_HOST}:3306/example_spring_quartz?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull
20-
username: ${DB_MYSQL_USER}
21-
password: ${DB_MYSQL_PASSWORD}
18+
url: jdbc:postgresql://postgres.example-spring-quartz.orb.local:5432/example_spring_quartz
19+
username: postgres
20+
password: postgres
2221

2322
quartz:
2423
auto-startup: true
2524
job-store-type: jdbc
25+
26+
scheduler-name: example-spring-quartz
27+
# 程序结束时会等待quartz相关的内容结束
28+
wait-for-jobs-to-complete-on-shutdown: true
29+
# QuartzScheduler启动时更新己存在的Job,这样就不用每次修改targetObject后删除qrtz_job_details表对应记录
30+
overwrite-existing-jobs: true
2631
jdbc:
2732
initialize-schema: ALWAYS
28-
scheduler-name: example-spring-quartz
2933
properties:
30-
org.quartz.jobStore.isClustered: true
31-
# org.quartz.scheduler.instanceName: quartz-demo-app
32-
org.quartz.scheduler.instanceId: AUTO
33-
# # org.quartz.scheduler.instanceIdGenerator.class: com.helixz.quartz.demo.component.CustomQuartzInstanceIdGenerator
34-
# # 并发数
35-
# org.quartz.threadPool.threadCount: 20
36-
# org.quartz.jobStore.class: org.quartz.impl.jdbcjobstore.JobStoreTX
37-
# org.quartz.jobStore.driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate
38-
# org.quartz.jobStore.useProperties: true
39-
# org.quartz.jobStore.misfireThreshold: 60000
40-
# org.quartz.jobStore.tablePrefix: qrtz_
41-
# org.quartz.jobStore.isClustered: true
42-
# org.quartz.plugin.shutdownHook.class: org.quartz.plugins.management.ShutdownHookPlugin
43-
# org.quartz.plugin.shutdownHook.cleanShutdown: TRUE
34+
org:
35+
quartz:
36+
scheduler:
37+
# instanceName: quartz-demo-app
38+
instanceId: AUTO #默认主机名和时间戳生成实例ID,可以是任何字符串,但对于所有调度程序来说,必须是唯一的 对应 QRTZ_SCHEDULER_STATE INSTANCE_NAME字段
39+
jobStore:
40+
class: org.springframework.scheduling.quartz.LocalDataSourceJobStore #持久化配置
41+
driverDelegateClass: org.quartz.impl.jdbcjobstore.PostgreSQLDelegate # 由于StdJDBCDelegate在读取BLOB时存在问题,需要使用与数据库相对应的驱动。
42+
#driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate #我们仅为数据库制作了特定于数据库的代理
43+
tablePrefix: QRTZ_ #数据库表前缀
44+
misfireThreshold: 60000 #在被认为“失火”之前,调度程序将“容忍”一个Triggers将其下一个启动时间通过的毫秒数。默认值(如果您在配置中未输入此属性)为60000(60秒)。
45+
clusterCheckinInterval: 5000 #设置此实例“检入”*与群集的其他实例的频率(以毫秒为单位)。影响检测失败实例的速度。
46+
isClustered: true #打开群集功能
47+
acquireTriggersWithinLock: true
48+
useProperties: false
49+
threadPool:
50+
class: org.springframework.scheduling.quartz.SimpleThreadPoolTaskExecutor # org.quartz.impl.jdbcjobstore.JobStoreTX
51+
threadCount: 10 # 并发数
52+
threadPriority: 5
53+
threadsInheritContextClassLoaderOfInitializingThread: true
54+
plugin:
55+
shutdownHook:
56+
class: org.quartz.plugins.management.ShutdownHookPlugin
57+
cleanShutdown: true
4458

4559

4660
#============================================================================# 配置JobStore#============================================================================# JobDataMaps是否都为String类型,默认falseorg.quartz.jobStore.useProperties=false

0 commit comments

Comments
 (0)