VanillaChronicle has a ThreadLocal cache of appenders/tailers:
public VanillaAppender createAppender() throws IOException {
WeakReference<VanillaAppender> ref = appenderCache.get();
VanillaAppender appender = null;
if (ref != null)
appender = ref.get();
if (appender == null) {
appender = createAppender0();
appenderCache.set(new WeakReference<VanillaAppender>(appender));
}
return appender;
}
If you do not have thousand short living threads you can use createAppender in your appendMessage method
public final void appendMessage( final String message ) {
try {
ExcerptAppender writer = chronicle.createAppender();
writer.startExcerpt( STRING_SIZE_OVERHEAD + message.length() );
writer.append( message );
writer.finish();
} catch( Exception e ) {
LOGGER.warn("Failed to persist Message [{}]", message );
LOGGER.warn("Exception: ", e );
}
}
I read somewhere that VanillaChronicle's
append(String message)
is thread-safe. However, am I correct in thinking that the compound action ofstartExcerpt()
+append()
+finish()
is NOT thread-safe?
VanillaChronicle can be used by concurrent thread, even concurrent processes, provided each thread uses it's own appender.