Announcement Announcement Module
Collapse
No announcement yet.
Easy question on getCurrentlyExecutingJobs() Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Easy question on getCurrentlyExecutingJobs()

    Got Spring 3.2 and quartz 2.1 running on multiple jobs and was looking to have a method the lists all the currently executing jobs. With out using the FactoryBeans in Spring or Quartz alone this is a relatively simple task using the scheduler.getCurrentlyExecutingJobs() method to a list. My current method always return a null pointer exception when I try to @Autowire the scheduler bean and call this method. Any help on why I can't inject the SchedulerfactoryBean would be greatly appreciated because second step is to make a soft shutdown or interrupt method.

    Here is my config
    Code:
    		<bean id="serverMonitorTask" class="com.test.tools.servermonitor.tasks.ServerMonitorTask" />
    	
    	<bean name="serverMonitorJob" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
    		<property name="jobClass" value="com.test.tools.servermonitor.jobs.ServerMonitorJob" />
    		<property name="jobDataAsMap">
    			<map>
    				<entry key="serverMonitorTask" value-ref="serverMonitorTask" />
    			</map>
    		</property>
    		<property name="durability" value="true"/>
    	</bean>
    	
    	<bean id="serverMonitorStatusUnknown" class="com.test.tools.servermonitor.tasks.ServerMonitorStatusUnknown" />
    	
    	<bean name="serverMonitorStatusUnknownJob" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
    		<property name="jobClass" value="com.test.tools.servermonitor.jobs.ServerMonitorStatusUnknownJob"/>
    		<property name="jobDataAsMap">
    			<map>
    				<entry key="serverMonitorStatusUnknown" value-ref="serverMonitorStatusUnknown" />
    			</map>
    		</property>
    		<property name="durability" value="true"/>
    	</bean>
    	
    	<bean id="serverMonitorMaintenance" class="com.test.tools.servermonitor.tasks.ServerMonitorMaintenance" />
    	
    	<bean name="serverMonitorMaintenanceJob" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
    		<property name="jobClass" value="com.test.tools.servermonitor.jobs.ServerMonitorMaintenanceJob" />
    		<property name="jobDataAsMap">
    			<map>
    				<entry key="serverMonitorMaintenance" value-ref="serverMonitorMaintenance" />
    			</map>
    		</property>
    		<property name="durability" value="true"/>
    	</bean>
    		
    	<!-- Simple Trigger, run every 15 seconds -->
    	<bean id="simpleTaskTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean">
    
    		<property name="jobDetail" ref="serverMonitorJob" />
    		<property name="repeatInterval" value="30000" />
    		<property name="startDelay" value="5000" />
    
    	</bean>
    Trying to call it up with this code:
    Code:
    	@Autowired
    	public Scheduler  schedulerFactoryBean;
    
    	public List<JobExecutionContext> listJobs() throws SchedulerException{
    		List<JobExecutionContext> currentlyExecuting = new ArrayList<JobExecutionContext>();
    		currentlyExecuting = schedulerFactoryBean.getCurrentlyExecutingJobs();
    		return currentlyExecuting;
    	}
    	
            public void printjobs() {
            List<JobExecutionContext> currentlyExecutingToPrint = listJobs();
            System.out.println("*** LISTJOBSTOSTRING:"+currentlyExecutingToPrint.toString());
    }
    Of course the context is being loaded via
    ApplicationContext applicationContext = new ClassPathXmlApplicationContext(new String[] {
    "classpath:/META-INF/xml file"}); in the class.

    Like I am not injecting the bean but realtively new to Spring but would like to go down this path. Couldn't find any full examples out there and the documentation pretty much stops at getting it running. If anyone has any examples of how to list all quartz jobs running that will make my week or pointing me in the correct direction. Thanks in Advance.

  • #2
    Got this to work using via application conext.

    Scheduler currentScheduler = (Scheduler)applicationContext.getBean("scheduler") ;

    Weird that it won't work with @Autowired and I assume it is lack of knowledge on my part.

    Comment

    Working...
    X