Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Gail Knight   on Apr 09 In Java Category.

  
Question Answered By: Corinne Rogers   on Apr 09

If you can use servlet instead, that is a good  idea;
here sample codes required:


web.xml
...
<servlet>

<servlet-name>BirthdayNotifierServlet</servlet-name>

<display-name>BirthdayNotifierServlet</display-name>

<servlet-class>com.xyz.webapp.notification.BirthdayNotifierServlet</servlet-clas\
s>
<init-param>
<param-name>leadTime</param-name>
<param-value>86400000</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
...
--------------------------------------------------
import javax.servlet.*;
import java.io.IOException;
import com.xyz.notification.BirthdayNotifier;

public class BirthdayNotifierServlet
extends GenericServlet {
public void destroy(){
notifier.stop();
}
PasswordExpirationNotifier notifier;
public void init(ServletConfig config) throws
ServletException {
try{
super.init(config);
String leadTimeStr =
config.getInitParameter("leadTime");
notifier = new BirthdayNotifier();
if (leadTimeStr != null &&
!leadTimeStr.equals("")) {

notifier.setLeadTime(Long.parseLong(leadTimeStr));
}

notifier.start();
}catch(Exception e){
e.printStackTrace();
throw new ServletException(e.getMessage());
}
}

public void service(ServletRequest arg0,
ServletResponse arg1) throws
ServletException, IOException {
}

public String getServletInfo() {
return null;
}
}
---------------------------------------------------
import java.util.*;

import com.xyz.dao.*;
import com.xyz.dto.*;
import com.xyz.mail.SendMail;

public class BirthdayNotifier extends Thread{
public long leadTime=1000*60*60*24*1;
private SendMail mailer;
public BirthdayNotifier() {
try {
dao = new XYZDao();
mailer=new SendMail();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
private XYZDao dao;
public void run() {
while (true) {
try {
//After

accountsToBeNotifid=dao.getAccountsToBeNotifiedAboutBirthday(leadTime);
for(int
i=0;i<accountsToBeNotifid.size();i++){

mailer.postMail(dao,accountsToBeNotifid.get(i));
}
sleep(leadTime);
} catch (Exception e) {
e.printStackTrace();
}
}
}
...
}

Share: 

 

This Question has 1 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Date listener Or get search suggestion and latest updates.


Tagged: