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 static org.apache.logging.log4j.internal.map.UnmodifiableArrayBackedMap.getMap;
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 default implementation of {@link ThreadContextMap}
*
* An instance of UnmodifiableArrayBackedMap can be represented as a single {@code Object[]}, which can safely
* be stored on the {@code ThreadLocal} with no fear of classloader-related memory leaks.
*
*
* Performance of the underlying {@link org.apache.logging.log4j.internal.map.UnmodifiableArrayBackedMap} exceeds
* {@link HashMap} in all supported operations other than {@code get()}. Note that {@code get()} performance scales
* linearly with the current map size, and callers are advised to minimize this work.
*
*/
public class DefaultThreadContextMap implements ThreadContextMap, ReadOnlyStringMap {
private static final long serialVersionUID = -2635197170958057849L;
/**
* 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 ThreadLocal