Skip to content

Commit e97c7cc

Browse files
Changing the sinchronization. Last time
1 parent 86c473e commit e97c7cc

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

client/src/main/java/io/split/client/ApiKeyCounter.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@
99
public class ApiKeyCounter {
1010

1111
private static final Logger _log = LoggerFactory.getLogger(ApiKeyCounter.class);
12-
private static ApiKeyCounter _apiKeyCounter;
1312
private static final Multiset<String> USED_API_KEYS = ConcurrentHashMultiset.create();
1413

1514

1615
private ApiKeyCounter() {}
1716

18-
public static synchronized ApiKeyCounter getApiKeyCounterInstance() {
19-
if(_apiKeyCounter == null) {
20-
_apiKeyCounter = new ApiKeyCounter();
21-
}
17+
public static ApiKeyCounter getApiKeyCounterInstance() {
18+
return ApyKeyCounterHolder.INSTANCE;
19+
}
2220

23-
return _apiKeyCounter;
21+
//Inner class to provide instance of class
22+
private static class ApyKeyCounterHolder
23+
{
24+
private static final ApiKeyCounter INSTANCE = new ApiKeyCounter();
2425
}
2526

2627
public void add(String apiKey) {

0 commit comments

Comments
 (0)