Is SLF4J thread-safe?

后端 未结 1 1393
野趣味
野趣味 2021-01-07 17:58

I might have a Dog class that has a single instance shared across multiple threads. I plan on using SLF4J for all logging:

public class Dog {
           


        
相关标签:
1条回答
  • 2021-01-07 18:07

    Certainly, everyone assumes that a Logger is going to be thread-safe. But you would need to look at the code / javadocs of the implementation classes behind the facade to be absolutely sure.

    For specific implementations:

    • Log4j 1.2 is thread-safe
    • java.util.logging.Logger is thread-safe (search for "multi-thread safe")
    • Logback is thread-safe

    (Obviously, these are statements that the respective code is designed to thread-safe. There can always be bugs. For example, were at the time of writing a couple of open thread-safety bugs in the Log4j 2 tracker, though it doesn't seem like those bugs would directly affect your example code.)

    0 讨论(0)
提交回复
热议问题