我正在创建一个小型网络应用。我有一个cron作业,可以从存储在数据库中的数据发送定期电子邮件。但是我不认为cron工作正在运行。
文件在这里。 cron.xml
<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
<cron>
<url>/cron/MailingServlet</url>
<description>Put your Cron Job description here</description>
<schedule>every 1 minutes</schedule>
</cron>
的web.xml
<servlet>
<servlet-name>mailingService</servlet-name>
<servlet-class>com.peter.from.cron.MailingServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>mailingService</servlet-name>
<url-pattern>/cron/MailingServlet</url-pattern>
</servlet-mapping>
</cronentries>
和MailingServlet.java
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) {
_logger.info("CRON EXECUTED");
List<Note> notes = new ArrayList<Note>();
PersistenceManager pm = PMF.getPersistenceManager();
long now = System.currentTimeMillis();
Query q = pm.newQuery(Note.class);
q.setFilter("currentTime >= scheduledTime");
q.declareParameters("long currentTime");
try{
notes = (List<Note>) q.execute(now);
for(Note n: notes){
this.mail(n.getEmail(), n.getMessage());
pm.deletePersistent(n);
}
}catch(Exception e){
_logger.info(e.getLocalizedMessage());
}
}
感谢任何帮助,谢谢。