[logback-dev] [JIRA] (LOGBACK-1476) Avoid synchronized blocks when copying MDC to a function-local map

QOS.CH (JIRA) noreply-jira at qos.ch
Wed Jul 24 14:01:00 CEST 2019


Daniel Knittl-Frank created LOGBACK-1476:
--------------------------------------------

             Summary: Avoid synchronized blocks when copying MDC to a function-local map
                 Key: LOGBACK-1476
                 URL: https://jira.qos.ch/browse/LOGBACK-1476
             Project: logback
          Issue Type: Improvement
            Reporter: Daniel Knittl-Frank
            Assignee: Logback dev list


When setting or duplicating the MDC context map, a synchronized map is used. This incurs the overhead of locking when putting key-value pairs into the map. This overhead can be avoided, because the map is method-local and only a single thread can access it a single time.

Delay wrapping the map in a synchronizedMap until before it leaves the scope of the method.

You can find the proposed changes inĀ [https://github.com/qos-ch/logback/pull/462|https://github.com/qos-ch/logback/pull/462/files]

I have not performed any benchmarks and would appreciate if somebody could write some. Maybe the JVM is already clever enough to detect this useless synchronization and elides the lock?



--
This message was sent by Atlassian JIRA
(v7.3.1#73012)


More information about the logback-dev mailing list