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 committed by GitHub
parent 6290346246
commit 536b83a1a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -107,19 +107,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();