用的spring,須要在XML裏面往JobDetailBean注入一個org.quartz.JobDataMap做爲參數.在類裏面能夠直接取出來.(若是不用spring,能夠直接配置job-data-map)java
<bean name="testDataMap" class="org.quartz.JobDataMap"> <constructor-arg> <map> <entry key="PARAM1" value="參數1"></entry> <entry key="PARAM2" value="參數2"></entry> <entry key="PARAM3" value="參數3"></entry> </map> </constructor-arg> </bean> <bean name="jobDetail1" class="org.springframework.scheduling.quartz.JobDetailBean"> <property name="jobClass"> <value> com.test.quartzforcz.sendTask </value> </property> <property name="jobDataMap"> <ref bean="testDataMap" /> </property> </bean>
在Job類中的 executeInternal(JobExecutionContext context) 中這樣取出:
spring
JobDataMap dataMap = context.getJobDetail().getJobDataMap(); logger.info("PARAM1:" + dataMap.getString("PARAM1"));