Reduce scope of synchronized block introduced in 5114588cba (#10013)

Motivation:

We should keep the scope of the synchronized block as small as possible.

Modifications:

Reduce scope by copy to an array first before iterate through it

Result:

Smaller scope of synchronized
This commit is contained in:
Norman Maurer 2020-02-10 19:30:53 +01:00
parent f4d1df9c57
commit 7e156b1e62
1 changed files with 7 additions and 7 deletions

View File

@ -102,19 +102,19 @@ public abstract class AddressResolverGroup<T extends SocketAddress> implements C
@SuppressWarnings({ "unchecked", "SuspiciousToArrayCall" })
public void close() {
final AddressResolver<T>[] rArray;
final Map.Entry<EventExecutor, GenericFutureListener<Future<Object>>>[] listeners;
synchronized (resolvers) {
rArray = (AddressResolver<T>[]) resolvers.values().toArray(new AddressResolver[0]);
resolvers.clear();
for (final Map.Entry<EventExecutor, GenericFutureListener<Future<Object>>> entry :
executorTerminationListeners.entrySet()) {
entry.getKey().terminationFuture().removeListener(entry.getValue());
}
listeners = executorTerminationListeners.entrySet().toArray(new Map.Entry[0]);
executorTerminationListeners.clear();
}
for (final Map.Entry<EventExecutor, GenericFutureListener<Future<Object>>> entry : listeners) {
entry.getKey().terminationFuture().removeListener(entry.getValue());
}
for (final AddressResolver<T> r: rArray) {
try {
r.close();