Class MDCs


  • @Beta
    public final class MDCs
    extends Object
    Utility methods for MDC.
    Author:
    Michael Vorburger.ch
    • Method Detail

      • put

        public static void put​(String key,
                               String val)
        Minor improvement over MDC.put(String, String). Specifically, it:
        • tests if there already is an entry for the given key (to detect forgotten remove, instead of overwriting)
        • does not accept null as val
        Throws:
        IllegalArgumentException - if val is value is already set (and was previously not MDC.remove(String))
      • putRunRemove

        public static void putRunRemove​(String key,
                                        String val,
                                        Runnable runnable)
        put(String, String) a key/val into the MDC, runs the provided Runnable, and (ensure that) the given key is MDC.remove(String)'d (even if there was an exception).
      • putRunRemove

        public static void putRunRemove​(MDCEntry entry,
                                        Runnable runnable)
      • putRunRemove

        public static void putRunRemove​(Map<String,​String> keysValues,
                                        Runnable runnable)
        put(String, String) each key/val of the passed Map into the MDC, runs the provided Runnable, and (ensure that) the all keys of the Map are MDC.remove(String)'d (even if there was an exception).
      • putRunRemove

        public static void putRunRemove​(Runnable runnable,
                                        MDCEntry... keysValues)