AtomicLong vs. Long Performance

Context: I use netty and defined a handler to count and classify inbound / outbound traffic. For this, I used enumMap, which looks like this:

EnumMap<MyEnum, AtomicLong> 

However, now I realized that there is only one thread that manipulates the values ​​(previously I thought it was more than one, netty seems to guarantee that there is one thread per channel). This means that AtomicLong is not required. However, since AtomicLong is a wrapper for a primitive long time, Long Long is an immutable type, I have reason to think that simply replacing AtomicLong with Long will be less efficient.

Any ideas on this?

What I probably should do is go to int and delete the entire enumMap entry.

BR Sebastian

+4
source share
3 answers

Assuming you have only one thread:

AtomicLong can be faster than using Long if it does not allow objects to be created.

Quickly use long[] again or not use collection objects at all, for example TObjectLongHashMap

+3
source

I can not imagine that this:

to count and classify incoming / outgoing traffic

that converting from AtomicLong to Long (or Long ) will have any effect on your performance.

+1
source

We use LongAdder for the same question;)

0
source

Source: https://habr.com/ru/post/1440001/


All Articles