1 17 18 package org.quartz.examples.example11; 19 20 import java.util.Date ; 21 22 import org.quartz.JobDetail; 23 import org.quartz.Scheduler; 24 import org.quartz.SchedulerFactory; 25 import org.quartz.SchedulerMetaData; 26 import org.quartz.SimpleTrigger; 27 import org.quartz.impl.StdSchedulerFactory; 28 29 import org.apache.commons.logging.LogFactory; 30 import org.apache.commons.logging.Log; 31 32 37 public class LoadExample { 38 39 private int _numberOfJobs = 500; 40 41 public LoadExample(int inNumberOfJobs) { 42 _numberOfJobs = inNumberOfJobs; 43 } 44 45 public void run() throws Exception { 46 Log log = LogFactory.getLog(LoadExample.class); 47 48 SchedulerFactory sf = new StdSchedulerFactory(); 50 Scheduler sched = sf.getScheduler(); 51 52 log.info("------- Initialization Complete -----------"); 53 54 log.info("------- (Not Scheduling any Jobs - relying on XML definitions --"); 55 56 String schedId = sched.getSchedulerInstanceId(); 57 58 for (int count=1; count <= _numberOfJobs; count++) { 60 JobDetail job = new JobDetail("job" + count, "group1", 61 SimpleJob.class); 62 job.getJobDataMap().put(SimpleJob.DELAY_TIME, 60000L); 64 job.setRequestsRecovery(true); 67 SimpleTrigger trigger = new SimpleTrigger("trigger_" + count, "group_1"); 68 trigger.setStartTime(new Date (System.currentTimeMillis() + 10000L 69 + (count * 100))); 70 sched.scheduleJob(job, trigger); 71 if (count % 25 == 0) { 72 log.info("...scheduled " + count + " jobs"); 73 } 74 } 75 76 77 log.info("------- Starting Scheduler ----------------"); 78 79 sched.start(); 81 82 log.info("------- Started Scheduler -----------------"); 83 84 log.info("------- Waiting five minutes... -----------"); 85 86 try { 88 Thread.sleep(300L * 1000L); 89 } catch (Exception e) { 90 } 91 92 log.info("------- Shutting Down ---------------------"); 94 sched.shutdown(true); 95 log.info("------- Shutdown Complete -----------------"); 96 97 SchedulerMetaData metaData = sched.getMetaData(); 98 log.info("Executed " + metaData.numJobsExecuted() + " jobs."); 99 } 100 101 public static void main(String [] args) throws Exception { 102 103 int numberOfJobs = 500; 104 if (args.length == 1) { 105 numberOfJobs = Integer.parseInt(args[0]); 106 } 107 if (args.length > 1) { 108 System.out.println( 109 "Usage: java " + 110 LoadExample.class.getName() + 111 "[# of jobs]"); 112 return; 113 } 114 LoadExample example = new LoadExample(numberOfJobs); 115 example.run(); 116 } 117 118 } | Popular Tags |