blob: b9f0ecbff72e62772141701115d5b1986032dfe8 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (version 1.7.0_80) on Sat Mar 17 16:07:25 MST 2018 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>ThreadContext (Apache Log4j API 2.11.0 API)</title>
<meta name="date" content="2018-03-17">
<link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style">
</head>
<body>
<script type="text/javascript"><!--
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="ThreadContext (Apache Log4j API 2.11.0 API)";
}
//-->
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a name="navbar_top">
<!-- -->
</a><a href="#skip-navbar_top" title="Skip navigation links"></a><a name="navbar_top_firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="class-use/ThreadContext.html">Use</a></li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../index-all.html">Index</a></li>
<li><a href="../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../org/apache/logging/log4j/MarkerManager.Log4jMarker.html" title="class in org.apache.logging.log4j"><span class="strong">Prev Class</span></a></li>
<li><a href="../../../../org/apache/logging/log4j/ThreadContext.ContextStack.html" title="interface in org.apache.logging.log4j"><span class="strong">Next Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../index.html?org/apache/logging/log4j/ThreadContext.html" target="_top">Frames</a></li>
<li><a href="ThreadContext.html" target="_top">No Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../../../../allclasses-noframe.html">All Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_top");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li><a href="#nested_class_summary">Nested</a>&nbsp;|&nbsp;</li>
<li><a href="#field_summary">Field</a>&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method_summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li><a href="#field_detail">Field</a>&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method_detail">Method</a></li>
</ul>
</div>
<a name="skip-navbar_top">
<!-- -->
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<!-- ======== START OF CLASS DATA ======== -->
<div class="header">
<div class="subTitle">org.apache.logging.log4j</div>
<h2 title="Class ThreadContext" class="title">Class ThreadContext</h2>
</div>
<div class="contentContainer">
<ul class="inheritance">
<li><a href="https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">java.lang.Object</a></li>
<li>
<ul class="inheritance">
<li>org.apache.logging.log4j.ThreadContext</li>
</ul>
</li>
</ul>
<div class="description">
<ul class="blockList">
<li class="blockList">
<hr>
<br>
<pre>public final class <a href="../../../../src-html/org/apache/logging/log4j/ThreadContext.html#line.49">ThreadContext</a>
extends <a href="https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</a></pre>
<div class="block">The ThreadContext allows applications to store information either in a Map or a Stack.
<p>
<b><em>The MDC is managed on a per thread basis</em></b>. To enable automatic inheritance of <i>copies</i> of the MDC
to newly created threads, enable the Log4j system property.
</p></div>
<dl><dt><span class="strong">See Also:</span></dt><dd><a href="https://logging.apache.org/log4j/2.x/manual/thread-context.html">Thread Context Manual</a></dd></dl>
</li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">
<!-- ======== NESTED CLASS SUMMARY ======== -->
<ul class="blockList">
<li class="blockList"><a name="nested_class_summary">
<!-- -->
</a>
<h3>Nested Class Summary</h3>
<table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Nested Class Summary table, listing nested classes, and an explanation">
<caption><span>Nested Classes</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Class and Description</th>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static interface&nbsp;</code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/logging/log4j/ThreadContext.ContextStack.html" title="interface in org.apache.logging.log4j">ThreadContext.ContextStack</a></strong></code>
<div class="block">The ThreadContext Stack interface.</div>
</td>
</tr>
</table>
</li>
</ul>
<!-- =========== FIELD SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="field_summary">
<!-- -->
</a>
<h3>Field Summary</h3>
<table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Field Summary table, listing fields, and an explanation">
<caption><span>Fields</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Field and Description</th>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static <a href="https://docs.oracle.com/javase/7/docs/api/java/util/Map.html?is-external=true" title="class or interface in java.util">Map</a>&lt;<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>,<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&gt;</code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/logging/log4j/ThreadContext.html#EMPTY_MAP">EMPTY_MAP</a></strong></code>
<div class="block">Empty, immutable Map.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>static <a href="../../../../org/apache/logging/log4j/spi/ThreadContextStack.html" title="interface in org.apache.logging.log4j.spi">ThreadContextStack</a></code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/logging/log4j/ThreadContext.html#EMPTY_STACK">EMPTY_STACK</a></strong></code>
<div class="block">Empty, immutable ContextStack.</div>
</td>
</tr>
</table>
</li>
</ul>
<!-- ========== METHOD SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="method_summary">
<!-- -->
</a>
<h3>Method Summary</h3>
<table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation">
<caption><span>Methods</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Method and Description</th>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static void</code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/logging/log4j/ThreadContext.html#clearAll()">clearAll</a></strong>()</code>
<div class="block">Clears the context map and stack.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>static void</code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/logging/log4j/ThreadContext.html#clearMap()">clearMap</a></strong>()</code>
<div class="block">Clears the context map.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static void</code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/logging/log4j/ThreadContext.html#clearStack()">clearStack</a></strong>()</code>
<div class="block">Clears the stack for this thread.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>static <a href="../../../../org/apache/logging/log4j/ThreadContext.ContextStack.html" title="interface in org.apache.logging.log4j">ThreadContext.ContextStack</a></code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/logging/log4j/ThreadContext.html#cloneStack()">cloneStack</a></strong>()</code>
<div class="block">Returns a copy of this thread's stack.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static boolean</code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/logging/log4j/ThreadContext.html#containsKey(java.lang.String)">containsKey</a></strong>(<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&nbsp;key)</code>
<div class="block">Determines if the key is in the context.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>static <a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a></code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/logging/log4j/ThreadContext.html#get(java.lang.String)">get</a></strong>(<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&nbsp;key)</code>
<div class="block">Gets the context value identified by the <code>key</code> parameter.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static <a href="https://docs.oracle.com/javase/7/docs/api/java/util/Map.html?is-external=true" title="class or interface in java.util">Map</a>&lt;<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>,<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&gt;</code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/logging/log4j/ThreadContext.html#getContext()">getContext</a></strong>()</code>
<div class="block">Returns a mutable copy of current thread's context Map.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/logging/log4j/ThreadContext.html#getDepth()">getDepth</a></strong>()</code>
<div class="block">Gets the current nesting depth of this thread's stack.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static <a href="https://docs.oracle.com/javase/7/docs/api/java/util/Map.html?is-external=true" title="class or interface in java.util">Map</a>&lt;<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>,<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&gt;</code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/logging/log4j/ThreadContext.html#getImmutableContext()">getImmutableContext</a></strong>()</code>
<div class="block">Returns an immutable view of the current thread's context Map.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>static <a href="../../../../org/apache/logging/log4j/ThreadContext.ContextStack.html" title="interface in org.apache.logging.log4j">ThreadContext.ContextStack</a></code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/logging/log4j/ThreadContext.html#getImmutableStack()">getImmutableStack</a></strong>()</code>
<div class="block">Gets an immutable copy of this current thread's context stack.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static <a href="../../../../org/apache/logging/log4j/spi/ReadOnlyThreadContextMap.html" title="interface in org.apache.logging.log4j.spi">ReadOnlyThreadContextMap</a></code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/logging/log4j/ThreadContext.html#getThreadContextMap()">getThreadContextMap</a></strong>()</code>
<div class="block">Returns a read-only view of the internal data structure used to store thread context key-value pairs,
or <code>null</code> if the internal data structure does not implement the
<code>ReadOnlyThreadContextMap</code> interface.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>static boolean</code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/logging/log4j/ThreadContext.html#isEmpty()">isEmpty</a></strong>()</code>
<div class="block">Returns true if the Map is empty.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static <a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a></code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/logging/log4j/ThreadContext.html#peek()">peek</a></strong>()</code>
<div class="block">Looks at the last diagnostic context at the top of this NDC without removing it.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>static <a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a></code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/logging/log4j/ThreadContext.html#pop()">pop</a></strong>()</code>
<div class="block">Returns the value of the last item placed on the stack.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static void</code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/logging/log4j/ThreadContext.html#push(java.lang.String)">push</a></strong>(<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&nbsp;message)</code>
<div class="block">Pushes new diagnostic context information for the current thread.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>static void</code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/logging/log4j/ThreadContext.html#push(java.lang.String,%20java.lang.Object...)">push</a></strong>(<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&nbsp;message,
<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</a>...&nbsp;args)</code>
<div class="block">Pushes new diagnostic context information for the current thread.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static void</code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/logging/log4j/ThreadContext.html#put(java.lang.String,%20java.lang.String)">put</a></strong>(<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&nbsp;key,
<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&nbsp;value)</code>
<div class="block">Puts a context value (the <code>value</code> parameter) as identified with the <code>key</code> parameter into
the current thread's context map.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>static void</code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/logging/log4j/ThreadContext.html#putAll(java.util.Map)">putAll</a></strong>(<a href="https://docs.oracle.com/javase/7/docs/api/java/util/Map.html?is-external=true" title="class or interface in java.util">Map</a>&lt;<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>,<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&gt;&nbsp;m)</code>
<div class="block">Puts all given context map entries into the current thread's
context map.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static void</code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/logging/log4j/ThreadContext.html#remove(java.lang.String)">remove</a></strong>(<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&nbsp;key)</code>
<div class="block">Removes the context value identified by the <code>key</code> parameter.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>static void</code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/logging/log4j/ThreadContext.html#removeAll(java.lang.Iterable)">removeAll</a></strong>(<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/Iterable.html?is-external=true" title="class or interface in java.lang">Iterable</a>&lt;<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&gt;&nbsp;keys)</code>
<div class="block">Removes the context values identified by the <code>keys</code> parameter.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static void</code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/logging/log4j/ThreadContext.html#removeStack()">removeStack</a></strong>()</code>
<div class="block">Removes the diagnostic context for this thread.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>static void</code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/logging/log4j/ThreadContext.html#setStack(java.util.Collection)">setStack</a></strong>(<a href="https://docs.oracle.com/javase/7/docs/api/java/util/Collection.html?is-external=true" title="class or interface in java.util">Collection</a>&lt;<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&gt;&nbsp;stack)</code>
<div class="block">Sets this thread's stack.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static void</code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/logging/log4j/ThreadContext.html#trim(int)">trim</a></strong>(int&nbsp;depth)</code>
<div class="block">Trims elements from this diagnostic context.</div>
</td>
</tr>
</table>
<ul class="blockList">
<li class="blockList"><a name="methods_inherited_from_class_java.lang.Object">
<!-- -->
</a>
<h3>Methods inherited from class&nbsp;java.lang.<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</a></h3>
<code><a href="https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true#clone()" title="class or interface in java.lang">clone</a>, <a href="https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true#equals(java.lang.Object)" title="class or interface in java.lang">equals</a>, <a href="https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true#finalize()" title="class or interface in java.lang">finalize</a>, <a href="https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true#getClass()" title="class or interface in java.lang">getClass</a>, <a href="https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true#hashCode()" title="class or interface in java.lang">hashCode</a>, <a href="https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true#notify()" title="class or interface in java.lang">notify</a>, <a href="https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true#notifyAll()" title="class or interface in java.lang">notifyAll</a>, <a href="https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true#toString()" title="class or interface in java.lang">toString</a>, <a href="https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true#wait()" title="class or interface in java.lang">wait</a>, <a href="https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true#wait(long)" title="class or interface in java.lang">wait</a>, <a href="https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true#wait(long,%20int)" title="class or interface in java.lang">wait</a></code></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">
<!-- ============ FIELD DETAIL =========== -->
<ul class="blockList">
<li class="blockList"><a name="field_detail">
<!-- -->
</a>
<h3>Field Detail</h3>
<a name="EMPTY_MAP">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>EMPTY_MAP</h4>
<pre>public static final&nbsp;<a href="https://docs.oracle.com/javase/7/docs/api/java/util/Map.html?is-external=true" title="class or interface in java.util">Map</a>&lt;<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>,<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&gt; <a href="../../../../src-html/org/apache/logging/log4j/ThreadContext.html#line.182">EMPTY_MAP</a></pre>
<div class="block">Empty, immutable Map.</div>
</li>
</ul>
<a name="EMPTY_STACK">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>EMPTY_STACK</h4>
<pre>public static final&nbsp;<a href="../../../../org/apache/logging/log4j/spi/ThreadContextStack.html" title="interface in org.apache.logging.log4j.spi">ThreadContextStack</a> <a href="../../../../src-html/org/apache/logging/log4j/ThreadContext.html#line.189">EMPTY_STACK</a></pre>
<div class="block">Empty, immutable ContextStack.</div>
</li>
</ul>
</li>
</ul>
<!-- ============ METHOD DETAIL ========== -->
<ul class="blockList">
<li class="blockList"><a name="method_detail">
<!-- -->
</a>
<h3>Method Detail</h3>
<a name="put(java.lang.String, java.lang.String)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>put</h4>
<pre>public static&nbsp;void&nbsp;<a href="../../../../src-html/org/apache/logging/log4j/ThreadContext.html#line.245">put</a>(<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&nbsp;key,
<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&nbsp;value)</pre>
<div class="block">Puts a context value (the <code>value</code> parameter) as identified with the <code>key</code> parameter into
the current thread's context map.
<p>
If the current thread does not have a context map it is created as a side effect.
</p></div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>key</code> - The key name.</dd><dd><code>value</code> - The key value.</dd></dl>
</li>
</ul>
<a name="putAll(java.util.Map)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>putAll</h4>
<pre>public static&nbsp;void&nbsp;<a href="../../../../src-html/org/apache/logging/log4j/ThreadContext.html#line.258">putAll</a>(<a href="https://docs.oracle.com/javase/7/docs/api/java/util/Map.html?is-external=true" title="class or interface in java.util">Map</a>&lt;<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>,<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&gt;&nbsp;m)</pre>
<div class="block">Puts all given context map entries into the current thread's
context map.
<p>If the current thread does not have a context map it is
created as a side effect.</p></div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>m</code> - The map.</dd><dt><span class="strong">Since:</span></dt>
<dd>2.7</dd></dl>
</li>
</ul>
<a name="get(java.lang.String)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>get</h4>
<pre>public static&nbsp;<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&nbsp;<a href="../../../../src-html/org/apache/logging/log4j/ThreadContext.html#line.280">get</a>(<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&nbsp;key)</pre>
<div class="block">Gets the context value identified by the <code>key</code> parameter.
<p>
This method has no side effects.
</p></div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>key</code> - The key to locate.</dd>
<dt><span class="strong">Returns:</span></dt><dd>The value associated with the key or null.</dd></dl>
</li>
</ul>
<a name="remove(java.lang.String)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>remove</h4>
<pre>public static&nbsp;void&nbsp;<a href="../../../../src-html/org/apache/logging/log4j/ThreadContext.html#line.289">remove</a>(<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&nbsp;key)</pre>
<div class="block">Removes the context value identified by the <code>key</code> parameter.</div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>key</code> - The key to remove.</dd></dl>
</li>
</ul>
<a name="removeAll(java.lang.Iterable)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>removeAll</h4>
<pre>public static&nbsp;void&nbsp;<a href="../../../../src-html/org/apache/logging/log4j/ThreadContext.html#line.300">removeAll</a>(<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/Iterable.html?is-external=true" title="class or interface in java.lang">Iterable</a>&lt;<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&gt;&nbsp;keys)</pre>
<div class="block">Removes the context values identified by the <code>keys</code> parameter.</div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>keys</code> - The keys to remove.</dd><dt><span class="strong">Since:</span></dt>
<dd>2.8</dd></dl>
</li>
</ul>
<a name="clearMap()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>clearMap</h4>
<pre>public static&nbsp;void&nbsp;<a href="../../../../src-html/org/apache/logging/log4j/ThreadContext.html#line.315">clearMap</a>()</pre>
<div class="block">Clears the context map.</div>
</li>
</ul>
<a name="clearAll()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>clearAll</h4>
<pre>public static&nbsp;void&nbsp;<a href="../../../../src-html/org/apache/logging/log4j/ThreadContext.html#line.322">clearAll</a>()</pre>
<div class="block">Clears the context map and stack.</div>
</li>
</ul>
<a name="containsKey(java.lang.String)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>containsKey</h4>
<pre>public static&nbsp;boolean&nbsp;<a href="../../../../src-html/org/apache/logging/log4j/ThreadContext.html#line.333">containsKey</a>(<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&nbsp;key)</pre>
<div class="block">Determines if the key is in the context.</div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>key</code> - The key to locate.</dd>
<dt><span class="strong">Returns:</span></dt><dd>True if the key is in the context, false otherwise.</dd></dl>
</li>
</ul>
<a name="getContext()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>getContext</h4>
<pre>public static&nbsp;<a href="https://docs.oracle.com/javase/7/docs/api/java/util/Map.html?is-external=true" title="class or interface in java.util">Map</a>&lt;<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>,<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&gt;&nbsp;<a href="../../../../src-html/org/apache/logging/log4j/ThreadContext.html#line.342">getContext</a>()</pre>
<div class="block">Returns a mutable copy of current thread's context Map.</div>
<dl><dt><span class="strong">Returns:</span></dt><dd>a mutable copy of the context.</dd></dl>
</li>
</ul>
<a name="getImmutableContext()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>getImmutableContext</h4>
<pre>public static&nbsp;<a href="https://docs.oracle.com/javase/7/docs/api/java/util/Map.html?is-external=true" title="class or interface in java.util">Map</a>&lt;<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>,<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&gt;&nbsp;<a href="../../../../src-html/org/apache/logging/log4j/ThreadContext.html#line.351">getImmutableContext</a>()</pre>
<div class="block">Returns an immutable view of the current thread's context Map.</div>
<dl><dt><span class="strong">Returns:</span></dt><dd>An immutable view of the ThreadContext Map.</dd></dl>
</li>
</ul>
<a name="getThreadContextMap()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>getThreadContextMap</h4>
<pre>public static&nbsp;<a href="../../../../org/apache/logging/log4j/spi/ReadOnlyThreadContextMap.html" title="interface in org.apache.logging.log4j.spi">ReadOnlyThreadContextMap</a>&nbsp;<a href="../../../../src-html/org/apache/logging/log4j/ThreadContext.html#line.372">getThreadContextMap</a>()</pre>
<div class="block">Returns a read-only view of the internal data structure used to store thread context key-value pairs,
or <code>null</code> if the internal data structure does not implement the
<code>ReadOnlyThreadContextMap</code> interface.
<p>
The <a href="../../../../org/apache/logging/log4j/spi/DefaultThreadContextMap.html" title="class in org.apache.logging.log4j.spi"><code>DefaultThreadContextMap</code></a> implementation does not implement <code>ReadOnlyThreadContextMap</code>, so by
default this method returns <code>null</code>.
</p></div>
<dl><dt><span class="strong">Returns:</span></dt><dd>the internal data structure used to store thread context key-value pairs or <code>null</code></dd><dt><span class="strong">Since:</span></dt>
<dd>2.8</dd>
<dt><span class="strong">See Also:</span></dt><dd><a href="../../../../org/apache/logging/log4j/spi/ThreadContextMapFactory.html" title="class in org.apache.logging.log4j.spi"><code>ThreadContextMapFactory</code></a>,
<a href="../../../../org/apache/logging/log4j/spi/DefaultThreadContextMap.html" title="class in org.apache.logging.log4j.spi"><code>DefaultThreadContextMap</code></a>,
<code>CopyOnWriteSortedArrayThreadContextMap</code>,
<code>GarbageFreeSortedArrayThreadContextMap</code></dd></dl>
</li>
</ul>
<a name="isEmpty()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>isEmpty</h4>
<pre>public static&nbsp;boolean&nbsp;<a href="../../../../src-html/org/apache/logging/log4j/ThreadContext.html#line.381">isEmpty</a>()</pre>
<div class="block">Returns true if the Map is empty.</div>
<dl><dt><span class="strong">Returns:</span></dt><dd>true if the Map is empty, false otherwise.</dd></dl>
</li>
</ul>
<a name="clearStack()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>clearStack</h4>
<pre>public static&nbsp;void&nbsp;<a href="../../../../src-html/org/apache/logging/log4j/ThreadContext.html#line.388">clearStack</a>()</pre>
<div class="block">Clears the stack for this thread.</div>
</li>
</ul>
<a name="cloneStack()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>cloneStack</h4>
<pre>public static&nbsp;<a href="../../../../org/apache/logging/log4j/ThreadContext.ContextStack.html" title="interface in org.apache.logging.log4j">ThreadContext.ContextStack</a>&nbsp;<a href="../../../../src-html/org/apache/logging/log4j/ThreadContext.html#line.397">cloneStack</a>()</pre>
<div class="block">Returns a copy of this thread's stack.</div>
<dl><dt><span class="strong">Returns:</span></dt><dd>A copy of this thread's stack.</dd></dl>
</li>
</ul>
<a name="getImmutableStack()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>getImmutableStack</h4>
<pre>public static&nbsp;<a href="../../../../org/apache/logging/log4j/ThreadContext.ContextStack.html" title="interface in org.apache.logging.log4j">ThreadContext.ContextStack</a>&nbsp;<a href="../../../../src-html/org/apache/logging/log4j/ThreadContext.html#line.406">getImmutableStack</a>()</pre>
<div class="block">Gets an immutable copy of this current thread's context stack.</div>
<dl><dt><span class="strong">Returns:</span></dt><dd>an immutable copy of the ThreadContext stack.</dd></dl>
</li>
</ul>
<a name="setStack(java.util.Collection)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>setStack</h4>
<pre>public static&nbsp;void&nbsp;<a href="../../../../src-html/org/apache/logging/log4j/ThreadContext.html#line.416">setStack</a>(<a href="https://docs.oracle.com/javase/7/docs/api/java/util/Collection.html?is-external=true" title="class or interface in java.util">Collection</a>&lt;<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&gt;&nbsp;stack)</pre>
<div class="block">Sets this thread's stack.</div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>stack</code> - The stack to use.</dd></dl>
</li>
</ul>
<a name="getDepth()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>getDepth</h4>
<pre>public static&nbsp;int&nbsp;<a href="../../../../src-html/org/apache/logging/log4j/ThreadContext.html#line.431">getDepth</a>()</pre>
<div class="block">Gets the current nesting depth of this thread's stack.</div>
<dl><dt><span class="strong">Returns:</span></dt><dd>the number of items in the stack.</dd><dt><span class="strong">See Also:</span></dt><dd><a href="../../../../org/apache/logging/log4j/ThreadContext.html#trim(int)"><code>trim(int)</code></a></dd></dl>
</li>
</ul>
<a name="pop()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>pop</h4>
<pre>public static&nbsp;<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&nbsp;<a href="../../../../src-html/org/apache/logging/log4j/ThreadContext.html#line.445">pop</a>()</pre>
<div class="block">Returns the value of the last item placed on the stack.
<p>
The returned value is the value that was pushed last. If no context is available, then the empty string "" is
returned.
</p></div>
<dl><dt><span class="strong">Returns:</span></dt><dd>String The innermost diagnostic context.</dd></dl>
</li>
</ul>
<a name="peek()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>peek</h4>
<pre>public static&nbsp;<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&nbsp;<a href="../../../../src-html/org/apache/logging/log4j/ThreadContext.html#line.459">peek</a>()</pre>
<div class="block">Looks at the last diagnostic context at the top of this NDC without removing it.
<p>
The returned value is the value that was pushed last. If no context is available, then the empty string "" is
returned.
</p></div>
<dl><dt><span class="strong">Returns:</span></dt><dd>String The innermost diagnostic context.</dd></dl>
</li>
</ul>
<a name="push(java.lang.String)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>push</h4>
<pre>public static&nbsp;void&nbsp;<a href="../../../../src-html/org/apache/logging/log4j/ThreadContext.html#line.472">push</a>(<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&nbsp;message)</pre>
<div class="block">Pushes new diagnostic context information for the current thread.
<p>
The contents of the <code>message</code> parameter is determined solely by the client.
</p></div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>message</code> - The new diagnostic context information.</dd></dl>
</li>
</ul>
<a name="push(java.lang.String, java.lang.Object...)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>push</h4>
<pre>public static&nbsp;void&nbsp;<a href="../../../../src-html/org/apache/logging/log4j/ThreadContext.html#line.488">push</a>(<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&nbsp;message,
<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</a>...&nbsp;args)</pre>
<div class="block">Pushes new diagnostic context information for the current thread.
<p>
The contents of the <code>message</code> and args parameters are determined solely by the client. The message
will be treated as a format String and tokens will be replaced with the String value of the arguments in
accordance with ParameterizedMessage.
</p></div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>message</code> - The new diagnostic context information.</dd><dd><code>args</code> - Parameters for the message.</dd></dl>
</li>
</ul>
<a name="removeStack()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>removeStack</h4>
<pre>public static&nbsp;void&nbsp;<a href="../../../../src-html/org/apache/logging/log4j/ThreadContext.html#line.508">removeStack</a>()</pre>
<div class="block">Removes the diagnostic context for this thread.
<p>
Each thread that created a diagnostic context by calling <a href="../../../../org/apache/logging/log4j/ThreadContext.html#push(java.lang.String)"><code>push(java.lang.String)</code></a> should call this method before exiting.
Otherwise, the memory used by the <b>thread</b> cannot be reclaimed by the VM.
</p>
<p>
As this is such an important problem in heavy duty systems and because it is difficult to always guarantee that
the remove method is called before exiting a thread, this method has been augmented to lazily remove references
to dead threads. In practice, this means that you can be a little sloppy and occasionally forget to call
<a href="../../../../org/apache/logging/log4j/ThreadContext.html#remove(java.lang.String)"><code>remove(java.lang.String)</code></a> before exiting a thread. However, you must call <code>remove</code> sometime. If you never call
it, then your application is sure to run out of memory.
</p></div>
</li>
</ul>
<a name="trim(int)">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>trim</h4>
<pre>public static&nbsp;void&nbsp;<a href="../../../../src-html/org/apache/logging/log4j/ThreadContext.html#line.544">trim</a>(int&nbsp;depth)</pre>
<div class="block">Trims elements from this diagnostic context. If the current depth is smaller or equal to <code>maxDepth</code>,
then no action is taken. If the current depth is larger than newDepth then all elements at maxDepth or higher are
discarded.
<p>
This method is a convenient alternative to multiple <a href="../../../../org/apache/logging/log4j/ThreadContext.html#pop()"><code>pop()</code></a> calls. Moreover, it is often the case that at
the end of complex call sequences, the depth of the ThreadContext is unpredictable. The <code>trim</code> method
circumvents this problem.
</p>
<p>
For example, the combination
</p>
<pre>
void foo() {
final int depth = ThreadContext.getDepth();
// ... complex sequence of calls
ThreadContext.trim(depth);
}
</pre>
<p>
ensures that between the entry and exit of <code>foo</code> the depth of the diagnostic stack is conserved.
</p></div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>depth</code> - The number of elements to keep.</dd><dt><span class="strong">See Also:</span></dt><dd><a href="../../../../org/apache/logging/log4j/ThreadContext.html#getDepth()"><code>getDepth()</code></a></dd></dl>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
<!-- ========= END OF CLASS DATA ========= -->
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar_bottom">
<!-- -->
</a><a href="#skip-navbar_bottom" title="Skip navigation links"></a><a name="navbar_bottom_firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="class-use/ThreadContext.html">Use</a></li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../index-all.html">Index</a></li>
<li><a href="../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../org/apache/logging/log4j/MarkerManager.Log4jMarker.html" title="class in org.apache.logging.log4j"><span class="strong">Prev Class</span></a></li>
<li><a href="../../../../org/apache/logging/log4j/ThreadContext.ContextStack.html" title="interface in org.apache.logging.log4j"><span class="strong">Next Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../index.html?org/apache/logging/log4j/ThreadContext.html" target="_top">Frames</a></li>
<li><a href="ThreadContext.html" target="_top">No Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../../../../allclasses-noframe.html">All Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_bottom");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li><a href="#nested_class_summary">Nested</a>&nbsp;|&nbsp;</li>
<li><a href="#field_summary">Field</a>&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method_summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li><a href="#field_detail">Field</a>&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method_detail">Method</a></li>
</ul>
</div>
<a name="skip-navbar_bottom">
<!-- -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
<p class="legalCopy"><small><p align="center">Copyright &#169; 1999-2018 <a href="https://www.apache.org/">The Apache Software Foundation</a>. All Rights Reserved.<br /> Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.</p></small></p>
</body>
</html>