Hiya all,
I have a method that returns a list of items called findItemByPIdEndDate() and its found inside MngtImpl.java class. Now I'd like to execute this method every once in a while, hourly lets say so here is what I did so far :
This is CronSchedule.java
import org.quartz.CronTrigger;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.JobDetail;
public class CronSchedule {
public CronSchedule ()throws Exception {
SchedulerFactory sf=new StdSchedulerFactory();
Scheduler sched=sf.getScheduler();
JobDetail jd=new JobDetail("job1","group1",CronJob.class);
CronTrigger ct=new CronTrigger("cronTrigger","group2","0 * * * * ?");
sched.scheduleJob(jd,ct);
sched.start();
}
public static void main(String args[]){
try{
new CronSchedule(); //Class where cron is created
}catch(Exception e){}
}
}
Now with this one I have problems. This class is called from the class above based on time constraints (* in parenthesis) and it executes method of MngtImpl class.
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import com.rosa.MngtImpl;
public class CronJob implements Job {
public void execute(JobExecutionContext arg0) throws JobExecutionException {
try {
MngtImpl pers = new MngtImpl();
pers.findItemByPIdEndDate();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Here is the method I try to invoke from the above class. This method is found inside class named MngtImpl.java
public List<Long> findItemByPIdEndDate() throws Exception {
List<Long> list = null;
try{
Session session = sessionFactory.getCurrentSession();
Query query = session.getNamedQuery("endDateChecker");
list = query.list();
}catch (HibernateException e){
throw new DataAccessException(e.getMessage());
}
return list;
}
Now here is what I'd like to do. I need to run this this above method based on some amount of time(which I could specify anytime). I need to make a bean inside bean factory xml file that actually instances this scheduler and calls this method, and I tried this by calling CronJob.java from CronScheldule.java which calls method from another class and I made a bean which maybe working or not
<bean id="cronSchedule" class="com.mypackage.CronSchedule">
</bean>
But its not working as I expected and its pretty complicated, may I get some help with code please? Thank you
I encounter the following exception:
java.lang.NullPointerException 11:10:46,410 ERROR [STDERR]
at com.packftc.RulesManager.exception(RulesManager.java:25) 11:10:46,410 ERROR [STDERR]
at org.drools.agent.RuleAgent$2.run(RuleAgent.java:442) 11:10:46,410 ERROR [STDERR]
at java.util.TimerThread.mainLoop(Unknown Source) 11:10:46,410 ERROR [STDERR]
at java.util.TimerThread.run(Unknown Source)
This is obviously wrong way of doing this I've tried like zilion things so far : Here is what I'm trying to do in simple words, I want to execute findItemByPIdEndDate() method from MngtImpl class every lets say minute. Method is functioning properly I wrote a test and it passes it. So what do I do now ? Thank you