Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Unoptimized
- // this performs a synchronized lookup for every increment
- taskLoop {
- String suffix = returnCounterType();
- Stats.incr("metric_name" + suffix);
- }
- // Optimized
- // ThreadLocalStats does not have any locks.
- ThreadLocalStats tls = Stats.makeThreadLocalStats();
- taskLoop {
- String suffix = returnCounterType();
- // regular lookup, not synchronized
- ThreadLocalCounter tlc = tls.counter("metric_name" + suffix);
- tlc.incr();
- }
- // User must flush the batch of stats at the end.
- tls.flush();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement