[#2390] Minimize memory usage of NioDatagramChannel

Motivation:
At the moment we create a HashMap that holds the MembershipKeys for multicast with every NioDatagramChannel even when most people not need it at al

Modifications:
Lazy create the HashMap when needed.

Result:
Less memory usage and less object creation
This commit is contained in:
Norman Maurer 2014-04-15 06:40:15 +02:00
parent 9cf92b3999
commit e8b5c9ccae

View File

@ -66,9 +66,8 @@ public final class NioDatagramChannel
private static final SelectorProvider DEFAULT_SELECTOR_PROVIDER = SelectorProvider.provider();
private final DatagramChannelConfig config;
private final Map<InetAddress, List<MembershipKey>> memberships =
new HashMap<InetAddress, List<MembershipKey>>();
private Map<InetAddress, List<MembershipKey>> memberships;
private RecvByteBufAllocator.Handle allocHandle;
private static DatagramChannel newSocket(SelectorProvider provider) {
@ -398,7 +397,12 @@ public final class NioDatagramChannel
}
synchronized (this) {
List<MembershipKey> keys = memberships.get(multicastAddress);
List<MembershipKey> keys = null;
if (memberships == null) {
memberships = new HashMap<InetAddress, List<MembershipKey>>();
} else {
keys = memberships.get(multicastAddress);
}
if (keys == null) {
keys = new ArrayList<MembershipKey>();
memberships.put(multicastAddress, keys);