@@ -102,7 +102,7 @@ private void removeLogger(Reference<? extends Logger> loggerRef) {
102102 /**
103103 * Returns the logger associated with the given name and message factory.
104104 *
105- * @param name a logger name
105+ * @param name a logger name
106106 * @param messageFactory a message factory
107107 * @return the logger associated with the given name and message factory
108108 */
@@ -150,7 +150,7 @@ public Collection<Logger> getLoggers() {
150150 /**
151151 * Checks if a logger associated with the given name and message factory exists.
152152 *
153- * @param name a logger name
153+ * @param name a logger name
154154 * @param messageFactory a message factory
155155 * @return {@code true}, if the logger exists; {@code false} otherwise.
156156 */
@@ -161,10 +161,9 @@ public boolean hasLogger(final String name, final MessageFactory messageFactory)
161161 }
162162
163163 /**
164- * Checks if a logger associated with the given name and message factory type
165- * exists.
164+ * Checks if a logger associated with the given name and message factory type exists.
166165 *
167- * @param name a logger name
166+ * @param name a logger name
168167 * @param messageFactoryClass a message factory class
169168 * @return {@code true}, if the logger exists; {@code false} otherwise.
170169 */
@@ -188,12 +187,14 @@ public Logger computeIfAbsent(
188187 final MessageFactory messageFactory ,
189188 final BiFunction <String , MessageFactory , Logger > loggerSupplier ) {
190189
190+ // Check arguments
191191 requireNonNull (name , "name" );
192192 requireNonNull (messageFactory , "messageFactory" );
193193 requireNonNull (loggerSupplier , "loggerSupplier" );
194194
195195 expungeStaleEntries (); // Clean up before adding a new logger
196196
197+ // Read lock fast path: See if logger already exists
197198 @ Nullable Logger logger = getLogger (name , messageFactory );
198199 if (logger != null ) {
199200 return logger ;
@@ -204,19 +205,15 @@ public Logger computeIfAbsent(
204205 // - Logger instantiation is expensive (causes contention on the write-lock)
205206 //
206207 // - User code might have circular code paths, though through different threads.
207- // Consider `T1[ILR:computeIfAbsent] -> ... -> T1[Logger::new] -> ... ->
208- // T2[ILR::computeIfAbsent]`.
209- // Hence, having logger instantiation while holding a write lock might cause
210- // deadlocks:
211- // https://github.com/apache/logging-log4j2/issues/3252
212- // https://github.com/apache/logging-log4j2/issues/3399
208+ // Consider `T1[ILR:computeIfAbsent] -> ... -> T1[Logger::new] -> ... -> T2[ILR::computeIfAbsent]`.
209+ // Hence, having logger instantiation while holding a write lock might cause deadlocks:
210+ // https://github.com/apache/logging-log4j2/issues/3252
211+ // https://github.com/apache/logging-log4j2/issues/3399
213212 //
214- // - Creating loggers without a lock, allows multiple threads to create loggers
215- // in parallel, which also improves
213+ // - Creating loggers without a lock, allows multiple threads to create loggers in parallel, which also improves
216214 // performance.
217215 //
218- // Since all loggers with the same parameters are equivalent, we can safely
219- // return the logger from the
216+ // Since all loggers with the same parameters are equivalent, we can safely return the logger from the
220217 // thread that finishes first.
221218 Logger newLogger = loggerSupplier .apply (name , messageFactory );
222219
0 commit comments