title: Spring Batch Job Running in Infinite loop
body: <p>I am working on simple Spring Batch Job. When I launch job its running in infinite loop. It doesn't stop. According to my scheduler time it should run after every 10 seconds. But when job starts it doesn't stop. Its just keeps printing sysouts from reader, processor and writer respectively. I am creating job with reader, processor and writer. And I am doing all configuration by annotations. Not by xml. </p>
  
  <p>Here is Batch Configuration</p>
  
  <pre><code>@Configuration
  @EnableBatchProcessing
  @EnableScheduling
  public class BatchJobConfig {
  
      @Autowired
      private JobBuilderFactory jobBuilderFactory;
  
      @Autowired
      private StepBuilderFactory stepBuilderFactory;
  
      @Autowired
      private SimpleJobLauncher jobLauncher;
  
      @Scheduled(cron="*/10 * * * * *")
      public void perform() throws Exception 
      {
          Job job = job(step1());
          JobParameters jobParameters = new JobParameters();
          jobLauncher.run(job, jobParameters);        
      }
  
      @Bean
      public Step step1() 
      {
          return stepBuilderFactory.get("step1").&lt;Person, Person&gt; chunk(1)
                  .reader(reader()).processor(processor()).writer(writer())
                  .build();
      }
  
      @Bean
      public Job job(Step step1) throws Exception 
      {
          return jobBuilderFactory.get("job")
                  .incrementer(new RunIdIncrementer()).flow(step1())
                  .end().build();
      }
  
      @Bean
      public DataSource dataSource()
      {
          EmbeddedDatabaseBuilder embeddedDatabaseBuilder = new EmbeddedDatabaseBuilder();
          return embeddedDatabaseBuilder.addScript("classpath:org/springframework/batch/core/schema-drop-hsqldb.sql")
                  .addScript("classpath:org/springframework/batch/core/schema-hsqldb.sql")
                  .setType(EmbeddedDatabaseType.HSQL)
                  .build();
      }
  
      @Bean
      public PersonReader reader() {
          return new PersonReader();
      }
      @Bean
      public PersonWriter writer() {
          return new PersonWriter();
      }
      @Bean
      public PersonProcessor processor() {
          return new PersonProcessor();
      }
  
      @Bean
      public MapJobRepositoryFactoryBean mapJobRepositoryFactory(ResourcelessTransactionManager txManager) throws Exception  {    
          MapJobRepositoryFactoryBean factory = new MapJobRepositoryFactoryBean(txManager);
          factory.afterPropertiesSet();
          return factory;
      }
      @Bean
      public JobRepository jobRepository(MapJobRepositoryFactoryBean factory) throws Exception {
          return factory.getObject();
      }
      @Bean
      public SimpleJobLauncher jobLauncher(JobRepository jobRepository) {
          SimpleJobLauncher launcher = new SimpleJobLauncher();
          launcher.setJobRepository(jobRepository);
          return launcher;
      }
      @Bean
      public ResourcelessTransactionManager transactionManager() {
          return new ResourcelessTransactionManager();
      }
  }
  </code></pre>
  
  <p>PersonReader.java</p>
  
  <pre><code>  public class PersonReader implements ItemReader&lt;Person&gt; {
      @Override
      public Person read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
          Person person = new Person();
          System.out.println("In PersonReader");
          return person;
      }
  }
  </code></pre>
  
  <p>PersonWriter.java</p>
  
  <pre><code>public class PersonWriter implements ItemWriter&lt;Person&gt; {
      @Override
      public void write(List&lt;? extends Person&gt; arg0) throws Exception {
          System.out.println("IN PersonWriter");
      }
  }
  </code></pre>
  
  <p>PersonProcessor.java</p>
  
  <pre><code>public class PersonProcessor implements ItemProcessor&lt;Person, Person&gt; {
      @Override
      public Person process(Person arg0) throws Exception  {
          System.out.println("In PersonProcessor");
          return arg0;
      }
  }
  </code></pre>