Hi Guys, I hv a servlet which shoots an email with some data taken from database.I want this servlet to shoot the email thrice in a day at specified time interval.In short i need to invoke a servlet at specified time intervals.How do i do it? I hv a timer class with an interface TimerListener.But how to invoke a servlet as an object? Can anyone help me. public class Timer extends Thread { TimerListener m_timerListener; int m_cycle; Object m_object; public Timer(TimerListener timerListener, int cycle) { m_timerListener = timerListener; m_cycle = cycle; m_object = null;
} public Timer(TimerListener timerListener, int cycle, Object object) { m_timerListener = timerListener; m_cycle = cycle; m_object = object; }
public void run() { while (true) { try {sleep(m_cycle * 1000); } catch (InterruptedException ex) {ex.printStackTrace();} // Fire a TimerEvent
if (m_timerListener != null) { m_timerListener.TimerEvent(m_object); } } //while ends }//run ends }//class ends public interface TimerListener {
void TimerEvent(Object object);
}
Thanx in advance !!!1 Bye, Manish
Frank Carver
Sheriff
Joined: Jan 07, 1999
Posts: 6913
posted
0
The Java Ranch has a naming policy, described here and "manish_dalal" is not a valid name; Please use a space to separate your two names. Thanks.
I'm puzzled why you feel you need to use a servlet to send an email. I would strongly recommend refactoring your code into one or more "email" classes which are used by the servlet, and also used by the timer. This is a classic example of why servlets should contain no application-specific code, but merely be a thin layer which interfaces your "business" classes to HTTP and HTML.
Anonymous
Ranch Hand
Joined: Nov 22, 2008
Posts: 18944
posted
0
Hi Frank, Well,I need to finally include this servlet in an XMLSERVER for my porject.I did not get you what do u mean by generating email classes in servlet & timer.May be I am a begineer level programmer to understand your advice. Manish
Siva Jagadeesan
Ranch Hand
Joined: Oct 31, 2000
Posts: 160
posted
0
Dear Manish : What Mr.Frank means is use servlets only for controllin the flow and not for any specific business logic . Put the business logic in a serperate class and use it in the servlet. Try to use MVC model Thank Siva Even i am beginner , if anything is wrong let me know