spring quartz xml中配置任务

使用spring quartz集群时,有一些任务已经存在,可以通过配置的方式将任务持久化到数据库中


        
            
        
        
        
        
        	
        		
        	
        	
     
    
    
    
    	 
			com.xlwzsoft.timepieceTask.task.DBClusterQuartzJobBean 
		
		   
			   
				  
				 
				
			
		 
    
    
        
        
        
//com.xlwzsoft.timepieceTask.task.DBClusterQuartzJobBean的内容:
public class DBClusterQuartzJobBean extends QuartzJobBean {  
    protected final Log logger = LogFactory.getLog(getClass());  
    private String targetObject;  
    private String targetMethod;
    private String taskInfoId;
    private String taskType;
    private String taskTime;
    private ApplicationContext ctx;  
  
    @Override  
    protected void executeInternal(JobExecutionContext context)  
            throws JobExecutionException {  
        try {  
            logger.info("bean:"+targetObject);
//            targetObject=context.getMergedJobDataMap().getString("targetObject");
//            targetMethod=context.getMergedJobDataMap().getString("staticMethod");
            //强转类型 由spring中获得要调用的bean类
            Job otargetObject = (Job)SpringUtil.getBean(targetObject);//ctx.getBean(targetObject);  
//            Method m = null;  
            //执行类的execute方法
        	otargetObject.execute(context);
        	//判断当前任务是否执行下一次
        	executeNext();
//                m = otargetObject.getClass().getMethod(targetMethod, JobExecutionContext.class);  
//                m.invoke(otargetObject, context);  
        } catch (Exception e) {
        	logger.info(e.getMessage());
        	exceptionError(e.getMessage());
        }  
    }

jobDataMap中的数据在DBClusterQuartzJobBean中需声明,并且实现get/set方法,方可在方法中获得,targetObject所指向的bean,需要实现Job接口,并且targetMethod必须为execute

你可能感兴趣的:(spring quartz xml中配置任务)