I m 开发一个Java App(JSF 2.0),使用Tamcat 7.0。 我需要每天发送电子邮件。 我会使用 Java邮发送电子邮件,但我如何在一定时间每天发送电子邮件。 中午?
any!
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 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();
相关问题
Spring Properties File
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 ...
What do you say of chopping type-4 UUID in this manner
Check this,
List<String> list = new ArrayList<String>();
for (int i = 0; i < 10000; i++) {
String value = (""+UUID.randomUUID().getLeastSignificantBits()).substring(3, ...
combining decorator and state pattern in java - question about OO design
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 ...
Unable to execute stored Procedure using Java and JDBC on SQL server
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 ...
Logging a global ID in multiple components
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 ...
Java Library Size
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 ...
How to get the Array Class for a given Class in Java?
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....
SQLite , Derby vs file system
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 ...
热门标签
- winforms
- combobox
- fogbugz
- java
- date
- internationalization
- asp.net
- iis
- url-rewriting
- urlrewriter
- c#
- enums
- ocaml
- haxe
- algorithm
- string
- viewstate
- .net
- c++
- c
- symbol-table
- mysql
- database
- postgresql
- licensing
- migration
- vb.net
- vb6
- declaration
- vb6-migration
- python
- psycopg2
- backup
- vmware
- virtualization
- gnu-screen
- authentication
- desktop
- excel
- xll
- cultureinfo
- regioninfo
- oracle
- client
- session
- download
- html
- virtual
- constructor
- scenarios
- perl
- full-text-search
- javascript
- ajax
- testing
- oop
- inheritance
- vim
- encapsulation
- information-hiding