質問

I'm seeking algorithm to design multithreading application in java where each thread write data to db. I want to control the number of records written to db per second.

the application gets RPS (records per second) param and approximately generate those many load.

役に立ちましたか?

解決

If you can use external libraries, guava has a RateLimiter class which probably does what you ask for:

Rate limiters are often used to restrict the rate at which some physical or logical resource is accessed. This is in contrast to Semaphore which restricts the number of concurrent accesses instead of the rate.

他のヒント

You could create a BlockingQueue of permit objects and have an extra helper thread that adds RPS number of additional permits to the queue once per second. Writing threads block on the queue and do not write until they successfully pop a permit off the top of the queue.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top