views:

60

answers:

1

I have made task using Spring @Scheduled annotation, but for some reason it is executing task twice. My Spring Framework version is 3.0.2.

@Service
public class ReportService {

    @Scheduled(fixedDelay=1000 * 60 * 60* 24)
    @Transactional
    public void dailyReportTask()
    {
        ... code here ...
    }

}

Here is my XML:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd"&gt;
    <task:scheduler id="taskScheduler" />
    <task:executor id="taskExecutor" pool-size="1" />
    <task:annotation-driven executor="taskExecutor"
        scheduler="taskScheduler" />
</beans>
A: 

Where are you actually running it? Your PC? Single server? 2 x load-balanced app servers?

Could be it's running on (a) your PC and (b) your server, so it just looks like it's running twice, if you see what I mean: it's correctly running once, just on two distinct locations.

Brian
Just running on my development machine ... it has only one istance running ... I run it from eclipse ...
newbie
Is it running on an app server on your machine, e.g. Tomcat, JBoss, Glassfish, to which you deploy from Eclipse? Or is it running as a standalone app? Eclipse may be letting you run a 2nd app while a first one is still actually running.
Brian
Its Eclipse embedded tomcat 6 server. And Im usre I have just one instance running, i checked it from task manager.
newbie
Interesting. If it was me, I would set up a standalone Tomcat 6 on my PC and deploy from Eclipse to that instead. If the problem still manifests, at least you can be sure that's a code/application problem. I'd also maybe change the scheduling to run once per hour to see if it continues to run the new schedule twice even on that separate deployed instance
Brian