List of usage examples for org.springframework.batch.repeat RepeatStatus continueIf
public static RepeatStatus continueIf(boolean continuable)
From source file:org.springframework.batch.core.step.item.ChunkOrientedTasklet.java
@Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { @SuppressWarnings("unchecked") Chunk<I> inputs = (Chunk<I>) chunkContext.getAttribute(INPUTS_KEY); if (inputs == null) { inputs = chunkProvider.provide(contribution); if (buffering) { chunkContext.setAttribute(INPUTS_KEY, inputs); }/*from ww w .j av a2s . c o m*/ } chunkProcessor.process(contribution, inputs); chunkProvider.postProcess(contribution, inputs); // Allow a message coming back from the processor to say that we // are not done yet if (inputs.isBusy()) { logger.debug("Inputs still busy"); return RepeatStatus.CONTINUABLE; } chunkContext.removeAttribute(INPUTS_KEY); chunkContext.setComplete(); if (logger.isDebugEnabled()) { logger.debug("Inputs not busy, ended: " + inputs.isEnd()); } return RepeatStatus.continueIf(!inputs.isEnd()); }
From source file:org.springframework.batch.repeat.support.TaskExecutorRepeatTemplateBulkAsynchronousTests.java
@Before public void setUp() { template = new TaskExecutorRepeatTemplate(); TaskExecutor taskExecutor = new SimpleAsyncTaskExecutor(); threadPool.setMaxPoolSize(300);//from w w w . j a v a 2 s .c o m threadPool.setCorePoolSize(10); threadPool.setQueueCapacity(0); threadPool.afterPropertiesSet(); taskExecutor = threadPool; template.setTaskExecutor(taskExecutor); template.setThrottleLimit(throttleLimit); items = Collections.synchronizedList(new ArrayList<String>()); callback = new RepeatCallback() { private volatile AtomicInteger count = new AtomicInteger(0); @Override public RepeatStatus doInIteration(RepeatContext context) throws Exception { int position = count.incrementAndGet(); String item = position <= total ? "" + position : null; items.add("" + item); if (item != null) { beBusy(); } /* * In a multi-threaded task, one of the callbacks can call * FINISHED early, while other threads are still working, and * would do more work if the callback was called again. (This * happens for instance if there is a failure and you want to * retry the work.) */ RepeatStatus result = RepeatStatus.continueIf(position != early && item != null); if (position == error) { throw new RuntimeException("Planned"); } if (!result.isContinuable()) { logger.debug("Returning " + result + " for count=" + position); } return result; } }; }