2222import java .util .concurrent .ThreadFactory ;
2323import java .util .concurrent .TimeUnit ;
2424import java .util .concurrent .atomic .AtomicBoolean ;
25+ import java .util .concurrent .atomic .AtomicInteger ;
2526
2627public class UniqueKeysTrackerImp implements UniqueKeysTracker {
2728 private static final Logger _log = LoggerFactory .getLogger (UniqueKeysTrackerImp .class );
2829 private static final double MARGIN_ERROR = 0.01 ;
2930 private static final int MAX_UNIQUE_KEYS_POST_SIZE = 5000 ;
3031 private static final int MAX_AMOUNT_OF_KEYS = 10000000 ;
31- private int trackerKeysSize = 0 ;
32+ private final AtomicInteger trackerKeysSize = new AtomicInteger ( 0 ) ;
3233 private FilterAdapter filterAdapter ;
3334 private final TelemetrySynchronizer _telemetrySynchronizer ;
3435 private final ScheduledExecutorService _uniqueKeysSyncScheduledExecutorService ;
@@ -61,11 +62,11 @@ public boolean track(String featureFlagName, String key) {
6162 (feature , current ) -> {
6263 HashSet <String > keysByFeature = Optional .ofNullable (current ).orElse (new HashSet <>());
6364 keysByFeature .add (key );
64- trackerKeysSize ++ ;
65+ trackerKeysSize . incrementAndGet () ;
6566 return keysByFeature ;
6667 });
6768 _logger .debug ("The feature flag " + featureFlagName + " and key " + key + " was added" );
68- if (trackerKeysSize >= MAX_UNIQUE_KEYS_POST_SIZE ){
69+ if (trackerKeysSize . intValue () >= MAX_UNIQUE_KEYS_POST_SIZE ){
6970 _logger .warn ("The UniqueKeysTracker size reached the maximum limit" );
7071 try {
7172 sendUniqueKeys ();
@@ -110,7 +111,7 @@ public HashMap<String,HashSet<String>> popAll(){
110111 HashSet <String > value = uniqueKeysTracker .remove (key );
111112 toReturn .put (key , value );
112113 }
113- trackerKeysSize = 0 ;
114+ trackerKeysSize . set ( 0 ) ;
114115 return toReturn ;
115116 }
116117
@@ -121,7 +122,7 @@ private void sendUniqueKeys(){
121122 }
122123
123124 try {
124- if (uniqueKeysTracker .size () == 0 ) {
125+ if (uniqueKeysTracker .isEmpty () ) {
125126 _log .debug ("The Unique Keys Tracker is empty" );
126127 return ;
127128 }
0 commit comments