Skip to content

Commit

Permalink
fix Double-Checked locking using volatile (apache#8475)
Browse files Browse the repository at this point in the history




```java
private void createSystemTopicFactoryIfNeeded() {
        if (namespaceEventsSystemTopicFactory == null) {
            synchronized (this) {
                if (namespaceEventsSystemTopicFactory == null) {
                    try {
                        namespaceEventsSystemTopicFactory = new NamespaceEventsSystemTopicFactory(pulsarService.getClient());
                    } catch (PulsarServerException e) {
                        log.error("Create namespace event system topic factory error.", e);
                    }
                }
            }
        }
    }
```

The creation of `namespaceEventsSystemTopicFactory` uses double-check locking, but does not add volatile
  • Loading branch information
315157973 authored Nov 8, 2020
1 parent a358430 commit 26fd380
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
public class SystemTopicBasedTopicPoliciesService implements TopicPoliciesService {

private final PulsarService pulsarService;
private NamespaceEventsSystemTopicFactory namespaceEventsSystemTopicFactory;
private volatile NamespaceEventsSystemTopicFactory namespaceEventsSystemTopicFactory;

private final Map<TopicName, TopicPolicies> policiesCache = new ConcurrentHashMap<>();

Expand Down

0 comments on commit 26fd380

Please sign in to comment.