JPA returning org.springframework.dao.DeadlockLoserDataAccessException

Viewed 18

I have found one scenario on Spring scheduler job. as while doing batch insert and then doing batch update, it is returning "DeadlockLoserDataAccessException" exception. this scenario occurs around one every 4 to 5 month.

code : getJdbcTemplate().batchUpdate("Update Query");

Can you suggest, how I can handle/fix this.

1 Answers

Since you give basically no information, what you are doing we can only give general recommendations.

  1. Consult your database documentation to learn how to debug dead locks, especially how to learn which objects are getting locked and by what statements. Use this to learn what parts of your application are deadlocking.

  2. To avoid deadlocks typical strategy is to always obtain locks in the same order. So if you need to access and lock two tables A and B make sure you always lock A first and then B. If you don't do this and mix the two, one session might first lock A while another session locks B resulting in both waiting for the other to release their lock, which will never happen.

Related