Skip to content

Commit

Permalink
Merge pull request wildfly#18067 from ehsavoie/WFLY-19567
Browse files Browse the repository at this point in the history
[WFLY-19567]: Removing ConcurrentHashMap usage
  • Loading branch information
bstansberry authored Aug 20, 2024
2 parents d9290ad + d5a7d23 commit 9c6b9e3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/

package org.wildfly.extension.messaging.activemq.deployment.injection;

import static org.wildfly.extension.messaging.activemq._private.MessagingLogger.ROOT_LOGGER;

import java.io.Serializable;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import jakarta.jms.ConnectionFactory;
import jakarta.jms.JMSContext;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantLock;

/**
* Abstract class for managing JMS Contexts.
Expand All @@ -23,12 +23,24 @@
*/
public abstract class AbstractJMSContext implements Serializable {

private final Map<String, JMSContext> contexts = new ConcurrentHashMap<>();
private final transient ReentrantLock lock = new ReentrantLock();
private final transient Map<String, JMSContext> contexts = new ConcurrentHashMap<>();

JMSContext getContext(String injectionPointId, JMSInfo info, ConnectionFactory connectionFactory) {
return contexts.computeIfAbsent(injectionPointId, key -> {
return createContext(info, connectionFactory);
});
JMSContext context = contexts.get(injectionPointId);
if (context == null) {
lock.lock();
try {
context = contexts.get(injectionPointId);
if (context == null) {
context = createContext(info, connectionFactory);
contexts.put(injectionPointId, context);
}
} finally {
lock.unlock();
}
}
return context;
}

private JMSContext createContext(JMSInfo info, ConnectionFactory connectionFactory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ public JMSContext call() throws Exception {
}

// Execute all tasks
for (Callable<JMSContext> task : tasks) {
executor.submit(task);
}
executor.invokeAll(tasks);

// Shutdown the executor
executor.shutdown();
Expand Down

0 comments on commit 9c6b9e3

Please sign in to comment.