Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. // Unoptimized
  2. // this performs a synchronized lookup for every increment
  3. taskLoop {
  4. String suffix = returnCounterType();
  5. Stats.incr("metric_name" + suffix);
  6. }
  7.  
  8. // Optimized
  9. // ThreadLocalStats does not have any locks.
  10. ThreadLocalStats tls = Stats.makeThreadLocalStats();
  11. taskLoop {
  12. String suffix = returnCounterType();
  13. // regular lookup, not synchronized
  14. ThreadLocalCounter tlc = tls.counter("metric_name" + suffix);
  15. tlc.incr();
  16. }
  17. // User must flush the batch of stats at the end.
  18. tls.flush();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement