[#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
837ddc01d2
commit
17334a0a42
@ -64,9 +64,8 @@ public final class NioDatagramChannel
|
|||||||
private static final SelectorProvider DEFAULT_SELECTOR_PROVIDER = SelectorProvider.provider();
|
private static final SelectorProvider DEFAULT_SELECTOR_PROVIDER = SelectorProvider.provider();
|
||||||
|
|
||||||
private final DatagramChannelConfig config;
|
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 RecvByteBufAllocator.Handle allocHandle;
|
||||||
|
|
||||||
private static DatagramChannel newSocket(SelectorProvider provider) {
|
private static DatagramChannel newSocket(SelectorProvider provider) {
|
||||||
@ -367,7 +366,12 @@ public final class NioDatagramChannel
|
|||||||
}
|
}
|
||||||
|
|
||||||
synchronized (this) {
|
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) {
|
if (keys == null) {
|
||||||
keys = new ArrayList<MembershipKey>();
|
keys = new ArrayList<MembershipKey>();
|
||||||
memberships.put(multicastAddress, keys);
|
memberships.put(multicastAddress, keys);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user