jia-gao commented on code in PR #1652:
URL: https://github.com/apache/samza/pull/1652#discussion_r1092286850
##########
samza-log4j2/src/main/java/org/apache/samza/logging/log4j2/StreamAppender.java:
##########
@@ -186,13 +190,20 @@ public void append(LogEvent event) {
if (!systemInitialized) {
// configs are needed to set up producer system, so check that before
actually initializing
if (this.loggingContextHolder.getConfig() != null) {
- synchronized (this) {
- if (!systemInitialized) {
- setupSystem();
- systemInitialized = true;
+ if (setUpSystemLock.tryLock(SET_UP_SYSTEM_TIMEOUT_MILLI_SECONDS,
TimeUnit.MILLISECONDS)) {
+ try {
+ if (!systemInitialized) {
+ setupSystem();
Review Comment:
Yes, it is supposed to be run only once.
I prefer not to set it to true within finally block because we want to make
sure it is only set to true if setupSystem() is completed successfully. In case
that setupSystem() fails (throwing some exceptions for example), we want to
leave it as false.
The same reason applies to the option of AtomicBoolean. there are two cons
for that:
1. same as above, can not make sure setupSystem() runs fine
2. perf reason, compareAndSet AtomicBoolean in line 190 means every time
LOG.xxx() StreamAppender needs to check the AtomicBoolean which is expensive
than checking a boolean
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]