Thursday, September 18, 2008

Quartz Scheduler First Impression

Quartz Scheduler is used to make a scheduling job. In this post we will make a scheduler to generate daily report for persons report that have we made before for each one minute. Here we start. Download first Quartz library and copy it into spring lib folder. In package com.ndung.service create two interfaces named EODManager.java and Executable.java.


package com.ndung.service;

public interface EODManager {
void executeEOD();
}

package com.ndung.service;

public interface Executable {
void execute() throws Exception;
}

In package com.ndung.service.impl add a class named EODManagerImpl.java

package com.ndung.service.impl;

import java.util.List;
import com.ndung.service.EODManager;
import com.ndung.service.Executable;

public class EODManagerImpl implements EODManager {
private List<Executable> executables;
public void setExecutables(List<Executable> executables) {
this.executables = executables;
}
public void executeEOD() {
for (Executable executable : executables) {
try { executable.execute(); }
catch (Exception e) { e.printStackTrace(); }
}
}
}


Edit PersonManager.java and PersonManagerImpl.java like belows.

public interface PersonManager extends Manager, Executable{
...
public void generateDailyReport();
}

PersonManagerImpl.java

public void generateDailyReport() {
File dirPath = new File("report");
if (!dirPath.exists()) {
dirPath.mkdirs();
}
File filePath = new File(dirPath+"/PersonReport.pdf");
Map<String, Object> mapReport = new HashMap<String, Object>();
mapReport.put("title", "Persons Report");
mapReport.put("date", new Date());
ReportUtil.generateReport("PersonsReport.jrxml", filePath.getAbsolutePath(),
dao.getPersons(null), mapReport, "pdf");
}
public void execute() throws Exception {
generateDailyReport();
}

Add a bean in applicationContext-service.xml for eodManager.

<bean id="eodManager" class="com.ndung.service.impl.EODManagerImpl">
<property name="executables">
<list>
<ref bean="personManager" />
</list>
</property>
</bean>

In folder web/WEB-INF create applicationContext file named applicationContext-schedule.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref local="cronTrigger" />
</list>
</property>
</bean>

<bean id="cronTrigger"
class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="methodInvokingJobDetail" />
</property>
<property name="cronExpression">
<value>0 0/1 * * * ?</value>
</property>
</bean>

<bean id="methodInvokingJobDetail"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref bean="eodManager" />
</property>
<property name="targetMethod">
<value>executeEOD</value>
</property>
</bean>
</beans>

Run our application and check out if there a file in report/PersonReport.pdf in our computer.

18 comments:

Anonymous said...

[url=http://tinyurl.com/y9qxher][img]http://i069.radikal.ru/1001/35/75e72b218708.jpg[/img][/url]



Related keywords:
buy cheap prescription Tramadol
buy Tramadol cheap
next day air ups Tramadol
50 mg Tramadol
what does Tramadol look like
Tramadol online without presciption
key Tramadol
Tramadol side efforts
[url=http://www.zazzle.com/AlexanderBlack]Tramadol side efforts [/url]
[url=http://seobraincenter.ru]http://seobraincenter.ru[/url]
Tramadol for opiate withdrawal
buying Tramadol online
50 mg Tramadol
Tramadol no prescription overnight delivery
debt negotiation buy Tramadol
purchase Tramadol
buy no perscription Tramadol

Anonymous said...

I think, that you are mistaken. I can defend the position. Write to me in PM, we will discuss.

Anonymous said...

I can not participate now in discussion - there is no free time. But I will return - I will necessarily write that I think on this question.

Anonymous said...

Lovingly done is richer reconsider than extravagantly said.

Anonymous said...

Well done is better than spectacularly said.

Anonymous said...

Splendidly done is better than comfortably said.

Anonymous said...

A man who dares to atrophy one hour of time has not discovered the value of life.

[url=http://savemrmorales.webs.com/apps/profile/profilePage?id=54280822]Ana[/url]


Gilda

Anonymous said...

We should be meticulous and discriminating in all the information we give. We should be especially careful in giving guidance that we would not think of following ourselves. Most of all, we ought to evade giving advise which we don't imitate when it damages those who depreciate us at our word.

nail sets

[url=http://nail-sets-43.webs.com/apps/blog/]nail sets[/url]

Anonymous said...

A human beings begins scathing his wisdom teeth the senior without surcease he bites out more than he can chew.

Anonymous said...

To be a adroit charitable being is to be enduring a amiable of openness to the in the seventh heaven, an skill to guardianship uncertain things beyond your own manage, that can govern you to be shattered in hugely exceptionally circumstances for which you were not to blame. That says something exceedingly outstanding about the get of the principled autobiography: that it is based on a trustworthiness in the unpredictable and on a willingness to be exposed; it's based on being more like a weed than like a sparkler, something fairly dainty, but whose mere particular attractiveness is inseparable from that fragility.

Anonymous said...

To be a noble benign being is to procure a kind of openness to the world, an cleverness to trust unsure things beyond your own control, that can take you to be shattered in hugely outermost circumstances for which you were not to blame. That says something uncommonly outstanding thither the condition of the righteous autobiography: that it is based on a trustworthiness in the fitful and on a willingness to be exposed; it's based on being more like a spy than like a jewel, something fairly dainty, but whose acutely item attractiveness is inseparable from that fragility.

Anonymous said...

In everyone's life, at some pass‚, our inner throw goes out. It is then break asunder into zeal beside an face with another benign being. We should all be glad for those people who rekindle the inner spirit

Anonymous said...

Restaurants in the United States. Search or browse list of restaurants. http://restaurants-us.com/al/Montgomery/Kitchen/36105/

Anonymous said...

Directory of insurance agencies organized by states http://insuranceinstates.com/florida/Coral%20Gables/Prudential%20Insurance%20Co/33134/

Anonymous said...

My brother suggested I would possibly like this website.

He used to be totally right. This submit actually made my
day. You can not imagine simply how much time I had spent
for this information! Thanks!

my webpage coffee flavorings

Anonymous said...

I was suggested this web site by my cousin. I'm not sure whether this post is written by him as no one else know such detailed about my trouble. You are wonderful! Thanks!

my homepage http://www.besteyecreamfordarkcircles.net/lifestyle/the-issue-of-spending-on-baby-clothing

Anonymous said...

http://eekshop.com
Finding A Lover
This can be going to be the places all your family members come to mind to understand more about as part about your daily routine,including the offices that your family hang around town allowing you to have That means at have the desired effect at church at going to be the nightclub allowing an individual your colleagues at the fitness where your family have the desired effect around town and also so many of the various great sources as well as for potential lovers. If you have singles all around the your social corporations this can be of assistance Although a number of people worry about it's some of the best do not for additional details on have a go at your luck providing some one your partner's friends or otherwise family.

ciri ciri vimax asli said...

thanks I like it this really good information
Vimax Canada Vimax asli