resettable timer pattern
21 Feb 2018Recently I undertook the task of refactoring batch processing at work. The jobs followed a similar pattern of records get staged, messages are sent and the stage status is updated for each message. This causes numerous DB connections to be opened up for every message and doing updates in separate threads seemed like a waste of time to me.
This made me think about batch updates and a pattern where a single thread does all the updates when the process finishes. The important point here is knowing when the process has finished. For me that was when no message has been sent for an arbitrary amount of time. Implementing the below interface did the trick for me:
Spring AOP configuration: