proomt

Search

Search posts, papers, and topics

All posts

CodeshipStephen Connolly2 min readintermediate

FileInputStream / FileOutputStream Considered Harmful

Summary

FileInputStream and FileOutputStream implement finalize, which forces objects onto the finalizer queue and can cause long GC pauses in programs that open many files. Switching to Files.newInputStream and Files.newOutputStream (Java 7+) eliminates the finalizer overhead and improves I/O‑heavy workloads.

  • FileInputStream/FileOutputStream override finalize, so even after close they remain finalizable objects.
  • Heavy file‑creation workloads (e.g., Hadoop) suffer noticeable GC pauses due to these finalizable streams.
  • Java 7+ provides Files.newInputStream / Files.newOutputStream which return streams without a finalize method.
  • Replacing the old constructors with the Files APIs is a one‑line change that reduces GC pressure.

Java developers who perform high‑volume file I/O should care because finalizer‑induced GC pauses can degrade performance.

6/10

Related reading

  1. What Go Taught Us About Java Garbage Collection

    ParparVM’s GC was tuned by lowering the allocation‑trigger floor, adding configurable thresholds, parallel marking, mutator assistance, and proper weak/soft reference handling. These changes cut RSS from 98 MB to 38 MB, reduced worst‑case GC pauses from seconds to sub‑second, and improved cache hit rates with a recency‑based eviction policy.

    CodeName Onecodenameone.com7 min
  2. App Hardening: One Obfuscation Pipeline Across Every Port

    Codename One adds a cloud‑side hardening step that runs on the merged JAR before it is split into Android, iOS, JavaScript, and desktop binaries. It can rename symbols, encrypt string literals, and insert opaque‑predicate control‑flow guards at configurable levels (off → standard → aggressive → paranoid). The transforms are selective per platform to avoid breaking optimizers, and a mapping is kep…

    CodeName Onecodenameone.com6 min