activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From franz1981 <>
Subject [GitHub] activemq-artemis issue #1263: ARTEMIS-1156: FIX: Long Autoboxing occurring o...
Date Thu, 11 May 2017 07:24:39 GMT
Github user franz1981 commented on the issue:
    @michaelandrepearce Got it, there is another effective solution to this: build an interner,
similar to a  StringInterner, but with a different hashed logic in order to avoid the JVM
duplicating autoboxed instances each time. 
    Few lines of code to explain it better:
    //it will retain in LRU fashion the last 64 Long instances 
    LongInterner longCache = new LongInterner(64);
    long id;
    //instead of:
    put(id , connection);
    //interned instance
    Long cachedId = longCache.intern(id);
    put(cachedId, connection);
    The caching/escape analysis are different things AFAIK: 
    - caching is performed by the library on long->Long, and put by the compiler when autoboxing
(eg [Long::valueOf](

    - [escape analysis](
newly created Long instances no longer exists on the heap but being unpacked on the stack
if used temporary, but need to call by hand new Long(long), bypassing the cached logic and
do not retain it (seems not our case anyway)

If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at or file a JIRA ticket
with INFRA.

View raw message