Guest User

Untitled

a guest
Nov 17th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. public class APIimits {
  2. List<Long> rList = new ArrayList<>();
  3.  
  4. public void get() {
  5. //this can only be called 10 times in a period of 5 seconds.
  6. if(rList.size() <= 10) {System.out.println("SUCCESS");rList.add(System.currentTimeMillis());return;}
  7. Long cts = System.currentTimeMillis();
  8. Long then = rList.get(rList.size() - 10);
  9. if(cts - then < 5000) {System.out.println("Limits Exceed");return;}
  10. else {
  11. System.out.println("SUCCESS");
  12. rList.clear();
  13. rList.add(System.currentTimeMillis());
  14. return;
  15. }
  16. }
  17.  
  18. public static void main(String[] args) throws InterruptedException {
  19. APIimits lim = new APIimits();
  20. while(true) {
  21. lim.get();
  22. Thread.sleep(400);
  23. }
  24. }
  25.  
  26. }
Add Comment
Please, Sign In to add comment