1
1
/*
2
- * Copyright 2002-2017 the original author or authors.
2
+ * Copyright 2002-2018 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -94,17 +94,13 @@ public class SchedulerFactoryBean extends SchedulerAccessor implements FactoryBe
94
94
public static final int DEFAULT_THREAD_COUNT = 10 ;
95
95
96
96
97
- private static final ThreadLocal <ResourceLoader > configTimeResourceLoaderHolder =
98
- new ThreadLocal <>();
97
+ private static final ThreadLocal <ResourceLoader > configTimeResourceLoaderHolder = new ThreadLocal <>();
99
98
100
- private static final ThreadLocal <Executor > configTimeTaskExecutorHolder =
101
- new ThreadLocal <>();
99
+ private static final ThreadLocal <Executor > configTimeTaskExecutorHolder = new ThreadLocal <>();
102
100
103
- private static final ThreadLocal <DataSource > configTimeDataSourceHolder =
104
- new ThreadLocal <>();
101
+ private static final ThreadLocal <DataSource > configTimeDataSourceHolder = new ThreadLocal <>();
105
102
106
- private static final ThreadLocal <DataSource > configTimeNonTransactionalDataSourceHolder =
107
- new ThreadLocal <>();
103
+ private static final ThreadLocal <DataSource > configTimeNonTransactionalDataSourceHolder = new ThreadLocal <>();
108
104
109
105
110
106
/**
@@ -166,6 +162,9 @@ public static DataSource getConfigTimeNonTransactionalDataSource() {
166
162
167
163
private Class <? extends SchedulerFactory > schedulerFactoryClass = StdSchedulerFactory .class ;
168
164
165
+ @ Nullable
166
+ private SchedulerFactory schedulerFactory ;
167
+
169
168
@ Nullable
170
169
private String schedulerName ;
171
170
@@ -185,7 +184,6 @@ public static DataSource getConfigTimeNonTransactionalDataSource() {
185
184
@ Nullable
186
185
private DataSource nonTransactionalDataSource ;
187
186
188
-
189
187
@ Nullable
190
188
private Map <String , ?> schedulerContextMap ;
191
189
@@ -217,7 +215,7 @@ public static DataSource getConfigTimeNonTransactionalDataSource() {
217
215
218
216
219
217
/**
220
- * Set the Quartz SchedulerFactory implementation to use.
218
+ * Set the Quartz {@link SchedulerFactory} implementation to use.
221
219
* <p>Default is {@link StdSchedulerFactory}, reading in the standard
222
220
* {@code quartz.properties} from {@code quartz.jar}.
223
221
* To use custom Quartz properties, specify the "configLocation"
@@ -230,6 +228,18 @@ public void setSchedulerFactoryClass(Class<? extends SchedulerFactory> scheduler
230
228
this .schedulerFactoryClass = schedulerFactoryClass ;
231
229
}
232
230
231
+ /**
232
+ * Set an external Quartz {@link SchedulerFactory} instance to use.
233
+ * <p>Default is an internal {@link StdSchedulerFactory} instance.
234
+ * If this method is being called, it overrides any class specified
235
+ * through {@link #setSchedulerFactoryClass}.
236
+ * @since 5.0.4
237
+ * @see #setSchedulerFactoryClass
238
+ */
239
+ public void setSchedulerFactory (SchedulerFactory schedulerFactory ) {
240
+ this .schedulerFactory = schedulerFactory ;
241
+ }
242
+
233
243
/**
234
244
* Set the name of the Scheduler to create via the SchedulerFactory.
235
245
* <p>If not specified, the bean name will be used as default scheduler name.
@@ -317,7 +327,6 @@ public void setNonTransactionalDataSource(DataSource nonTransactionalDataSource)
317
327
this .nonTransactionalDataSource = nonTransactionalDataSource ;
318
328
}
319
329
320
-
321
330
/**
322
331
* Register objects in the Scheduler context via a given Map.
323
332
* These objects will be available to any Job that runs in this Scheduler.
@@ -470,8 +479,9 @@ public void afterPropertiesSet() throws Exception {
470
479
this .resourceLoader = this .applicationContext ;
471
480
}
472
481
473
- // Create SchedulerFactory instance...
474
- SchedulerFactory schedulerFactory = BeanUtils .instantiateClass (this .schedulerFactoryClass );
482
+ // Initialize the SchedulerFactory instance...
483
+ SchedulerFactory schedulerFactory = (this .schedulerFactory != null ? this .schedulerFactory :
484
+ BeanUtils .instantiateClass (this .schedulerFactoryClass ));
475
485
initSchedulerFactory (schedulerFactory );
476
486
477
487
if (this .resourceLoader != null ) {
0 commit comments