[#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
8615f7a69e
commit
238af8cbd1
@ -65,9 +65,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) {
|
||||
@ -368,7 +367,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