Fix for AMQ-1344 - Deadlock can occur when cerating and deleting many destinations concurrently

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@559155 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Hiram R. Chirino 2007-07-24 18:27:49 +00:00
parent 76b2a3ed8f
commit 3b88ba0c47
1 changed files with 61 additions and 60 deletions

View File

@ -88,7 +88,7 @@ public class RegionBroker implements Broker {
protected final DestinationStatistics destinationStatistics = new DestinationStatistics();
private final CopyOnWriteArrayList connections = new CopyOnWriteArrayList();
private final HashMap destinations = new HashMap();
private final Map destinations = new ConcurrentHashMap();
private final CopyOnWriteArrayList brokerInfos = new CopyOnWriteArrayList();
private final LongSequenceGenerator sequenceGenerator = new LongSequenceGenerator();
@ -251,11 +251,10 @@ public class RegionBroker implements Broker {
public Destination addDestination(ConnectionContext context, ActiveMQDestination destination) throws Exception {
Destination answer;
synchronized(destinations) {
answer = (Destination) destinations.get(destination);
if (answer != null)
return answer;
}
switch (destination.getDestinationType()) {
case ActiveMQDestination.QUEUE_TYPE:
@ -274,14 +273,14 @@ public class RegionBroker implements Broker {
throw createUnknownDestinationTypeException(destination);
}
synchronized(destinations) {
destinations.put(destination, answer);
return answer;
}
}
public void removeDestination(ConnectionContext context,ActiveMQDestination destination,long timeout) throws Exception{
synchronized(destinations) {
public void removeDestination(ConnectionContext context,
ActiveMQDestination destination, long timeout) throws Exception {
if (destinations.remove(destination) != null) {
switch (destination.getDestinationType()) {
case ActiveMQDestination.QUEUE_TYPE:
@ -291,16 +290,18 @@ public class RegionBroker implements Broker {
topicRegion.removeDestination(context, destination, timeout);
break;
case ActiveMQDestination.TEMP_QUEUE_TYPE:
tempQueueRegion.removeDestination(context,destination,timeout);
tempQueueRegion
.removeDestination(context, destination, timeout);
break;
case ActiveMQDestination.TEMP_TOPIC_TYPE:
tempTopicRegion.removeDestination(context,destination,timeout);
tempTopicRegion
.removeDestination(context, destination, timeout);
break;
default:
throw createUnknownDestinationTypeException(destination);
}
}
}
}
public void addDestinationInfo(ConnectionContext context,DestinationInfo info) throws Exception{
@ -315,9 +316,9 @@ public class RegionBroker implements Broker {
public ActiveMQDestination[] getDestinations() throws Exception {
ArrayList l;
synchronized(destinations) {
l = new ArrayList(destinations.values());
}
ActiveMQDestination rc[] = new ActiveMQDestination[l.size()];
l.toArray(rc);
return rc;