Stack ScheduledTask Help

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

Stack ScheduledTask Help

Postby tlmaravilla » Mon Feb 07, 2011 4:39 pm

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: 100
Joined: Mon Mar 29, 2010 2:11 pm
Location: Utah, USA

Postby YoungstromMJ » Mon Feb 07, 2011 5:02 pm

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

Postby tlmaravilla » Tue Feb 08, 2011 3:07 pm

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: 100
Joined: Mon Mar 29, 2010 2:11 pm
Location: Utah, USA

Postby YoungstromMJ » Tue Feb 08, 2011 3:18 pm

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

Postby tlmaravilla » Tue Feb 08, 2011 3:32 pm

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!


Return to “Java Web Project Support (Stack)”

Who is online

Users browsing this forum: No registered users and 1 guest