James R. Perkins writes:
That said I still don't understand why initialization just can't be thread-safe. Using SubstitueLoggers and what not just hides the issue. The bottom line is initialization of a binder is not thread-safe and I see no reason why it shouldn't be. If it's just made thread-safe there is no need for all this substitute logger code.
As Chetan Mehrotra mentioned, with
SLF4J-302
fixed in release of SLF4J version 1.7.6 dated February 5th, 2014, Logger.FActory.TEMP_FACTORY emits SubstituteLoggers instances during the initialization phase. Once initialization is complete, SubstituteLogger instances delegate to regular loggers. Thus, it is only during the initialization phase that SubstituteLogger instances behave as NOPLoggers.
As for thread safeness of read/writes of the INITIALIZATION_STATE variable, I have made the following change, essentially a double-check lock on an int:
public static ILoggerFactory getILoggerFactory() {
if (INITIALIZATION_STATE == UNINITIALIZED) {
synchronized (LoggerFactory.class) {
if (INITIALIZATION_STATE == UNINITIALIZED) {
INITIALIZATION_STATE = ONGOING_INITIALIZATION;
performInitialization();
}
}
}
.. same as before
which can also be seen in commit c5ae991.
Please let me know if this change makes any difference.
|