2012-12-31 1 views
1

Quartz은 일반적으로 클래스 경로에 quartz.properties을 통해 구성됩니다.Quartz Scheduler : API를 통해 Java에서 quartz 속성을 동적으로 읽는 방법은 무엇입니까?

예컨대 :, 내가 속성을 읽어하고자하는 석영 작업을 실행할 같은 응용 프로그램 내에서

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

.

Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); 
String name = scheduler.getSchedulerName(); 

을하지만 난`threadPriority '속성을 읽을 수있는 방법 :

쉽게 스케줄러 이름을 독서?

다음은 작동하지 않습니다 솔루션 업데이트]

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

: 속성이 석영 API를 통해 읽을 수없는 것 같다 , 당신은 정기적으로 Properties를 통해 갈 필요가 :

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

잘 작동합니다.

답변

2

quartz.properties에 해당 속성을 추가하기 만하면됩니다. 예를 들어 :

org.quartz.threadPool.threadPriority=3 

자세한 내용은 hereconfiguration documentation

편집 참조 : 런타임에 속성을 읽으려면 Properties를 사용할 수 있습니다. 사용할 수있는 코드 스 니펫은 다음과 같습니다.

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 
+0

알고 있습니다. 문제는 런타임에 속성을 읽는 방법입니다 (예 : 관리자 페이지에 표시). – basZero

+1

@basZero, 내 편집 된 답변보기. –

관련 문제