Announcement Announcement Module
Collapse
No announcement yet.
Quartz Terminating the Process Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Quartz Terminating the Process

    Hi all,
    I am using Quartz (corn Trigger) to schedule the Batch,i am just using simple quartz to trigger the Batch and not the one which has been provided by Spring Batch.
    It runs smoothly but once i am done with the process , the trigger gets terminated, i want the process to keep on running

    Please find the code and give me a solution where am i going wrong.

    Newtrigger.java
    Code:
    public class NewTrigger {
    	protected final Log log = LogFactory.getLog(NewTrigger.class);
    	public NewTrigger(){
    		  try{
    			// Initiate a Schedule Factory
    			  log.debug("In CON");
    		        SchedulerFactory schedulerFactory = new StdSchedulerFactory();
    		        // Retrieve a scheduler from schedule factory
    		        Scheduler scheduler = schedulerFactory.getScheduler();
    		        
    		        // current time
    		        long ctime = System.currentTimeMillis(); 
    		        CronTrigger ct=new CronTrigger("cronTrigger","group2","0 0/1 * * * ?");
    		        // Initiate JobDetail with job name, job group, and executable job class
    		        JobDetail jobDetail = 
    		        	new JobDetail("abcd", "1234", QuartzSample.class);
    		        //(jobDetail==null)
    		        scheduler.scheduleJob(jobDetail,ct);
    //		        else
    //		        {
    //		        	System.out.println("Job name"+jobDetail.getName());
    //		        	System.out.println("Job group"+jobDetail.getGroup());
    //		        	System.out.println("Ct"+ct);
    //		        	scheduler.rescheduleJob(jobDetail.getName(), jobDetail.getGroup(), ct);
    ////		        }
    		        scheduler.start();
    		        
    		  }catch(Exception ex){
    			  ex.printStackTrace();
    		  }
    		
    		
    		
    	}
    	public static void main(String[] args) throws IOException{
    		
    		try {
    			new NewTrigger();
    		} catch (Exception ex) {
    			ex.printStackTrace();
    		}
    		
    	}
    
    }


    QuartzSample.java

    Code:
    public class QuartzSample implements org.quartz.Job{
    	protected final Log log = LogFactory.getLog(QuartzSample.class);
       
    	@Override
    	public void execute(JobExecutionContext arg0) throws JobExecutionException {
    		
    		try{
    			System.out.println("*********************************IN QUARTZ*********************************************************");
    			log.debug("In EXECUTE");
    			MyCommandLine.main(new String[]{});
    			
    			 
    		}catch(Exception ex){
    			ex.printStackTrace();
    		}
    		
    		
    	}
    
    }

    Here i am calling the mycommand line Main method (Custom CommandLine class)Class.


    MyCommandLine.Java
    Code:
    public static void main(String[] args) throws IOException{
    		try {
    
    			
    
    	  		MyCommandLine command = new MyCommandLine();
    		
        	  
    		
    		PropertyConfigurator.configure("log4j.properties");
    				
    		String jobPath = "4010Jobreader.xml";
    		String jobName = "EDIJob";
    		String[] parameters = new String[]{"ABCD"};
    		/*System.arraycopy(args, 0, parameters, 0, 0);*/
    		
    	
    
    
    		int result = command.startJob(jobPath, jobName, parameters);
    		
    		
    		long stopTime = System.currentTimeMillis();
    		processtime= stopTime-startTime;
    		 
        
             
            if(result==0){
            	try{
            		List<String> l =command.getAdmin();
            		  
            		if (l.size() > 0) {
        				for (Iterator<?> it = l.iterator(); it.hasNext();) {
        					IcdLoginDtl icdLoginDtl = (IcdLoginDtl) it.next();
        					String email =icdLoginDtl.getUserEmailAddr().toLowerCase().toString();
        					String content =  "  The  Batch process has been completed sucessfully ,\n please find the report log in the attachments";
        	            	SendMailWithAttachment smwa = new SendMailWithAttachment();
        	                smwa.sendMail(email, "Batch Process Status", content,reportFileName);
        				}
            		}
            		
            		
            		 
            		
            	}catch(Exception ex){
            		ex.printStackTrace();
            	}
            	 
             }
             
    		command.exit(result);		
    	
    	
    		} catch (Exception ex) {
    			ex.printStackTrace();
    		}
    	}
    Last edited by sansun2111; Sep 6th, 2010, 10:54 PM.

  • #2
    Hi,

    why you never call

    ApplicationContext context = new ClasspathApplicationContext("yourxml.xml");

    I've found some way to integrating Quartz with your spring bean.

    you can found it at my blog with "Injecting spring bean to quartz jobs" as topic.

    i hope it could help you.

    Comment

    Working...
    X