[ https://issues.apache.org/jira/browse/LOG4J2-1397?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15322120#comment-15322120 ]
Remko Popma commented on LOG4J2-1397: ------------------------------------- In that case you need to use an AtomicLong instead of a primitive long. The preAllocated array is not modified during the life of the program so is safe to use from multiple threads, as long as each buffer is only accessed by a single thread, which the AtomicLong counter guarantees: {code} ByteBuffer[] preAllocated = ... AtomicLong counter = new AtomicLong(); private void onMessage(ByteBuffer data) { ... long current = counter.incrementAndGet(); ByteBuffer copy = preAllocated[MASK & current]; } {code} I was wrong about the number of pre-allocated buffers necessary: you need {{LoggerRingBufferSize + ThreadCount}}. That way you will never overwrite a pre-allocated buffer that has not been logged yet. When the AsyncLogger RingBuffer is full the AsyncLogger will block until a RingBuffer slot becomes available. > Support ByteBufferLayout > ------------------------ > > Key: LOG4J2-1397 > URL: https://issues.apache.org/jira/browse/LOG4J2-1397 > Project: Log4j 2 > Issue Type: New Feature > Components: Layouts > Affects Versions: 2.6 > Reporter: Remko Popma > > As requested by Kirk Pepperdine on the Mechanical Sympathy [mailing > list|https://groups.google.com/d/msg/mechanical-sympathy/klefjRqlpQE/-1WF59IGAwAJ]: > Support a new Layout that takes ObjectMessages containing a ByteBuffer > payload and write them to the appender without modification. -- This message was sent by Atlassian JIRA (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: log4j-dev-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-dev-h...@logging.apache.org