Announcement Announcement Module
Collapse
No announcement yet.
Task Scheduler seems to be running an annotated method twice Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Task Scheduler seems to be running an annotated method twice

    Hi Folks -

    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'm sure it's a configuration issue on my end, but I'm stumped.. can anyone offer any ideas?


    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.

    Matt

  • #2
    Fyi

    This is a bug fixed in 3.0.1, to be release soon.

    Comment


    • #3
      I am still getting this issue with 3.1.1.RELEASE!

      it has been fixed?

      Comment

      Working...
      X