I have list of Processes and i want to execute them like, Ten processes per minute.
I tried ExecutorService
, ThreadPoolExecutor
, RateLimiter
but none of them can support my case, also i tried RxJava
but maybe i cannot figure out how ti implement it correctly.
Example
I have list of Runnable
with size 100K, each Runnable
have this logic:
- Retrieve data from
rest api
. - Do some calculation on data.
- Save the result in database.
So i used ExecutorService
with size 10 and make Delay(5 seconds) inside Runnable#run()
to manage what i need "Ten processes per minute", but still, it's not manageable.
The main point of this logic to decrease requests on rest api
.
UPDATE
effectively what we're looking for is to have an upper limit (in time and count of operations) rather than evenly distribute the time across operations regardless of their individual throughput.
i.e. if I have a list of 100 ops which will take 0.5 seconds each, and I have a rate limiter than (after distribution) determined that a single operation should take 0.8 seconds I then have a gap of 0.3 second I can use to start a new operation