twitter/util — pull request #18 by jvirtanen (2012-03-05 12:01:51+00:00)
Title: util-logging: Make Level objects thread-safe

The `Level` constructor mutates two unsynchronized maps within the `Logger` singleton. This coupled with the lazy construction of `Level` objects leads to trouble (for example, deadlocks) in multithreaded applications:

- Thread 1 accesses `Level.OFF` for the first time, triggering the constructor
- Thread 2 accesses concurrently `Level.FATAL` for the first time, also triggering the constructor
- Both threads attempt to mutate `Logger`'s unsynchronized maps concurrently

Fix the problem by constructing the `Level` objects non-lazily when the `Level` singleton is accessed for the first time.