There is not enough heap memory (increase it with -Xmx, e.g. -Xmx512m ). When free memory goes very low, a lot of time is spent on the garbage collector, which violently scans the heap for unreachable objects.
Your hashCode () is fine, extra points to use all bits of cycleId long.
Edit Now I saw that you increased your memory and did not help. First of all, are you sure that you managed to increase your memory? You can check this on jconsole, connect to your application and see its heap size.
To find an alternative explanation, is there any specific pattern in your cycleId that can make this hashCode () implementation bad? For example, its 32 high order bits are mostly similar to the 32 low order bits. (Yes, right).
But no. Even if this is the case, you will see a gradual decrease in performance, rather than a sharp drop to a certain point (and you will get an OutOfMemoryError and frenzy gc operation). Therefore, my best guess is still a memory problem. You either did not increase the heap size as you thought , or at some point there is some other memory. (You can use a tool like VisualVM to profile it and get a heap dump on OOME and see what objects it contains).
Edit2 I highlighted the correct part above.
Dimitris andreou
source share