SHARE
TWEET

Untitled

a guest Jun 27th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class SimpleRateLimiter {
  2.  
  3.     private ExecutorService executorService = Executors.newFixedThreadPool(10);
  4.     private static SimpleRateLimiter srl = new SimpleRateLimiter();
  5.  
  6.     private SimpleRateLimiter() {}
  7.  
  8.     public static SimpleRateLimiter getInstance() {
  9.         return srl;
  10.     }
  11.  
  12.     public void doSomething() {
  13.         executorService.submit(new Runnable() {        
  14.             @Override
  15.             public void run() {
  16.  
  17.                 // call to 3rd party api
  18.             }
  19.         });
  20.     }
  21.  
  22.     public void terminate() throws Exception {
  23.         executorService.shutdown();
  24.     }
  25.  
  26. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top