0

I have written a spring batch with Reader and Writer (No Processor). All it does is based upon the input records from the reader, loads the data from few source tables to archive tables. I am calling a stored procedure in the writer which loads the records to archive tables and deletes from the source tables. But I am running into a strange behavior, Every time I start the batch it performs the archiving process but stops abruptly at 2 hours 10 minutes of execution time. Even if i rerun, again runs for 2 hours and 10 minutes and stops the execution. But the archival is not fully completed. There are no errors in the log except the below line.

Error Log :

2022-08-29 17:12:09.157  INFO 9109612 --- [SpringApplicationShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2022-08-29 17:12:09.158 TRACE 9109612 --- [SpringApplicationShutdownHook] o.h.type.spi.TypeConfiguration$Scope     : Handling #sessionFactoryClosed from [org.hibernate.internal.SessionFactoryImpl@c647c96f] for TypeConfiguration
2022-08-29 17:12:09.158 DEBUG 9109612 --- [SpringApplicationShutdownHook] o.h.type.spi.TypeConfiguration$Scope     : Un-scoping TypeConfiguration [org.hibernate.type.spi.TypeConfiguration$Scope@9239dddd] from SessionFactory [org.hibernate.internal.SessionFactoryImpl@c647c96f]

Below is my batch Writer implementation. Can someone please shed some light on this ?

@Override
public void write(List<? extends Account> items) throws Exception {
    
    DataSource dataSource= (DataSource) ctx.getBean("dataSource");
    this.jdbcTemplate = new JdbcTemplate(dataSource);
    
    for (cvObj : items) {

        logger.info("Going to archive for batch ");
        jdbcTemplate.update(QUERY_INSERT_ARCHIVE,cvObj.getRunner);  
        jdbcTemplate.update("{ call pArchiveRecords (?) }", cvObj.getRunner);
        logger.info("Archival completed for ::: "+cvObj.getRunner);
        jdbcTemplate.update(QUERY_UPDATE_ARCHIVE,cvObj.getRunner);
        
        
    }
    

}
Saimuga
  • 255
  • 1
  • 5
  • 16
  • 3
    What does "stops the execution" mean exactly? Is the JVM exiting? Or does it continue to run, but is no longer making observable progress? What steps have you taken to debug the issue? – meriton Aug 31 '22 at 04:04
  • 1
    move the below code into constructor DataSource dataSource= (DataSource) ctx.getBean("dataSource"); this.jdbcTemplate = new JdbcTemplate(dataSource); Its using jdbcTemplate above errors in logs not related to writer. try to logs jdbc using logging.level.org.springframework.jdbc.core = TRACE – sjy Aug 31 '22 at 07:46
  • 1
    Your writer is wrong. First don't create a `JdbcTemplate` but use a preconfigured one and inject it. You should use a batch insert/update and not individual updates. This is slow, don't do logging in the writer, logging in slow and will become a performance bottleneck. Your logging doesn't show anything related, please add the full log from the point it starts to shutdown and preferably some before that. – M. Deinum Aug 31 '22 at 08:15
  • @meriton As you mentioned, JVM is not exiting. Spring Batch keeps executing. But there is no progress. No Log entries. No Errors. Initially I did some research and found that the error might be due to Hikari Database validation settings. So I have added the below values to properties file. spring.datasource.hikari.connectionTimeout=12000000. But it didnt work. Please let me know if you have any more questions. – Saimuga Sep 03 '22 at 01:47
  • @sjy Sure, I will try it out and let you know. Thanks for your suggestions !!! – Saimuga Sep 03 '22 at 01:49
  • @M.Deinum Thanks for the suggestions. I will remove the log entries from the writer. The thing is there are no logs other than the one I added in my post. The log doesnt show anything related to the error. Thats why I am wondering what is causing the problem. – Saimuga Sep 03 '22 at 01:52
  • See [Tool for debugging hangs in java application](https://stackoverflow.com/questions/9833497/tool-for-debugging-hangs-in-java-application) and similar questions for how to debug hung java processes. A thread dump will tell you where the program is hanging, which greatly narrows down the possible causes. – meriton Sep 03 '22 at 12:06
  • It isn't only the log entries your `JdbcTemplate` usage, as mentioned, is wrong as well. – M. Deinum Sep 04 '22 at 07:47

0 Answers0