I would like to ask for some advice regarding my problem. I have a package that does some calculations (multi threading environement) and does some insertion in a table. I would like to do something like batch insertion, which means that as soon as I receive the request, wait for example 1000 requests and then start batch insertion (without doing it one by one).
I was wondering if there is any design pattern. I have a solution, but it is a bit complicated:
create a method that will receive requests
add them to the list (string and / or instructions)
are not executed until there are 1000 items in the list
Problem: how do I handle the end? I mean, the last 999 queries, when I execute them, since I will never reach 1000? What should I do?
I am thinking of a thread that wakes up every 5 minutes and checks the number of items in the list. If he wakes up twice, and the number is the same, complete the existing queries.
Anyone have a better idea?
source
share