0

I have an implementation ( doing some operations and save the object in database ) before its triggering an email and update data in BATCH_JOB_EXECUTION_CONTEXT table.

While do this operation application is throwing an exception. Please find the exception below.

    2019-10-01 00:00:01,379 [pool-3-thread-1]  INFO core.batch.tasklet.RemoveSpringBatchHistoryTasklet:  70 - Remove the Spring Batch history before the 9/1/19 12:00 AM
2019-10-01 00:00:19,082 [pool-3-thread-1]  INFO core.batch.tasklet.RemoveSpringBatchHistoryTasklet:  73 - Deleted rows number from the BATCH_STEP_EXECUTION_CONTEXT table: 1293132
2019-10-01 00:01:17,216 [pool-3-thread-1]  INFO core.batch.tasklet.RemoveSpringBatchHistoryTasklet:  77 - Deleted rows number from the BATCH_STEP_EXECUTION table: 1293132
2019-10-01 00:01:26,461 [pool-3-thread-1]  INFO core.batch.tasklet.RemoveSpringBatchHistoryTasklet:  81 - Deleted rows number from the BATCH_JOB_EXECUTION_CONTEXT table: 1295359
2019-10-01 00:03:20,615 [WebContainer-9] ERROR         com.api.controller.BaseController:  82 - Unhandled exception while processing request for URL : https://scsbatch.com:9152/jobs/emails with exception : PreparedStatementCallback; SQL [INSERT INTO BATCH_JOB_EXECUTION_CONTEXT (SHORT_CONTEXT, SERIALIZED_CONTEXT, JOB_EXECUTION_ID) VALUES(?, ?, ?)]; Lock wait timeout exceeded; try restarting transaction; nested exception is java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction
org.springframework.dao.CannotAcquireLockException: PreparedStatementCallback; SQL [INSERT INTO BATCH_JOB_EXECUTION_CONTEXT (SHORT_CONTEXT, SERIALIZED_CONTEXT, JOB_EXECUTION_ID) VALUES(?, ?, ?)]; Lock wait timeout exceeded; try restarting transaction; nested exception is java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction

Eventhough its throwing an exception it sends email and wrong information updated in the database table.

Please find my code below.

@Override
@Transactional
public void approve(Long id, ClaimApproval claimApproval) {
    Claim claim = claimRepository.findOne(id);

             ClaimAssignment claimAssignment = claim.findNextPendingAssignment();

             claim.incrementApprovalLevel();
             claim.addHistory(historyRecordFor(claimApproval, HistoryAction.APPROVED));
             claimRepository.save(claim);
             if (!areAllAssignmentsApproved(claim))
                 emailDispatcherService.notifyNextClaimApprover(claim, assignmentService.getNextLevelApprovers(claim));  //Exception is throws here, but previous statements are executed properly and that should not happen when exception thrown.


}
Karthikeyan
  • 211
  • 1
  • 4
  • 15
  • Where is the exception coming from? Show the full stacktrace. – Andreas Oct 10 '19 at 11:15
  • @Andreas - updated with full stacktrace – Karthikeyan Oct 11 '19 at 06:25
  • Would a better approach not be to add a job monitoring listener to the job definition and then in the listener inject a notifier which you could then use to send emails when the job is complete. You could also then do the DB work via the notifier in the full knowledge that the job itself has not locked the tables.. Refer to : https://livebook.manning.com/book/spring-batch-in-action/chapter-12/92 – mkane Oct 11 '19 at 14:19
  • That's not a stacktrace, see [What is a stack trace, and how can I use it to debug my application errors?](https://stackoverflow.com/q/3988788/5221149) – Andreas Oct 11 '19 at 19:16

0 Answers0