Return-Path: X-Original-To: apmail-logging-log4j-dev-archive@www.apache.org Delivered-To: apmail-logging-log4j-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E39EF190AA for ; Tue, 5 Apr 2016 15:04:25 +0000 (UTC) Received: (qmail 20052 invoked by uid 500); 5 Apr 2016 15:04:25 -0000 Delivered-To: apmail-logging-log4j-dev-archive@logging.apache.org Received: (qmail 19986 invoked by uid 500); 5 Apr 2016 15:04:25 -0000 Mailing-List: contact log4j-dev-help@logging.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Log4J Developers List" Reply-To: "Log4J Developers List" Delivered-To: mailing list log4j-dev@logging.apache.org Received: (qmail 19875 invoked by uid 99); 5 Apr 2016 15:04:25 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Apr 2016 15:04:25 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id 884462C1F5A for ; Tue, 5 Apr 2016 15:04:25 +0000 (UTC) Date: Tue, 5 Apr 2016 15:04:25 +0000 (UTC) From: "Greg Thomas (JIRA)" To: log4j-dev@logging.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (LOG4J2-1348) Add an AutoCloseable ThreadContext class: CloseableThreadContext MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/LOG4J2-1348?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15226415#comment-15226415 ] Greg Thomas commented on LOG4J2-1348: ------------------------------------- The static method can't return `this` - but there's no reason why `put(...)` / `push(...)` couldn't be instance methods as well as static methods. Something like {code} public static put(String key, String value) { return new CloseableThreadContext().put(key, value); } public CloseableThreadContext put(String key, String value) { ... return this; } {code} However, this still requires new object creation, hence requiring garbage collection. > Add an AutoCloseable ThreadContext class: CloseableThreadContext > ---------------------------------------------------------------- > > Key: LOG4J2-1348 > URL: https://issues.apache.org/jira/browse/LOG4J2-1348 > Project: Log4j 2 > Issue Type: Improvement > Components: API > Reporter: Greg Thomas > Assignee: Gary Gregory > Priority: Minor > Fix For: 2.6 > > Attachments: CloseableThreadContext.zip, thread-context.xml.patch > > > The log4j2 API provides a ThreadContext - https://logging.apache.org/log4j/2.x/manual/thread-context.html - that allows items to be added to a stack or a map for logging, and then subsequently removed once they are no longer required. > This sounds like an ideal candidate for a AutoCloseable implementation so that items are removed automatically and no longer left around littering the stack/map. -- This message was sent by Atlassian JIRA (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org For additional commands, e-mail: log4j-dev-help@logging.apache.org