Stand alone quartz scheduler

Create a MyScheduler class:


public class MailScheduler implements Constants
{
private static Log log = LogFactory.getLog(MailScheduler.class);

public MailScheduler()
{
long frequency = 5 * TIME_DAY; // every 5 days
try
{
Scheduler sched = new StdSchedulerFactory().getScheduler();
sched.start();

Date startSending = DateHelper.incrementDays(new Date(), 1); //tomorrow

JobDetail jd = new JobDetail("gameReminder", Scheduler.DEFAULT_GROUP, GameScoreEntryReminderJob.class);
SimpleTrigger st = new SimpleTrigger("daily", Scheduler.DEFAULT_GROUP, startSending, null, SimpleTrigger.REPEAT_INDEFINITELY, frequency);
sched.scheduleJob(jd, st);
} catch (Exception e)
{
log.error("MailScheduler exception");
log.error(e.getMessage());
}
}


Create MyJob class:


public void execute(JobExecutionContext arg0) throws JobExecutionException
{
try
{
if (mailModule == null)
throw new NullPointerException("Please configure MailModule bean.");
List<TeamGame> teamGames = teamGameDao.fetchYesterdayGames();

for (TeamGame teamGame : teamGames)
{

List<Administrator> admins = teamGameDao.fetchAdmins(new Long(19));

for (Administrator admin : admins)
{
log.warn("Admin email is: " + admin.getUser().getEmail());
mailModule.sendGameReminder(teamGame, admin);
}
}

} catch (Exception e)
{
log.error("An error occured while executing the job - " + e.getMessage(), e);
}
}


As an Amazon Associate I earn from qualifying purchases.

My favorite quotations..


“A man should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects.”  by Robert A. Heinlein

"We are but habits and memories we chose to carry along." ~ Uki D. Lucas


Popular Recent Articles