Stack ScheduledTask Help

Support and Announcements for the Tech Java Web Application Platform (setup, configuration, bugs, feedback).
Locked
tlmaravilla
New Member
Posts: 25
Joined: Tue Feb 01, 2011 5:34 pm
Location: Riverton, UT

Stack ScheduledTask Help

#1

Post by tlmaravilla »

We are still on Stack 2.2 RC5 and are using tomcat locally and deploying to WAS. At this point, we are using the stack ScheduledTask (due to issues with Spring/Quartz within WAS), our serviceBeanContext.xml:
...
<bean id="activationSvc" class="org.lds.ics.mtm.firewall.service.ActivationServiceImpl" scope="prototype">
</bean>
...
<util:list id="scheduledTasks">
<bean class="org.lds.stack.spring.scheduling.ScheduledTask">
<property name="period" value="10000" />
<property name="delay" value="10000" />
<property name="runnable">
<bean class="org.springframework.scheduling.support.MethodInvokingRunnable">
<property name="targetObject" ref="activationSvc" />
<property name="targetMethod" value="checkGpmLoadDate" />
</bean>
</property>
</bean>
</util:list>


Initially we thought that a simple delay would work for our needs, but now we are needing to run tasks at certain times, such as 23:50, such as a GPM DB daily refresh check, so what would be easier:

- Trying to get Quartz to run within WAS
- Have Quartz run as a stand-alone app on linux, which calls our methods within WAS
- Upgrade to stack 3.1 and replace WAS with Tomcat in prod

Is there a solution within stack ScheduledTask that I am missing?

Thoughts?
YoungstromMJ
Member
Posts: 101
Joined: Mon Mar 29, 2010 3:11 pm
Location: Utah, USA

#2

Post by YoungstromMJ »

Yes there is a solution to this. You can do the following:

1. Extend org.lds.stack.spring.scheduling.ScheduledTask
2. Override the getDelay() method to dynamically determine when you want it to start. Use logic such as:
Time at 23:50 today - now.
This will tell the scheduler to delay running until 23:50 tonight.
3. Set the period to 24 hours.
4. Set the "fixedRate" property in ScheduledTask to "true".

That should allow you to create a task that runs every day at 23:50.

Mike
tlmaravilla
New Member
Posts: 25
Joined: Tue Feb 01, 2011 5:34 pm
Location: Riverton, UT

#3

Post by tlmaravilla »

Mike,

In your directions:
2. Override the getDelay() method to dynamically determine when you want it to start. Use logic such as:
Time at 23:50 today - now.
I am assuming that I need to override the getDelay(), then call super.setDelay(long delay), right?
YoungstromMJ
Member
Posts: 101
Joined: Mon Mar 29, 2010 3:11 pm
Location: Utah, USA

#4

Post by YoungstromMJ »

Probably the more appropriate thing to do would be to Override the constructor and call setDelay and setFixedRate from there.
tlmaravilla
New Member
Posts: 25
Joined: Tue Feb 01, 2011 5:34 pm
Location: Riverton, UT

#5

Post by tlmaravilla »

After talking with Mike, he put together this class:

public class SpecificTimeScheduledTask extends ScheduledTask {

private static Logger logger = Logger.getLogger(SpecificTimeScheduledTask.class);

@PostConstruct
public void init() {
super.setDelay(calculateDelay());
super.setFixedRate(true);
super.setPeriod(86400000);
}

private long calculateDelay() {
Calendar loadDateCal = new GregorianCalendar();
loadDateCal.setTime(new Date());
loadDateCal.set(Calendar.HOUR_OF_DAY, 23);
loadDateCal.set(Calendar.MINUTE, 59);

long currTm = System.currentTimeMillis();
long delayTm = loadDateCal.getTimeInMillis() - currTm;

logger.info("loadDateCal time (ms): " + loadDateCal.getTimeInMillis() + ", currTm: : " + currTm + ", delayTm: "
+ delayTm);
return delayTm;
}
}

serivceBeanContext.xml:
<util:list id="scheduledTasks">
<bean class="org.lds.ics.mtm.firewall.service.SpecificTimeScheduledTask">
<property name="runnable">
<bean class="org.springframework.scheduling.support.MethodInvokingRunnable">
<property name="targetObject" ref="activationSvc" />
<property name="targetMethod" value="checkGpmLoadDate" />
</bean>
</property>
</bean>
</util:list>

Thanks Mike!
Locked

Return to “Java Web Project Support (Stack)”