| <!DOCTYPE HTML> |
| <html lang="en"> |
| <head> |
| <!-- Generated by javadoc (17) --> |
| <title>AsynchronouslyFormattable (Apache Log4j API 2.23.1 API)</title> |
| <meta name="viewport" content="width=device-width, initial-scale=1"> |
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| <meta name="description" content="declaration: package: org.apache.logging.log4j.message, annotation type: AsynchronouslyFormattable"> |
| <meta name="generator" content="javadoc/ClassWriterImpl"> |
| <link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style"> |
| <link rel="stylesheet" type="text/css" href="../../../../../script-dir/jquery-ui.min.css" title="Style"> |
| <link rel="stylesheet" type="text/css" href="../../../../../jquery-ui.overrides.css" title="Style"> |
| <script type="text/javascript" src="../../../../../script.js"></script> |
| <script type="text/javascript" src="../../../../../script-dir/jquery-3.6.1.min.js"></script> |
| <script type="text/javascript" src="../../../../../script-dir/jquery-ui.min.js"></script> |
| </head> |
| <body class="class-declaration-page"> |
| <script type="text/javascript">var pathtoroot = "../../../../../"; |
| loadScripts(document, 'script');</script> |
| <noscript> |
| <div>JavaScript is disabled on your browser.</div> |
| </noscript> |
| <div class="flex-box"> |
| <header role="banner" class="flex-header"> |
| <nav role="navigation"> |
| <!-- ========= START OF TOP NAVBAR ======= --> |
| <div class="top-nav" id="navbar-top"> |
| <div class="skip-nav"><a href="#skip-navbar-top" title="Skip navigation links">Skip navigation links</a></div> |
| <ul id="navbar-top-firstrow" class="nav-list" title="Navigation"> |
| <li><a href="../../../../../index.html">Overview</a></li> |
| <li><a href="package-summary.html">Package</a></li> |
| <li class="nav-bar-cell1-rev">Class</li> |
| <li><a href="class-use/AsynchronouslyFormattable.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#class">Help</a></li> |
| </ul> |
| </div> |
| <div class="sub-nav"> |
| <div> |
| <ul class="sub-nav-list"> |
| <li>Summary: </li> |
| <li>Field | </li> |
| <li>Optional | </li> |
| <li>Required</li> |
| </ul> |
| <ul class="sub-nav-list"> |
| <li>Detail: </li> |
| <li>Field | </li> |
| <li>Element</li> |
| </ul> |
| </div> |
| <div class="nav-list-search"><label for="search-input">SEARCH:</label> |
| <input type="text" id="search-input" value="search" disabled="disabled"> |
| <input type="reset" id="reset-button" value="reset" disabled="disabled"> |
| </div> |
| </div> |
| <!-- ========= END OF TOP NAVBAR ========= --> |
| <span class="skip-nav" id="skip-navbar-top"></span></nav> |
| </header> |
| <div class="flex-content"> |
| <main role="main"> |
| <!-- ======== START OF CLASS DATA ======== --> |
| <div class="header"> |
| <div class="sub-title"><span class="package-label-in-type">Package</span> <a href="package-summary.html">org.apache.logging.log4j.message</a></div> |
| <h1 title="Annotation Type AsynchronouslyFormattable" class="title">Annotation Type AsynchronouslyFormattable</h1> |
| </div> |
| <section class="class-description" id="class-description"> |
| <hr> |
| <div class="type-signature"><span class="annotations"><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/annotation/Documented.html" title="class or interface in java.lang.annotation" class="external-link">@Documented</a> |
| <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/annotation/Target.html" title="class or interface in java.lang.annotation" class="external-link">@Target</a>(<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/annotation/ElementType.html#TYPE" title="class or interface in java.lang.annotation" class="external-link">TYPE</a>) |
| <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/annotation/Retention.html" title="class or interface in java.lang.annotation" class="external-link">@Retention</a>(<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/annotation/RetentionPolicy.html#RUNTIME" title="class or interface in java.lang.annotation" class="external-link">RUNTIME</a>) |
| </span><span class="modifiers">public @interface </span><span class="element-name type-name-label">AsynchronouslyFormattable</span></div> |
| <div class="block">Annotation that signals to asynchronous logging components that messages of this type can safely be passed to |
| a background thread without calling <a href="Message.html#getFormattedMessage()"><code>Message.getFormattedMessage()</code></a> first. |
| <p> |
| Generally, logging mutable objects asynchronously always has the risk that the object is modified between the time |
| the logger is called and the time the log message is formatted and written to disk. Strictly speaking it is the |
| responsibility of the application to ensure that mutable objects are not modified after they have been logged, |
| but this is not always possible. |
| </p><p> |
| Log4j prevents the above race condition as follows: |
| </p><ol> |
| <li>If the Message implements <a href="ReusableMessage.html" title="interface in org.apache.logging.log4j.message"><code>ReusableMessage</code></a>, asynchronous logging components in the Log4j implementation |
| will copy the message content (formatted message, parameters) onto the queue rather than passing the |
| <code>Message</code> instance itself. This ensures that the formatted message will not change |
| when the mutable object is modified. |
| </li> |
| <li>If the Message is annotated with <a href="AsynchronouslyFormattable.html" title="annotation in org.apache.logging.log4j.message"><code>AsynchronouslyFormattable</code></a>, it can be passed to another thread as is.</li> |
| <li>Otherwise, asynchronous logging components in the Log4j implementation will call |
| <a href="Message.html#getFormattedMessage()"><code>Message.getFormattedMessage()</code></a> before passing the Message object to another thread. |
| This gives the Message implementation class a chance to create a formatted message String with the current value |
| of the mutable object. The intention is that the Message implementation caches this formatted message and returns |
| it on subsequent calls. |
| (See <a href="https://issues.apache.org/jira/browse/LOG4J2-763">LOG4J2-763</a>.) |
| </li> |
| </ol></div> |
| <dl class="notes"> |
| <dt>Since:</dt> |
| <dd>2.8</dd> |
| <dt>See Also:</dt> |
| <dd> |
| <ul class="see-list"> |
| <li><a href="Message.html" title="interface in org.apache.logging.log4j.message"><code>Message</code></a></li> |
| <li><a href="ReusableMessage.html" title="interface in org.apache.logging.log4j.message"><code>ReusableMessage</code></a></li> |
| <li><a href="https://issues.apache.org/jira/browse/LOG4J2-763">LOG4J2-763</a></li> |
| </ul> |
| </dd> |
| </dl> |
| </section> |
| <!-- ========= END OF CLASS DATA ========= --> |
| </main> |
| <footer role="contentinfo"> |
| <hr> |
| <p class="legal-copy"><small><p align="center"> Copyright © 1999-2024 <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> |
| </footer> |
| </div> |
| </div> |
| </body> |
| </html> |