ASTERIXDB-1497: Prevent ConcurrentModification in DefaultDeallocatableRegistry
This change prevents the possible ConcurrentModificationException
in DefaultDeallocatableRegistry.
Change-Id: I1189d74ca33cbe8abf5b964eb8ff334df03c4004
Reviewed-on: https://asterix-gerrit.ics.uci.edu/965
Reviewed-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Michael Blow <michael.blow@couchbase.com>
diff --git a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/resources/DefaultDeallocatableRegistry.java b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/resources/DefaultDeallocatableRegistry.java
index d491836..d1ae8f3 100644
--- a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/resources/DefaultDeallocatableRegistry.java
+++ b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/resources/DefaultDeallocatableRegistry.java
@@ -18,8 +18,8 @@
*/
package org.apache.hyracks.control.nc.resources;
+import java.util.ArrayList;
import java.util.List;
-import java.util.Vector;
import org.apache.hyracks.api.resources.IDeallocatable;
import org.apache.hyracks.api.resources.IDeallocatableRegistry;
@@ -28,21 +28,17 @@
private final List<IDeallocatable> deallocatables;
public DefaultDeallocatableRegistry() {
- deallocatables = new Vector<IDeallocatable>();
+ deallocatables = new ArrayList<>();
}
@Override
- public void registerDeallocatable(IDeallocatable deallocatable) {
+ public synchronized void registerDeallocatable(IDeallocatable deallocatable) {
deallocatables.add(deallocatable);
}
- public void close() {
+ public synchronized void close() {
for (IDeallocatable d : deallocatables) {
- try {
- d.deallocate();
- } catch (Exception e) {
- // ignore
- }
+ d.deallocate();
}
}
-}
+}
\ No newline at end of file