Java Respect Rate Limit -
i'm working on code supposed respect rate limit, here's i've written far (single main class):
public class main{ public static void get(){ //method i'm gonna put http stuff retrieve data system.out.println("get!"); } public static void main(string[] args){ int getdone = 0; //number of get() done since t0 updated last time final int get_max = 10; //max number of get() can done in time_frame ms, 10 here else long t0 = system.currenttimemillis(); //currenttimemillis() registered on last time getdone equal 0 final long time_frame = 2000; //number of ms of "cycle" for(int = 0; < 45; i++){ //number of calls, 45 here else if(getdone == get_max){ while(system.currenttimemillis() - t0 < time_frame); } get(); if(getdone == 0){ t0 = system.currenttimemillis(); } getdone = (getdone + 1) % (get_max + 1); //for example, if get_max = 5, getdone goes like: 0 1 2 3 4 5 0 1 2 .. } } }
also wondering if should use nano instead of millis? if so, why? :)
can of guys validate or correct if i'm doing wrong? in advance! :d
Comments
Post a Comment