Apache HttpClient: Limit total calls per second

血红的双手。 提交于 2019-12-12 04:23:29

问题


I need to limit the number of HTTP calls per second to max 10. This is as per the allowed quota.

Does HttpClient has some feature for this? Or any custom implementation would also do.


回答1:


You might try the ScheduledThreadPoolExecutor.

From the javadoc:

A ThreadPoolExecutor that can additionally schedule commands to run after a given delay, or to execute periodically

You would simply use the schedule method and pass it a Runnable, where the Runnable makes your call via the HttpClient. You could schedule your Runnable to run 10 times per second, or as needed. The Executor will queue up your calls over the HttpClient, and only run a max of 10 per second.



来源:https://stackoverflow.com/questions/41475367/apache-httpclient-limit-total-calls-per-second

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!