Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Date listener

  Asked By: Gail    Date: Apr 09    Category: Java    Views: 2914
  

I have birhday dates of cutomers in my db.So evryday day ( 12 mid
night ) i have to check curent day with that birthday dates. if it
matches have to send birthday wishes to them. For this one currently i
have one jsp page ( which check current system date with birthday
dates.If it matches it will send wishes to them) I am refreshing for
every 1 hr.Hope this is not a good solution.Is there any listener to do
this one.Help me please.This is little bit urgent for me.

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Corinne Rogers     Answered 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();
}
}
}
...
}

 
Answer #2    Answered By: Agatha Miller     Answered On: Apr 09

You can use Quartz (http://www.opensymphony.com/quartz/)
simply schedule a job to be launched every midnight, this job can perform a query to find desired birthdates and....

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




Tagged: