Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harmful Usage of FileInputStream/FileOutputStream #5920

Open
bogdanspbm opened this issue May 9, 2024 · 0 comments
Open

Harmful Usage of FileInputStream/FileOutputStream #5920

bogdanspbm opened this issue May 9, 2024 · 0 comments

Comments

@bogdanspbm
Copy link

Describe the issue
There appears to be an issue where using FileInputStream and FileOutputStream objects can cause significant memory management overhead due to their finalization process. Even when these objects are closed diligently, they remain in the JVM's finalizer queue until a full garbage collection cycle is performed. This behavior, intended for backward compatibility, leads to increased garbage collection times and can severely impact the performance of applications with high file I/O operations.

Additional context
The issue has been observed in the following methods within our system:

  • NarrativeTemplateManifest.loadResource
  • TlsAuthenticationSvc.createKeyStore
  • VelocityHelper.configureVelocityEngine

A recommended workaround for this issue, especially for Java versions 7 and above, is to use Files.newInputStream(...) and Files.newOutputStream(...) instead of the traditional file stream classes. This change helps mitigate the described problem by avoiding reliance on the finalization process for resource management.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant