Win a copy of Grokking Bitcoin this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

Spring batch tasklet execute method not calling  RSS feed

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Iam trying spring batch version 4. Iam facing one problem with tasklet 's execute is never called.

here is my code:


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;


@SpringBootApplication
public class Main {

   public static void main(String args[]) {
       System.out.println(3);
       SpringApplication.run(Main.class, args);
       System.out.println(4);
   }
}

/********Tasklet*****/


import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.StepExecutionListener;
import org.springframework.batch.core.configuration.annotation.StepScope;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;

public class DemoTasklet implements Tasklet, StepExecutionListener {

   public DemoTasklet() {
       System.out.println("demo tasklet constructor");
   }

   @Override
   public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {
       System.out.println("hello");
       return RepeatStatus.FINISHED;
   }

   @Override
   public void beforeStep(StepExecution stepExecution) {
       System.out.println("before");
   }

   @Override
   public ExitStatus afterStep(StepExecution stepExecution) {
       System.out.println("after");
       return stepExecution.getExitStatus();
   }
}

/*******Main code*****/

import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepScope;
import org.springframework.batch.core.launch.support.RunIdIncrementer;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

@Configuration
@EnableBatchProcessing
public class BatchConfiguration {

   @Autowired
   private JobBuilderFactory jobBuilderFactory;

   @Autowired
   private StepBuilderFactory stepBuilderFactory;

   @Bean
   public Step step1() {
       return stepBuilderFactory.get("step1")
               .tasklet(new DemoTasklet())
               .build();
   }

   @Bean
   public Job job() throws Exception {
       return jobBuilderFactory.get("job")
               .incrementer(new RunIdIncrementer())
               .flow(step1())
               .end()
               .build();
   }
}



Please help. Its calling only constructor. not execute method.



Thanks in advance
 
Ranch Hand
Posts: 570
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please elaborate your problem.
 
vinoth sathi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

John Joe wrote:Please elaborate your problem.




Hi,

Iam trying to do some login in execute method(public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) ). But its not calling to execute method. its only calling DemoTasklet constructor.

what is the problem?
 
vinoth sathi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry. typo error. Not login . i mean logic
 
John Joe
Ranch Hand
Posts: 570
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happened if you remove these code since you have created a class named DemoTasklet ?
 
vinoth sathi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

John Joe wrote:What happened if you remove these code since you have created a class named DemoTasklet ?



Hi,  Thanks now working.
 
John Joe
Ranch Hand
Posts: 570
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

vinoth sathi wrote:Hi,  Thanks now working.

Great
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!