Skip to the page

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.

The notes

What you must know

  • File descriptors cover files, sockets and pipes. See them with ls -l /proc/<pid>/fd or lsof -p <pid> and count over time.
  • Files.lines, Files.list and Files.walk keep 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

  1. A service fails with Too many open files after four days. What do you do?
  2. Log volume jumped from 2 GB a day to 40 GB an hour. First ten minutes?
  3. Why does a missing stack trace sometimes appear in logs?
  4. Tell me about the hardest Java production issue you debugged.

Practise

Practise with these questions

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview