This week's book giveaways are in the Cloud and AI/ML forums.
We're giving away four copies each of Cloud Native Patterns and Natural Language Processing and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Spring batch tasklet execute method not calling

 
Greenhorn
Posts: 25
  • 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: 25
  • 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: 25
  • 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: 25
  • 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
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!