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:
parent
6290346246
commit
536b83a1a8
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user