[#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:
parent
9cf92b3999
commit
e8b5c9ccae
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user