r*****e 发帖数: 30 | 1 有一个接口叫
void setRPS(int num);
接下来不断有request过来,如何实现下面的接口,返回accept或者deny,
bool process(int timestamp){
}
有什么好的想法吗 |
|
l*******0 发帖数: 95 | 2 This is a question about concurrency, the following code may work. Hope it's
helpful.
public class Solution {
AtomicInteger count = new AtomicInteger(0);
Integer limit = 0;
Integer startTimestamp = -1;
void setRPS(int num) {
limit = num;
}
bool process(int timestamp){ // suppose timestamp is ms
synchronized {
if(count.get() < limit) {
count.incrementAndGet();
return true;
... 阅读全帖 |
|
|
m*****k 发帖数: 731 | 4 control request number within a second |
|
x*******9 发帖数: 138 | 5 单线程多线程?
用一个双端队列存时间信息,然后每次有新请求来的时候维护一下。
不过对多线程不适用。 |
|
e***m 发帖数: 92 | 6 Google的Guava里提供了一个RateLimiter的class,可以做参考 |
|
w********8 发帖数: 55 | 7 请假大牛,这个题跟consumer producer有关系吗? |
|