Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Regarding Job Scheduler in JSF

 
Srilatha Avula
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,

I am using JSF to enter the contact details of employees like First Name,Last Name,Date Of Joining,Date of Birth,Email etc.. into the MySQL Database ,also to update those details when needed.

Now I want to run the Job Scheduler on the date of birth of the employee and send him wishes to his mail id.The problem I am facing here is how to run that job continously(Using Tomcat Server which will be ON) without invoking that manually by me

Please help me in this regard..


Thanks and Regards,
Srilatha
 
Max Jonas Werner
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Srilatha,

I can't quite figure what that job scheduler would have to do with your JSF application. Could you be a bit more specific on the functioning of the scheduler?

Max
 
Tim Holloway
Bartender
Posts: 18419
60
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you're describing is basically a batch process, and technically, that's not what web servers are intended to do. However, it's usually more convenient to bundle the batch process into a web app than to run a separate stand-alone application, so there's some well-established ways of doing this.

The first thing to realize is that you'll need an independent thread to manage this process. Normally, web apps only respond to external requests and sleep the rest of the time. What you want is to have a process that wakes up and runs due to an internal trigger.

To do this, you can spawn a thread in the init() method of a servlet. If you don't have a servlet you can modify, write what I call a "null servlet", which is a servlet that has no request handlers, just an init() method. Make sure you set up web.xml so that it will automatically start up when the webapp starts. You don't have to map any URLs to it, since it won't be handling URL requests.

The simplest sort of service thread would simply sleep until a certain time of day (using Thread.sleep or something like that). When it woke up, it would look for work, and do whatever needed to be done.

More complex scheduling can be done using the Quartz scheduler. Quartz is a freely-available open-source general-purpose scheduler that can be embedded in just about any sort of Java application (web or not). Quartz is a lot like the Unix "cron" utility. It supports calendars and complex scheduling, including the use of a database to maintain the event schedules.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!