-
CSR
-
Resolution: Unresolved
-
P4
-
None
-
behavioral
-
minimal
-
-
Java API
-
SE
Summary
Synchronization has been narrowed in the publish()
methods of java.util.logging.Handler
sub-classes to avoid deadlock risk.
Problem
By synchronizing around code which calls back to arbitrary user code when formatting LogRecord
instances, Handler
implementations will create conditions in which deadlocks can occur.
Solution
By narrowing the regions of code being explicitly synchronized, deadlock risk can be removed.
This necessarily requires removal of the synchronized
keywords on any implementations of the publish()
in StreamHandler
and its subclasses, but may also require changes within publish()
method implementations to narrow any synchronized regions. As StreamHandler
is publicly subclassable, this change to its publish()
method must be specified and new restrictions placed on overrides of this method.
Specification
Documentation change to java.util.logging.Handler
class-level JavaDoc:
+ * <p>
+ * Implementations of {@code Handler} should be thread-safe. Handlers are
+ * expected to be invoked concurrently from arbitrary threads. However,
+ * over-use of synchronization may result in unwanted thread contention,
+ * performance issues or even deadlocking.
*
* @since 1.4
*/
Api note for Handler publish method:
+ * <p>
+ * @apiNote To avoid the risk of deadlock, implementations of this method
+ * should avoid holding any locks while calling out to application code,
+ * such as the formatting of {@code LogRecord}.
*
* @param record description of the log event. A null record is
* silently ignored and is not published
*/
public abstract void publish(LogRecord record);
Specification change for java.util.logging.StreamHandler
:
*
+ * @implSpec This method avoids acquiring locks during {@code LogRecord}
+ * formatting, but {@code this} instance is synchronized when writing to the
+ * output stream. To avoid deadlock risk, subclasses must not hold locks
+ * while calling {@code super.publish()}. Specifically, subclasses must
+ * not define the overridden {@code publish()} method to be
+ * {@code synchronized} if they call {@code super.publish()}.
+ *
* @param record description of the log event. A null record is
* silently ignored and is not published
*/
@Override
public void publish(LogRecord record) {
- csr of
-
JDK-8349206 j.u.l.Handler classes create deadlock risk via synchronized publish() method
-
- Open
-