Description
Matt Young opened SPR-6859 and commented
I posted this on the forum, but with no response... I wondered if you all could look into it.
I was stubbing out some code that I'd like to run on a schedule, and just to test it, I have it running once every 60 seconds. I noticed that in my logging, the method seems to be executed twice. To make sure it wasn't a logging issue, I put a static int counter into the class and have it increment on each call. So I can confirm the method is actually being run twice.
I suspect that this is something like doing a context:component-scan twice-over and resulting in double execution, but can't seem to locate the problem. I thought I would check first if there were any pointers.
The class
Code:
/**
-
Date: Feb 15, 2010
-
Time: 10:54:36 AM
*/
@Component
public class DataHarvestingServiceImpl implements DataHarvestingService {
private static final Logger logger = Logger.getLogger(DataHarvestingServiceImpl.class);private static int count = 0;
@Override
// Every night at 1 AM
//@Scheduled
(cron = "* * 1 * * ?")@Scheduled
(cron = "0 * * * * ?")
public void collectSocialMediaData() {
logger.info("Starting data retrieval at " + new Date(System.currentTimeMillis()));logger.info("Finished media data retrieval at " + new Date(System.currentTimeMillis())); System.out.println("count is " + count++);
}
}
The configuration
Code:
<?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">
<!-- This is the bit of configuration that allows spring to search for annotations
that indicate that particular methods should be run at particular times. -->
<task:scheduler id="searchScheduler"/>
<task:executor id="searchExecutor" pool-size="1"/>
<task:annotation-driven executor="searchExecutor" scheduler="searchScheduler"/>
</beans>
The output I see:
Code:
11316 [searchScheduler-1] INFO com.vodori.cms.feature.socialMedia.service.impl.DataHarvestingServiceImpl - Starting data retrieval at Mon Feb 15 14:56:00 CST 2010
11321 [searchScheduler-1] INFO com.vodori.cms.feature.socialMedia.service.impl.DataHarvestingServiceImpl - Finished media data retrieval at Mon Feb 15 14:56:00 CST 2010
count is 0
11321 [searchScheduler-1] INFO com.vodori.cms.feature.socialMedia.service.impl.DataHarvestingServiceImpl - Starting data retrieval at Mon Feb 15 14:56:00 CST 2010
11321 [searchScheduler-1] INFO com.vodori.cms.feature.socialMedia.service.impl.DataHarvestingServiceImpl - Finished media data retrieval at Mon Feb 15 14:56:00 CST 2010
count is 1
71318 [searchScheduler-1] INFO xxx.service.impl.DataHarvestingServiceImpl - Starting data retrieval at Mon Feb 15 14:57:00 CST 2010
71318 [searchScheduler-1] INFO xxx.service.impl.DataHarvestingServiceImpl - Finished media data retrieval at Mon Feb 15 14:57:00 CST 2010
count is 2
71318 [searchScheduler-1] INFO xxx.service.impl.DataHarvestingServiceImpl - Starting data retrieval at Mon Feb 15 14:57:00 CST 2010
71318 [searchScheduler-1] INFO xxx.service.impl.DataHarvestingServiceImpl - Finished media data retrieval at Mon Feb 15 14:57:00 CST 2010
count is 3
Any insight very much appreciated.
Affects: 3.0 GA
Reference URL: http://forum.springsource.org/showthread.php?t=84747
Issue Links:
- ScheduledAnnotationBeanPostProcessor registers schedules twice in web application [SPR-6656] #11322 ScheduledAnnotationBeanPostProcessor registers schedules twice in web application ("duplicates")
- CronSequenceGenerator fails to accurately compute earliest next date when using second expression [SPR-9459] #14094 CronSequenceGenerator fails to accurately compute earliest next date when using second expression
- CronTrigger is not triggered at correct time [SPR-7004] #11669 CronTrigger is not triggered at correct time
5 votes, 21 watchers