org.apache.logging.log4j.ThreadContext.removeStack()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(3.6k)|赞(0)|评价(0)|浏览(116)

本文整理了Java中org.apache.logging.log4j.ThreadContext.removeStack()方法的一些代码示例,展示了ThreadContext.removeStack()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ThreadContext.removeStack()方法的具体详情如下:
包路径:org.apache.logging.log4j.ThreadContext
类名称:ThreadContext
方法名:removeStack

ThreadContext.removeStack介绍

[英]Removes the diagnostic context for this thread.

Each thread that created a diagnostic context by calling #push should call this method before exiting. Otherwise, the memory used by the thread cannot be reclaimed by the VM.

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 #remove before exiting a thread. However, you must call remove sometime. If you never call it, then your application is sure to run out of memory.
[中]删除此线程的诊断上下文。
通过调用#push创建诊断上下文的每个线程都应该在退出之前调用此方法。否则,虚拟机无法回收线程使用的内存。
由于这在重载系统中是一个非常重要的问题,而且在退出线程之前很难始终保证调用remove方法,因此对该方法进行了扩展,以惰性地删除对死线程的引用。实际上,这意味着您可能会有点马虎,偶尔会忘记在退出线程之前调用#remove。但是,你必须找时间打电话给remove。如果你从未调用它,那么你的应用程序肯定会耗尽内存。

代码示例

代码示例来源:origin: org.apache.logging.log4j/log4j-1.2-api

/**
 * Remove the diagnostic context for this thread.
 * <p>
 * Each thread that created a diagnostic context by calling
 * {@link #push} 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 {@code remove} 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>
 */
public static void remove() {
  org.apache.logging.log4j.ThreadContext.removeStack();
}

代码示例来源:origin: org.apache.logging.log4j.adapters/log4j-1.2-api

/**
 * Remove the diagnostic context for this thread.
 * <p/>
 * <p>Each thread that created a diagnostic context by calling
 * {@link #push} 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 {@link #remove} 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.
 */
public static void remove() {
  org.apache.logging.log4j.ThreadContext.removeStack();
}

代码示例来源:origin: org.apache.logging.log4j/log4j12-api

/**
 * Remove the diagnostic context for this thread.
 * <p/>
 * <p>Each thread that created a diagnostic context by calling
 * {@link #push} 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 {@link #remove} 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.
 */
public static void remove() {
  org.apache.logging.log4j.ThreadContext.removeStack();
}

相关文章