我正在使用 VanillaChronicle 将一些消息写入磁盘。
public final class ConcurrentPersister{
private final String location;
private final Chronicle chronicle;
private final ExcerptAppender writer;
private final static int STRING_SIZE_OVERHEAD = 1000;
private final static String FILE_DATE_FORMAT = "MM-dd-yyyy";
private final static String NAME = "ConcurrentPersister";
private final static Logger LOGGER = LoggerFactory.getLogger( NAME );
public ConcurrentPersister( String location, VanillaChronicleConfig config ){
this.chronicle = new VanillaChronicle( location );
this.writer = chronicle.createAppender();
}
public final void appendMessage( final String message ){
try{
long length = STRING_SIZE_OVERHEAD + message.length();
writer.startExcerpt( length );
writer.append( message );
writer.finish();
}catch( Exception e ){
LOGGER.warn("Failed to persist Message [{}]", message );
LOGGER.warn("Exception: ", e );
}
}
}
如果从多个线程调用 appendMessage(String message) 方法,如上所示,是线程安全的吗?
我在某处读到 VanillaChronicle 的 append(String message) 是线程安全的。但是,我认为 startExcerpt() + append() + finish() 的复合动作不是线程安全的,这是否正确?
谢谢。