Quartz Scheduler:如何通过API从Java动态读取quartz属性? [英] Quartz Scheduler: How to dynamically read a quartz property from Java via API?

查看:445
本文介绍了Quartz Scheduler:如何通过API从Java动态读取quartz属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Quartz 通常通过 quartz.properties 。

例如:

org.quartz.scheduler.instanceName = BagginsScheduler
org.quartz.threadPool.class=org.quartz.simpl.SimpleThreadPool   
org.quartz.threadPool.threadCount=5  
org.quartz.threadPool.threadPriority=1  

从运行Quartz作业的同一个应用程序中,我想读出这些属性。

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();

但我如何阅读`threadPriority'属性?

But how can I read the `threadPriority' property?

以下不起作用:

scheduler.getContext().getString("org.quartz.threadPool.threadPriority");

更新解决方案
看来该物业可以'通过Quartz API读取,您必须通过常规属性

Properties prop = new Properties();
prop.load(AnyClassUsedByJVM.class.getClassLoader().getResourceAsStream("quartz.properties"));
String prio = prop.getProperty("org.quartz.threadPool.threadPriority");

一切正常。

推荐答案

您可以将该属性添加到 quartz.properties 。例如:

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

这篇关于Quartz Scheduler:如何通过API从Java动态读取quartz属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆