I am using Java as my programming interface. Here is my work flow. I have a producer who has a file name with path and adds it to queue. And then consumer who consumes it. After dequeue I add it to arraylist and then check if it has reached a count of x. If yes then I will process it. So far so good. But the problem is when I have a single file sitting in this list. It doesn't get processed till filelist has reached size x. I wanted to have some kind of timer to elapse and after y mins, I wanted to process the file list if it is not empty. How do I achieve this? I know about timer task, scheduled executor but it runs a thread after scheduled time which is not my case. I can provide more details if you need. Please let me know if my design is wrong and thanks for the help.
Every time you try to dequeue check a timestamp that you set when you consumed the last file. If that timestamp is bigger than your threshold time and you have n-files in the queue (where n < x) - consume the files even though they haven't reached x.
pseudo-code:
timestamp <= now
every k milliseconds:
check the number of files n in queue:
if n >= x:
consume the files
update timestamp (to "now")
else if (now - timestamp > time-threshold):
consume the files
update timestamp (to "now")