Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class APIimits {
- List<Long> rList = new ArrayList<>();
- public void get() {
- //this can only be called 10 times in a period of 5 seconds.
- if(rList.size() <= 10) {System.out.println("SUCCESS");rList.add(System.currentTimeMillis());return;}
- Long cts = System.currentTimeMillis();
- Long then = rList.get(rList.size() - 10);
- if(cts - then < 5000) {System.out.println("Limits Exceed");return;}
- else {
- System.out.println("SUCCESS");
- rList.clear();
- rList.add(System.currentTimeMillis());
- return;
- }
- }
- public static void main(String[] args) throws InterruptedException {
- APIimits lim = new APIimits();
- while(true) {
- lim.get();
- Thread.sleep(400);
- }
- }
- }
Add Comment
Please, Sign In to add comment