基于maven发送邮件系列(3)---maven自带的quartz实现定时发送邮件
2017-08-15 10:54
676 查看
参考别人的代码,实现自己的功能,只是为了方便查找
1还是基于(1)的基础上实现的
package com.test.mavenMethod;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.test.acount.email.AcountEmailException;
import com.test.acount.email.AcountEmailService;
public class MailJob implements Job {
@Override
public void execute(JobExecutionContext arg0) throws JobExecutionException {
ClassPathXmlApplicationContext cxa = new ClassPathXmlApplicationContext(
"acount-email.xml");
AcountEmailService acountEmailService = (AcountEmailService) cxa
.getBean("acountEmailService");
String html = "test hahha ";
try {
acountEmailService.sendEmail("XXX@XXX", "hello world",
html);
} catch (AcountEmailException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
2每隔58秒发一次,学一下表达式还是有必要的
package com.test.mavenMethod;
import java.util.Random;
import org.quartz.CronScheduleBuilder;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;
public class CronTriggerExample {
public static void main(String[] args) throws Exception {
JobDetail job = JobBuilder.newJob(MailJob.class)
.withIdentity("dummyJobName", "group1").build();
Random rand = new Random(System.currentTimeMillis());
//int secDelta = rand.nextInt(3);
int secDelta = rand.nextInt(58);
Trigger trigger = TriggerBuilder
.newTrigger()
.withIdentity("dummyTriggerName", "group1")
.withSchedule(
CronScheduleBuilder.cronSchedule("0/" + secDelta + " * * * * ?")).build();
Scheduler scheduler = new StdSchedulerFactory().getScheduler();
//CronScheduleBuilder.cronSchedule(secDelta + " 0 9 ? * 6")).build();
scheduler.start();
scheduler.scheduleJob(job, trigger);
}
}
1还是基于(1)的基础上实现的
package com.test.mavenMethod;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.test.acount.email.AcountEmailException;
import com.test.acount.email.AcountEmailService;
public class MailJob implements Job {
@Override
public void execute(JobExecutionContext arg0) throws JobExecutionException {
ClassPathXmlApplicationContext cxa = new ClassPathXmlApplicationContext(
"acount-email.xml");
AcountEmailService acountEmailService = (AcountEmailService) cxa
.getBean("acountEmailService");
String html = "test hahha ";
try {
acountEmailService.sendEmail("XXX@XXX", "hello world",
html);
} catch (AcountEmailException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
2每隔58秒发一次,学一下表达式还是有必要的
package com.test.mavenMethod;
import java.util.Random;
import org.quartz.CronScheduleBuilder;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;
public class CronTriggerExample {
public static void main(String[] args) throws Exception {
JobDetail job = JobBuilder.newJob(MailJob.class)
.withIdentity("dummyJobName", "group1").build();
Random rand = new Random(System.currentTimeMillis());
//int secDelta = rand.nextInt(3);
int secDelta = rand.nextInt(58);
Trigger trigger = TriggerBuilder
.newTrigger()
.withIdentity("dummyTriggerName", "group1")
.withSchedule(
CronScheduleBuilder.cronSchedule("0/" + secDelta + " * * * * ?")).build();
Scheduler scheduler = new StdSchedulerFactory().getScheduler();
//CronScheduleBuilder.cronSchedule(secDelta + " 0 9 ? * 6")).build();
scheduler.start();
scheduler.scheduleJob(job, trigger);
}
}
相关文章推荐
- 基于maven发送邮件系列(2)---用spring的timer实现定时发送邮件
- 基于maven发送邮件系列(5)----基于quartz定时的另一种方式:配置文件
- 基于Quartz实现简单的定时发送邮件
- 基于Maven,spring整合quartz,定时发送邮件
- 基于maven的SSH项目结合quzrtz定时发送邮件
- spring整合javamail跟quartz实现定时发送邮件
- javamail,quartz,freemarker实现定时邮件模板发送(2)
- Quartz 框架和cron表达式任务调度的例子(spring下实现定时发送邮件)
- javamail,quartz,freemarker实现定时邮件模板发送(1)
- spring与Quartz整合实现定时邮件发送
- Java系列--第四篇 基于Maven的SSME之发送邮件
- asp.net基于windows服务实现定时发送邮件的方法
- Spring 3整合Quartz 2实现定时任务一:常规整合 (基于maven构建)
- asp.net基于windows服务实现定时发送邮件的方法
- java quartz实现定时发送邮件
- 基于maven发送邮件系列(1)--简单发送邮件
- asp.net基于windows服务实现定时发送邮件的方法
- Spring 4.3.6 整合 Quartz 2.2.3 与 Java Mail1.4.0实现定时邮件发送
- SPring中quartz的配置(可以用实现邮件定时发送,任务定时执行,网站定时更新等)
- Spring 3整合Quartz 2实现定时任务一:常规整合 (基于maven构建)