基于maven发送邮件系列(3)---maven自带的quartz实现定时发送邮件
来源:互联网 发布:java web文件管理系统 编辑:程序博客网 时间:2024/06/03 21:07
参考别人的代码,实现自己的功能,只是为了方便查找
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 {@Overridepublic 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 blocke.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);}}
阅读全文
0 0
- 基于maven发送邮件系列(3)---maven自带的quartz实现定时发送邮件
- 基于maven发送邮件系列(2)---用spring的timer实现定时发送邮件
- 基于maven发送邮件系列(5)----基于quartz定时的另一种方式:配置文件
- 基于Maven,spring整合quartz,定时发送邮件
- 基于maven发送邮件系列(1)--简单发送邮件
- 基于maven的邮件发送模块
- Maven+Spring实现邮件发送
- maven 项目 发送邮件的实现
- java quartz实现定时发送邮件
- Quartz定时任务实现自动发送邮件
- 使用QuartZ定时发送邮件
- Maven+Spring+邮件发送
- Maven邮件发送服务
- spring与Quartz整合实现定时邮件发送
- spring整合javamail跟quartz实现定时发送邮件
- maven+freemarker+velocity发送邮件
- maven项目之发送邮件
- 定时发送发送邮件
- 标准库String类型
- 查看Ubuntu的系统版本信息
- Find命令默认为深度优先搜索
- es6学习记录 set/ iterators
- Java高级特性之枚举学习总结
- 基于maven发送邮件系列(3)---maven自带的quartz实现定时发送邮件
- UVA 116 Unidirectional TSP
- 分治 C题
- 两个字符驱动实例second 及 globalfifo
- Convert Oracle Restart to Cluster
- 关闭端口脚本.bat
- 解决cxf2.2.3客户端动态调用与jdk1.7不兼容问题
- Android Studio建立jni开发环境
- 基于ajaxupload的多文件上传