Question: I am new to Spring. I have a Job where it reads the file and writes to the Database. If the number of records in the file are more than 8000, i should not process the file and is hould stop the Job Execution. Please suggest what is the better way to do this.

Answer: 
you can implement StepExecutionListener at itemreader. Then you can get readcount which is corresponds your line number.

```
 public class ExampleItemReader implements ItemReader<String>, StepExecutionListener {

    public synchronized String read() throws Exception {
        return "";
    }

    @Override
    public ExitStatus afterStep(StepExecution executionContext) {
        if (executionContext.getReadCount() > 8000) {
            return ExitStatus.COMPLETED;
        }
        return ExitStatus.EXECUTING;
    }

    @Override
    public void beforeStep(StepExecution arg0) {

    }

}

```

advise reading [spring batch patterns](http://docs.spring.io/spring-batch/reference/html/patterns.html)
I'm assuming that the records in your file are not fixed length. If so, File.length() will easily calculate the number of records in the file.

If not, does it need to be exactly 8000 or around 8000? If it's a rough limit, I would get an average record length for these files and then use File.length() to estimate the number of records.