views:

362

answers:

4

Hi every1! Please help me about this issue...

In my application i have calender where user can set the events for particular day.. this event info is store in database.... now i want my application to automatically send an email to that user on that assigned day....

A: 

Your servlet is running on the back-end. So all you need is to create an endless loop which is regulary checking if an email needs to be send out.

Something like this:

public void run()
{
 isRunning = true;
 while (isRunning)
 {
  performSomething();

 try
 {
  Thread.sleep(someInterval);
 }
 catch (InterruptedException e)
 {
  isRunning = false;
 }

}

Where the performSomething(); method is a synchornized method:

public synchronized void performSomething()
Drejc
+1  A: 

You have to use scheduler(quartz).Most of the applications are using that.Particularly for sending mails.

http://www.roseindia.net/quartz/index.shtml

http://www.opensymphony.com/quartz/

https://quartz.dev.java.net/

You can schedule the scheduler to do some action in particular time interval.

BlackPanther
Have a look at this.http://stackoverflow.com/questions/1654376/how-can-send-email-on-specific-day-without-running-my-gwt-servlet
BlackPanther
I won't call roseindia.net a reliable source.
BalusC
A: 

You don't explititly need the Quartz API for such a simple timer task. For this java.util.TimerTask is perfectly suitable.

BalusC
Thanks guys for your answers..using your guidelines i have understood how to achieve this functionality...instead of using Quartz API i can directly use the TimerTask...
Azhar
A: 

How about using cron jobs, you can call URLs with cron job which can be your servlet that handle the logic.

dkberktas