title: Spring batch job is not terminating after adding Splunk logging step
body: <p>I am running a Spring batch but for logging purposes, I am redirecting all my logs to Splunk. The logs are getting updated on Splunk as expected, but now my job is not terminating. Even after everything gets processed, it's still running.</p>
  <p>How can I terminate my job with Splunk logging enabled?</p>
  <p><strong>log4j2.xml :</strong></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;Configuration status=&quot;info&quot; name=&quot;cspprovmi&quot;
                 packages=&quot;com.prov&quot;&gt;
  
      &lt;Appenders&gt;
          &lt;SplunkHttp name=&quot;http&quot; url=&quot;${env:SPLUNK_URL}&quot;
                      token=&quot;${env:SPLUNK_TOKEN}&quot;  host=&quot;${env:SPLUNK_NAMESPACE}&quot;
                      index=&quot;cba_facts_cs&quot; source=&quot;${env:SPLUNK_SOURCE}&quot;
                      sourcetype=&quot;facts_cs:http:log&quot; messageFormat=&quot;json&quot;
                      disableCertificateValidation=&quot;true&quot;&gt;
              &lt;PatternLayout pattern=&quot;%msg&quot; /&gt;
          &lt;/SplunkHttp&gt;
          &lt;Console name=&quot;Console&quot; target=&quot;SYSTEM_OUT&quot;&gt;
              &lt;PatternLayout
                      pattern=&quot;%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n&quot; /&gt;
          &lt;/Console&gt;
      &lt;/Appenders&gt;
      &lt;Loggers&gt;
          &lt;Root level=&quot;info&quot; additivity=&quot;false&quot;&gt;
              &lt;AppenderRef ref=&quot;http&quot; level=&quot;info&quot; /&gt;
          &lt;/Root&gt;
      &lt;/Loggers&gt;
  &lt;/Configuration&gt;
  </code></pre>
  <p><strong>pom.xml :</strong></p>
  <pre><code>&lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-batch&lt;/artifactId&gt;
              &lt;exclusions&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                      &lt;artifactId&gt;spring-boot-starter-logging&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
              &lt;/exclusions&gt;
          &lt;/dependency&gt;
  </code></pre>
  <p><strong>JobBuilderConfig.java</strong></p>
  <pre><code>  //  Job
      @Bean
      public Job job(){
          return jobBuilderFactory.get(&quot;jobCSProvMI4275&quot;)
                  .start(step1())
                  .next(step2())
                  .next(step3())
                  .next(step4())
                  .next(step5())
                  .next(step6())
                  .next(step7())
                  .incrementer(new RunIdIncrementer())
                  .build();
      }
  }
  </code></pre>
  <p>One workaround I am considering is to include <code>jobListener</code> and call <code>system.exit(0)</code> in the code itself. This seems to work fine, as it's terminating job even with Splunk logging enabled, but not sure if there is a better way to achieve this (ie exit the process gracefully).</p>
  <pre><code>   @Bean
      public JobExecutionListener jobMi4275ExecutionListener() {
          JobExecutionListener jobExecutionListener = new JobExecutionListener() {
              @Override
              public void beforeJob(JobExecution jobExecution) {
                  LOGGER.info(&quot;jobCSP4275 Started executing..&quot;);
              }
              @Override
              public void afterJob(JobExecution jobExecution) {
                  LOGGER.info(&quot;jobCSP4275 finished successfully..Exiting job !!&quot;);
                
                  System.exit(0);
              }
          };
          return jobExecutionListener;
      }
  </code></pre>