Announcement Announcement Module
Collapse
No announcement yet.
Configure throttle-limit as a parameter? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Configure throttle-limit as a parameter?

    Is there a good way to configure a <batch:tasklet>'s throttle-limit property as a run time job parameter? We are currently testing a job on different hardware, and we would like to try different settings for throttle-limit for each job, without having to rebuild our code.

    The {jobParameters[] } syntax does not seem to work, but it could very well be my ignorance of how late binding is going on in Spring Batch...

  • #2
    My hunch (and this is getting into Spring Core stuff that I'm not 100% on how it works) is that that wouldn't be possible using the standard Spring Batch tags. What I think you would have to try (and I'm not even sure if this is still supported) is try to configure your tasklet the way Spring Batch 1.x did (as a bean instead with the <tasklet> tag). I'm not even sure that that will work, but it might work around the issue. Otherwise, I would think you should be able to inject it as a property file that you could package outside of your artifact.

    Comment


    • #3
      I've also faced with this problem.
      We are writing jobs configurator, so I prefer to set a lot of parameters by myself.

      You can define StepFactoryBean
      Code:
      	<bean id="factoryBean" class="org.springframework.batch.core.step.item.FaultTolerantStepFactoryBean">
      		<property name="transactionManager" ref="transactionManager" />
      		<property name="jobRepository" ref="jobRepository" />
      		<property name="startLimit" value="100" />
      		<property name="commitInterval" value="10" />
      		<property name="skipLimit" value="400" />
                      <property name="taskExecutor" ref="asyncTaskExecutor" />
      		<property name="listeners">
      			<list>
      				<ref bean="skipListener" />
      				<ref bean="stepExecutionListener" />
      			</list>
      		</property>
      		<property name="skippableExceptionClasses">
      			<map>
      	
      					<entry key-ref="runtimeException" value="true" />
      <!-- 				<entry key-ref="pathNotFoundException" value="true" /> -->
      <!-- 				<entry key-ref="documentGenerationException" value="true" /> -->
      			</map>
      		</property>
      	</bean>
      then inject it... and all others beans what you need

      Code:
      ......................................................
      ......................................................               
                      factoryBean.setSkipLimit(jobDefinition.getSkipLimit());
      		
      		factoryBean.setCommitInterval(jobDefinition.getCommitInterval());
      		factoryBean.setThrottleLimit(jobDefinition.getThrottleLimit());
      		
      		TaskletStep taskletStep = (TaskletStep) factoryBean.getObject();
      		taskletStep.setName("Tasklet Step");
      		
      		job.addStep(taskletStep);
      
      ......................................................
      ......................................................
      
                     jobLauncher.run(job, jobParametersBuilder.toJobParameters());
      It's quite flexible approach. For instance you can also set taskExecutor programmatically and manipulate maxPoolSize, queueCapacity etc on-a-fly

      IMHO, of course

      Comment


      • #4
        There is a simpler solution to this problem. The throttling is actually performed by the task Executor for the step - for concurrent processing this is normally a SimpleAsyncTaskExecutor. This is generally defined as a named bean in the config. Simply load this bean and set the concurrencyLimit explicitly.

        Note that there is a warning in the class that changing unlimited (-1, default) to a concrete value at runtime messes up the concurrency counts. So put a concrete limit on the bean def in the config.

        Comment

        Working...
        X