|
|
Stopping via the CommandLineJobRunner
Quick question...
I have a job that is running as expected. When I attempt to stop it via the CommandLineJobRunner (during the execution of step1 in the below configuration) I can see that the Job's Execution status is set to STOPPING. The issue I'm having is that I would expect that after a chunk is done processing that this status would be checked and processing would end. However what I'm seeing is that processing is continuing. Any insight you can provide on what I'm missing would be appreciated. Thanks in advance!
My job configuration:
Code:
... lt;beans:bean id=quot;transactionFileReaderquot; class=quot;com.mystuff.TransactionReaderquot;gt; lt;beans:property name=quot;fieldSetReaderquot; ref=quot;fileItemReaderquot;/gt; lt;/beans:beangt;
lt;beans:bean id=quot;fileItemReaderquot; class=quot;org..batch.item.file.FlatFileItemReaderquot;gt; lt;beans:property name=quot;resourcequot; ref=quot;transactionFilequot; /gt; lt;beans:property name=quot;lineMapperquot;gt; lt;beans:bean class=quot;org..batch.item.file.mapping.DefaultLineMapperquot;gt; lt;beans:property name=quot;lineTokenizerquot;gt; lt;beans:bean class=quot;org..batch.item.file.transform.DelimitedLineTokenizerquot;gt; lt;beans:property name=quot;delimiterquot; value=quot;,quot;/gt; lt;/beans:beangt; lt;/beans:propertygt; lt;beans:property name=quot;fieldSetMapperquot;gt; lt;beans:bean class=quot;org..batch.item.file.mapping.PassThroughFieldSetMapperquot; /gt; lt;/beans:propertygt; lt;/beans:beangt; lt;/beans:propertygt; lt;/beans:beangt;
lt;step id=quot;importTransactionFileStepquot;gt; lt;tasklet allow-start-if-complete=quot;truequot;gt; lt;chunk reader=quot;transactionFileReaderquot; writer=quot;transactionWriterquot; commit-interval=quot;100quot;gt; lt;streamsgt; lt;stream ref=quot;fileItemReaderquot;/gt; lt;/streamsgt; lt;/chunkgt; lt;listenersgt; lt;listener ref=quot;transactionFileReaderquot;/gt; lt;/listenersgt; lt;/taskletgt; lt;/stepgt;
lt;step id=quot;generateAccountSummaryStepquot;gt; lt;taskletgt; lt;chunk reader=quot;accountSummaryReaderquot; writer=quot;accountSummaryWriterquot; commit-interval=quot;100quot;/gt; lt;/taskletgt; lt;/stepgt;
lt;step id=quot;applyTransactionsStepquot;gt; lt;taskletgt; lt;chunk reader=quot;accountSummaryReaderquot; processor=quot;transactionApplierProcessorquot; writer=quot;accountSummaryUpdaterquot; commit-interval=quot;100quot;/gt; lt;/taskletgt; lt;/stepgt;
lt;job id=quot;transactionJobquot;gt; lt;step id=quot;step1quot; parent=quot;importTransactionFileStepquot; next=quot;step2quot;/gt; lt;step id=quot;step2quot; parent=quot;applyTransactionsStepquot; next=quot;step3quot;/gt; lt;step id=quot;step3quot; parent=quot;generateAccountSummaryStepquot;/gt; lt;/jobgt;
...
The code for the transactionReader:
Code:
package com.mystuff;
import org..batch.core.ExitStatus;
import org..batch.core.StepExecution;
import org..batch.core.annotation.AfterStep;
import org..batch.item.ItemReader;
import org..batch.item.NonTransientResourceException;
import org..batch.item.ParseException;
import org..batch.item.UnexpectedInputException;
import org..batch.item.file.transform.FieldSet;
public class TransactionReader implements ItemReaderlt;Objectgt; {
private ItemReaderlt;FieldSetgt; fieldSetReader; private int recordCount = 0; private int expectedRecordCount = 0;
public Object read() throws Exception, UnexpectedInputException, ParseException,NonTransientResourceException { Transaction record = process(fieldSetReader.read());
return record; }
private Transaction process(FieldSet fieldSet) { Transaction result = null;
if(fieldSet.getFieldCount() gt; 1) {result = new Transaction();result.setAccountNumber(fieldSet.readString(0));result.setTimestamp(fieldSet.readDate(1, quot;yyyy-MM-DD HH:mm:ssquot;));result.setAmount(fieldSet.readDouble(2));
recordCount++; } else {expectedRecordCount = fieldSet.readInt(0); }
return result; }
public void setFieldSetReader(ItemReaderlt;FieldSetgt; fieldSetReader) { this.fieldSetReader = fieldSetReader; }
@AfterStep public ExitStatus afterStep(StepExecution execution) { return execution.getExitStatus(); }
}I can't see why it wouldn't work if the job is actually still executing. Are you sure it is? If it is running then it must be stuck on something so it doesn't finish a chunk. Can you see changes to the step execution in the JobRepository? If you take a thread dump you can check what it is doing, and see if you can see any reason it would do that.
Can you share the command which you are using to stop your job and how you are seeing job status is getting completed . |
|