我希望它在每个第一天发一次,每个月应该是任何一周。但是如果它是在星期天,不要解雇工作只是推迟它在第二天开火并立即终止时间表。 再次为下个月做同样的调度过程。
下面是测试环境每隔55秒计划一次的代码以及destroy方法怎么样?
QuartzPlugin.java
public class QuartzPlugin implements PlugIn {
@Override
public void destroy() {
}
@Override
public void init(ActionServlet servlet, ModuleConfig config) throws ServletException {
// define the job and tie it to our MyJob class
JobDetail job = JobBuilder.newJob(SchedulerJob.class).withIdentity("anyJobName", "group1").build();
try {
// Cron Trigger the job to run now, and then repeat every 55 secs
Trigger trigger = TriggerBuilder.newTrigger().withIdentity("anyTriggerName", "group1")
.withSchedule(CronScheduleBuilder.cronSchedule("0/55 * * * * ?"))
//Every 1 minute "0 0/1 * 1/1 * ? *"
// Every 55 Sec "0/55 * * * * ?"
// Every 5 Sec "0/5 * * * * ?"
// Every month 1st day "0 10 1-7 * *"
.build();
// Grab the Scheduler instance from the Factory
Scheduler scheduler = new StdSchedulerFactory().getScheduler();
// and start it off
scheduler.start();
// Tell quartz to schedule the job using our trigger
scheduler.scheduleJob(job, trigger);
} catch (SchedulerException e) {
e.printStackTrace();
}
}
}
SchedularJob.java
public class SchedulerJob implements Job {
private ArrayList mapList = new ArrayList();
private DAO dao = new DAO();
private HSSFWorkbook workbook = new HSSFWorkbook();
private FileOutputStream fileOut = null;
public void execute(JobExecutionContext context) throws JobExecutionException {
String dirpath = System.getProperty("user.dir").replaceAll("bin", "") + "webapps/it_email/sent/email_"
+ new SimpleDateFormat("dd-MM-yyyy").format(new Date());
String genStatus = generateExcel(dirpath);
System.out.println("genStatus::" + genStatus);
if (genStatus.equals("Y")) {
String text = "Please find attached case list dated "
+ new SimpleDateFormat("dd-MM-yyyy").format(new Date()) + "."
+ "\n\n Microsoft Excel is required to open this attachment.\n\n"
+ "Registrar Judicial,High Court of Judicature at Hyderabad.\n\n"
+ "This email is System generated. Please do not reply to this email ID.\n\n "
+ "Disclaimer:The NIC/High Court is not responsible for non-delivery of emails.";
String subject = "HIGH COURT:Availability of Case Data.";
String to = "ajaythakur2014@gmail.com";
String filetype = ".xls";
sendEmail(to, subject, text, dirpath, filetype);
System.out.println("For every 55 secs");
}
}
当上面的代码运行时,我偶尔会得到
Oracle 9i生产环境:IO Exception : The Network Adapter could not establish the connection
我想每隔55秒就会创建更多的新连接。