I m 开发一个Java App(JSF 2.0),使用Tamcat 7.0。 我需要每天发送电子邮件。 我会使用 Java邮发送电子邮件,但我如何在一定时间每天发送电子邮件。 中午?
any!
由于Tomcat是一个简单的服务器,不提供在时间安排上修建的设施,也不支持手提的EJB@Sequle
说明,你需要管理日程安排,或使用Kartz等第3个政党图书馆,或者只将工作委托给基本的操作系统平台,像Windows平台和Cron平台的预定设施。
在使用标准案文<<<<<<>>时,您可使用http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContextListener.html” rel=“nofollow noreferer”>> 代码> 这里的例子有: 在<密码>的<类别”中,仅看上去:@WebListener
public class Config implements ServletContextListener {
private ScheduledExecutorService scheduler;
@Override
public void contextInitialized(ServletContextEvent event) {
long secondsUntilNoon = calculateItSomehow();
long secondsPerDay = 60 * 60 * 24;
scheduler = Executors.newSingleThreadScheduledExecutor();
scheduler.scheduleAtFixedRate(new Mailer(), secondsUntilNoon, secondsPerDay, TimeUnit.SECONDS);
}
@Override
public void contextDestroyed(ServletContextEvent event) {
scheduler.shutdownNow();
}
}
public class Mailer implements Runnable {
@Override
public void run() {
// Do your mailing job here.
}
}
See also:
最佳和灵活的解决办法是使用Quartz列表器。 你们都需要创造一份工作岗位,并根据你的具体要求启动工作。
For details refer to the official documents
http://quartz-scheduler.org/documentation/quartz-2.1.x/tutorials/"rel=“nofollow> 图瓦卢
You can use the timer task http://www.ibm.com/developerworks/java/library/j-schedule/index.html
Or Quartz scheduler http://www.quartz-scheduler.org/download/
you can schedule you email your Quartz scheduler as Umesh suggested, you can use the below code to start off:
//set quartz properties in propreties file or map
SchedulerFactory schedFact = new StdSchedulerFactory();
Scheduler sched = schedFact.getScheduler();
//set these parameters
JobDetail jobDetail = new JobDetail( "Email Job" , Scheduler.DEFAULT_GROUP , MyEmailAction.class );
//add data or objects you may require in your scheduled job
JobDataMap dataMap = jobDetail.getJobDataMap();
dataMap.put("mydata", myDataObj);
SimpleTrigger st = new SimpleTrigger();
st.setName("DeployTrigger");
//set the time when you want to send email
st.setStartTime( java.util.Date );
sched.scheduleJob( jobDetail , st );
sched.start();
Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...
Check this, List<String> list = new ArrayList<String>(); for (int i = 0; i < 10000; i++) { String value = (""+UUID.randomUUID().getLeastSignificantBits()).substring(3, ...
I am in the middle of solving a problem where I think it s best suited for a decorator and a state pattern. The high level setting is something like a sandwich maker and dispenser, where I have a set ...
I have been trying to execute a MS SQL Server stored procedure via JDBC today and have been unsuccessful thus far. The stored procedure has 1 input and 1 output parameter. With every combination I ...
I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...
If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...
I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....
I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...