问题
Quartz is usually configured via quartz.properties
on the classpath.
e.g.:
org.quartz.scheduler.instanceName = BagginsScheduler
org.quartz.threadPool.class=org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount=5
org.quartz.threadPool.threadPriority=1
From within the same application that will run the Quartz jobs, I'd like to read out the properties.
Reading the scheduler name is easy:
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
String name = scheduler.getSchedulerName();
But how can I read the `threadPriority' property?
The following does not work:
scheduler.getContext().getString("org.quartz.threadPool.threadPriority");
UPDATED Solution:
It seems that the property can't be read via Quartz API, you have to go via regular Properties
:
Properties prop = new Properties();
prop.load(AnyClassUsedByJVM.class.getClassLoader().getResourceAsStream("quartz.properties"));
String prio = prop.getProperty("org.quartz.threadPool.threadPriority");
This works fine.
回答1:
You can just add that property to your quartz.properties
. For example:
org.quartz.threadPool.threadPriority=3
For more information, see here and configuration documentation
EDIT: To read properties at runtime, you can use Properties. Here's a sample snippet of code you can use:
Properties p = new Properties();
p.load("/tmp/quartz.properties"); // path to your properties file
System.out.println(p.getProperty("org.quartz.threadPool.threadPriority"); // prints 3
来源:https://stackoverflow.com/questions/14103150/quartz-scheduler-how-to-dynamically-read-a-quartz-property-from-java-via-api