Why Your Java App Freezes: Uncovering the Log4j Lock Bug and How to Fix It
An intermittent slowdown in a Java SaaS app, even during low traffic, was traced to a Log4j locking bug that blocked hundreds of threads; capturing a thread dump, analyzing it with fastthread.io, and upgrading to Log4j2 resolved the issue.
We observed a SaaS application that intermittently slowed down, even during low traffic, and restarting only temporarily resolved the issue.
The slowdown was investigated by capturing a thread dump with jstack when the application was sluggish.
Obtaining a thread dump at the moment of failure is crucial!
The dump was uploaded to the online analysis tool fastthread.io , which immediately generated a report.
The report identified that thread http-nio-8080-exec-121 was blocking more than 100 other threads. The dependency graph shows these threads waiting for a lock held by that thread.
Inspecting the stack trace of the blocked thread reveals it has acquired the lock on org.apache.log4j.Logger and is performing other operations.
Other threads, such as http-nio-8080-exec-56, are in BLOCKED state waiting for the same org.apache.log4j.Logger lock.
Because the lock is never released, any thread that tries to log becomes blocked, causing the entire application to stall.
Troubleshooting
We searched for “org.apache.log4j.Logger blocked thread” and found a known Log4j bug (Bug 57714, reported in 2015). The bug causes any thread that attempts to log to block, effectively freezing the application.
Conclusion
Log4j has not been maintained since August 2015. If your application still uses Log4j, upgrade to Log4j 2, which is a completely rewritten framework with many performance improvements. Migrating resolves the blocking issue and prevents similar slowdowns.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Backend Technology
Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
