Spring Batch - Is it possible for Job_Instance to have multiple Job_execution? - spring-batch

I'm just wondering whether its possible for a single Job_instance in spring Batch to have multiple Job_execution if so can anyone please explain the process? And also for step_execution please !

Yes, a job instance can have multiple job executions. The typical use case is when a job instance has a first execution that fails, and a second (or subsequent) execution that succeeds.
This is explained in details with concrete examples in the Domain language of Batch section of the reference documentation.

Related

A file prepared by one spring batch job is not accessible to other for deletion

I have a requirement where I have to prepare a file using one job and another job which runs once a day will send the file to external system and delete/or move from the location. When this job tries to delete/or move the file it can't access it.
I tried setting writable to true when file is created. Running jobs on separate times (Running one job at a time). Tried adding "delete" as a step to the same job as well. Nothing worked.
I am using file.delete(). Also tried Files.deleteIfExists().
I suspect the first job is not assigning proper permissions but don't know a way around it set permissions in spring batch
Are these jobs run by the same user? i.e. Same user and permissions?
Also what is the actual error message? Does it say permissions denied? If so they it is likely an OS restriction not Spring Batch/Java limitation.
An easier solution would be to just add a step to the first job to send the files are part of the job and drop the job that just transfers the files.
Answering my own question 😀. Hope it helps someone.
Issue was the last ItemWriter was holding the resources because I was using the composite writer. While using CompositeWriter beforeStep, afterStep methods are “hidden”. You have to call them explicitely. I selected the approach to write a custom writer which will explicitely call writer.close().
Adding afterStep method and calling super.close() should also work. Though I have nit tries that out.

Talend job batch processing

I am exploring Talend at work, I was asked if Talend supports batch processing as in running the job in multiple threads. After going through the user guide I understood threading is possible with sub jobs. I would like to know if it is possible to run the a job with a single action in parallel
Talend has excellent multi threading support. There are two basic methods for this. One method gives you more control and is implemented using components. The other method is implemented as job setting.
For the first method see my screenshot. I use tParallelize to load three files into three tables at the same time. Then when all three files are successfully loaded I use the same tParallelize to set the values of a control table. tParallelize can also be connected to tRunJob as easily as a subjob.
The other method is described very well here in Talend Help: Talend Help- Run Jobs in Parallel
Generally I recommend the first method because of the control it gives you, but if your job follows the simple pattern described in the help link, that method works as well.

What are the different step types in Spring Batch?

I'm currently studiying Spring Batch and I don't get the difference between different steps types: chunk-oriented, item-oriented, stadalone...etc. I'm not even sure if these are actually steps types...
Thank you
There's really only two major "step types" in Spring Batch.
Chunk-Oriented Step
This step consists of a reader->processor->writer combination (where the processor is optional). This is the most common type of Batch step.
Tasklet Step
This step does not have a reader, processor, or writer but instead is simply a task to be executed. It is useful for running single command-like processes in your batch job (for example, to invoke a stored procedure on a database).
Technically speaking a chunk-oriented step is a sub-type of a Tasklet step. Also, there are different configurations of a chunk-oriented step that has different behavior. Like parallel step, partitioned step, mutli-threaded step, etc... but these are all more advanced concepts that build on top of the basics mentioned above. Understand chunk-oriented step first; then explore the more advanced configurations.

Spring Batch - execute a set of steps 'x' times based on a condition

I need to execute a sequence of steps a specific number of times.. any pointers on what is the best way to do this in Spring Batch. I am able to implement executing a single step 'x' times. but my requirement is to execute a set of steps - based on a condition 'x' times.Any pointers will help.
Thanks
Lakshmi
You could put all steps in a job an start the whole job several times. There are different ways, how a job actually is launched in spring-batch. have a look at joboperator and launcher and then simply implement a loop around the launching of the job.
You can do this after the whole spring-context is initialized, so there will be no overhead concerning that. But you must by attention about the scope of your beans, especially the reader and writers.
Depending on your needs concerning failurehandling and restart, you also have pay attention how you manage the execution context of your job and steps.
You can simulate a loop with SB using a JobExecutionDecider:
Put it in front of all steps.
Store x in job execution context and check for x value into
decider: move to 'END' if x equals desidered value or increment it
and move to first step of set.
After last step move back to start (the decider).

Spring batch dynamic execution flow

I'm working on a requirement that defines a job/execution unit as a list of ordered steps which are themselves defined as a list of ordered substeps/phases. This job can be started beginning at any of the first-level steps, potentially ignoring the N-th first steps (and their substeps/phases).
What would be the best strategy for implementing this with spring batch ?
Cheers
A way to programmatically branching job execution (eg. skip step) is to use a JobExecutionDecider.