I have a spring boot app that receives data from different devices that I need to insert as batch to maximize performance. For this I have considered storing data in memory for a while and then calling build in spring data saveAll method to save as a batch. But the my problem is that data does not come at a regular speed and I may get a few thousand data at a time and then no data for next few hours. So I am not sure how to properly build the batch as there may be few data at the end that would be left out with a fixed sized batch. Is there a way to do a timed batching in java/spring that flushes the batch after a configured timeout?