Load batch job config at runtime
I am already using Spring Batch for a limited number of jobs, but I am in the process of transferring all jobs from our custom batch framework to our Spring Batch implementation.
The problem is that there are close to 50 jobs in our custom framework. If I put it into our current implementation, all spring configs for all jobs will be loaded at batch startup. Not only will this take an obscene amount of time, but it will also place quite a bit of stress on the heap space etc.
Is there a way to configure the jobs to run, but load the specific spring configs for that job at runtime? That way, once the job has completed, the context can be closed and objects garbage collected as required.
My initial solution is to override SimpleJob or FlowJob and more specifically override the doExecute(JobExecution execution) method. This will load the Job specific spring context, set the steps in the parent *Job and then continue with the execution logic.
My main queries are:
- Will this work?
- Does anyone have any better solutions?