You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* [Comma separated list of values](#comma-separated-list-of-values)
93
94
@@ -963,7 +964,42 @@ input {
963
964
}
964
965
```
965
966
967
+
### Threads and ThreadLocals
966
968
969
+
Asynchronous appenders use a separate set of threads to process logging events.
970
+
971
+
The encoders/layouts use ThreadLocals internally to improve performance.
972
+
973
+
In environments that support application reloading (e.g. web containers)
974
+
and in applications with many threads logging events (e.g. virtual threads),
975
+
it is recommended to:
976
+
1. use an asynchronous appender (such as `LogstashTcpSocketAppender`, `LoggingEventAsyncDisruptorAppender`, or [`AsyncAppender`](https://logback.qos.ch/manual/appenders.html#AsyncAppender)), and
977
+
2.[cleanly shut down logback](http://logback.qos.ch/manual/configuration.html#stopContext) when the application is stopped/reloaded.
978
+
979
+
980
+
Using an asynchronous appender ensures that a limited number of threads use the encoder/layout,
981
+
and therefore limits the number of ThreadLocal value instances
982
+
and minimizes resource contention.
983
+
984
+
Cleanly shutting down logback stops the threads used by the asynchronous appender,
985
+
and makes their ThreadLocal values eligible for garbage collection.
986
+
987
+
Failure to use an asynchronous appender may result in errors like the following when stopping/reloading an application in Tomcat:
988
+
989
+
```
990
+
The web application [webapp] created a ThreadLocal with key of type [java.lang.ThreadLocal.SuppliedThreadLocal]
991
+
(value [java.lang.ThreadLocal$SuppliedThreadLocal@6f75b07c]) and a value of type
0 commit comments