Java in production · senior
Leaked files, noisy logs and telling the story
Unclosed files and streams, runaway logs and slow jobs have simple causes. A good incident answer has impact, evidence, a mitigation, a root cause and prevention.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- File descriptors cover files, sockets and pipes. See them with
ls -l /proc/<pid>/fdorlsof -p <pid>and count over time. Files.lines,Files.listandFiles.walkkeep the resource open until the stream is closed. A terminal operation such as count() does not close it. Use try-with-resources.- The GC is not a resource manager: cleanup tied to garbage collection happens late or never. Also check JDBC statements, result sets and HTTP responses.
- Monitor open versus maximum file descriptors with Micrometer and alert at a share of the limit. Add a test that runs the import many times and checks the count stays flat.
- Log flood: first free space and lower the noisy logger's level at runtime. HotSpot's OmitStackTraceInFastThrow can remove stack traces for exceptions thrown very often.
- A synchronous file appender makes request threads wait. Use an async appender with a bounded queue. Use parameterised logging so a debug line does not build a big string before the level check.
- One log line per final failure with context (order id, attempts), not a stack trace per retry. Use size- and time-based rolling with a total cap, a separate log volume and alerts on log volume.
- For "hardest production issue": a concrete story with numbers, the right tool for the symptom (thread dumps for hangs, heap dumps and GC logs for memory, JFR for CPU), a root cause in Java terms, mitigation then fix then prevention, and an honest account of your part.
The red pen
Common traps: mistake → fix
Mistake: Files close when the GC runs
Fix: not reliably; close them yourself.
Mistake: Debug logging is free when disabled
Fix: building the message still costs unless you use parameters.
Mistake: Restart fixes the incident
Fix: it hides the cause; capture evidence first.
Easy to hard
Questions interviewers ask, easy to hard
- A service fails with Too many open files after four days. What do you do?
- Log volume jumped from 2 GB a day to 40 GB an hour. First ten minutes?
- Why does a missing stack trace sometimes appear in logs?
- Tell me about the hardest Java production issue you debugged.
Practise
Practise with these questions
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.