org.apache.logging.log4j.spi.DefaultThreadContextMap Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.logging.log4j.spi;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import org.apache.logging.log4j.util.BiConsumer;
import org.apache.logging.log4j.util.PropertiesUtil;
import org.apache.logging.log4j.util.ReadOnlyStringMap;
import org.apache.logging.log4j.util.TriConsumer;
/**
* The actual ThreadContext Map. A new ThreadContext Map is created each time it is updated and the Map stored is always
* immutable. This means the Map can be passed to other threads without concern that it will be updated. Since it is
* expected that the Map will be passed to many more log events than the number of keys it contains the performance
* should be much better than if the Map was copied for each event.
*/
public class DefaultThreadContextMap implements ThreadContextMap, ReadOnlyStringMap {
private static final long serialVersionUID = 8218007901108944053L;
/**
* Property name ({@value} ) for selecting {@code InheritableThreadLocal} (value "true") or plain
* {@code ThreadLocal} (value is not "true") in the implementation.
*/
public static final String INHERITABLE_MAP = "isThreadContextMapInheritable";
private final boolean useMap;
private final ThreadLocal