简体   繁体   中英

Is there a disadvantage if I produce an OutputStream in configuration in a spring-boot application and keep it till the application instance runs?

I wrote a method which creates a private key file and saves it on the disk. I have a spring-boot application which I will configure to produce this private key file and keep it as OutputStream in the application and use it when required. Are there any disadvantages or issues with this approach?

Most modern operation systems limits how many open files could an application have. If you keep a file open when it is not neccesary, you will have one more open file, one less free slots available for you. For some applications, the default 1024 slot is too much, but for some other applications, it's very few.

Anyway, from operation perspective this is a bad pattern. Open the file when you need, close it when you finished with it. Write a helper method to make serialization and storing in file easier.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM