Context: I am using netty and have defined a handler in order to count and categorize incoming/outgoing traffic. For this I have used an enumMap that looks like this:
EnumMap<MyEnum, AtomicLong>
However now I have realized that there is only one thread that is manipulating the values (previously I thought it was more than one, netty seems to guarantee that one thread per channel). This means that AtomicLong is not necessary. However, as AtomicLong is a wrapper for a primitive long meanwhile Long is an immutable type, I have a reason to think that just swapping AtomicLong to Long will be less performant.
Any ideas on this?
What I probably should do is to move to int and remove the whole enumMap thing..
BR Sebastian
Assuming you have only one thread:
AtomicLong can be faster than using Long, if it avoid object creation.
Fast again is to use long[]
or not use objects at all with a collection like TObjectLongHashMap
I can't image that given:
in order to count and categorize incoming/outgoing traffic
that a conversion from AtomicLong
to Long
(or long
) will have any impact at all upon your performance.
我们使用LongAdder同样的事情;)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.