Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-10830

Scheduled tasks seem to run twice (Not in a Web environment)

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Cannot Reproduce
    • Affects Version/s: 3.2.3
    • Fix Version/s: None
    • Component/s: Core
    • Labels:
    • Last commented by a User:
      true

      Description

      The problem is, using @Scheduled(cron = "${cron.expression}") run twice. I am using setters variables ( or variables with @Autowired) that are Datasources. One time my setters variables are null, the other time these variables ar not null!

      In the Main Program I only use:
      --------------------------------

      public class MainImport {

      private static ClassPathXmlApplicationContext classPathXmlApplicationContext;

      public static void main(String[] args) throws InterruptedException

      { classPathXmlApplicationContext = new ClassPathXmlApplicationContext("/config/springJob.xml"); }

      }

      In SpringJob.xml:
      -----------------

      <task:annotation-driven executor="taskExecutor" scheduler="taskScheduler"/>
      <task:scheduler id="taskScheduler" pool-size="20"/>
      <task:executor id="taskExecutor" pool-size="20"/>

      <context:property-placeholder location="classpath:/config/*.properties" />
      <context:component-scan base-package="dbimport" />

      <!-- *** DATASOURCES *** -->
      <!-- ******************* -->

      <bean id="myOracle" class="dbimport.dao.DataSourceOracle"
      p:oracleDriver="${oracleW4BIS.driver}"
      p:oracleUrl="${oracleW4BIS.url}"
      p:oracleUsername="${oracleW4BIS.username}"
      p:oraclePassword="${oracleW4BIS.password}"
      />

      <!-- Which JOB should be executed -->
      <bean id="JobToExecuteID" class="dbimport.job.JobMapping"
      p:oracleDatasource-ref="myOracle"
      />

      Now in In JobMapping:
      ---------------------

      public void setOracleDatasource( DataSourceOracle dsOracle) {
      this.dsOracle = dsOracle;
      }

      @Scheduled(cron = "${cron.expression}")
      public void executeJob() {
      List<Partner> lPartners = null;

      System.out.println("execute() --> Executing Job ");
      if ( dsOracle == null )

      { System.out.println("FIRST TIME --> " + new Date() + " ... Oracle Connection is = null "); }

      else

      { System.out.println("SECOND TIME --> " + new Date() + " ... DATOS = " + dsOracle.getTestString()); callMathod(dsOracle); }

      }

      Notice that cron.expression is configured to run each 30 seconds.
      and my output shows as:

      SECOND TIME Tue Aug 13 10:51:30 CEST 2013 ... DATOS = oracle.jdbc.OracleDriver, jdbc:oracle:thin:@139.X.Y.Z:1001:MYDB, MyUser, MyPassword
      FIRST TIME --> Tue Aug 13 10:51:30 CEST 2013 ... Oracle Connection is = null

      This is not a Web Application, I don't have Tomcat or something similar.
      I am using Windows´7, 64 Bits, Java 7.
      Is there a similar problem with this environment?

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            jesmac Macias De La Rosa Jesus Gerardo
            Last updater:
            Spring Issues Spring Issues
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Days since last comment:
              3 years, 1 week, 4 days ago