1

I'm using HttpURLConnection for connecting to another service. After setting up the connection, I have the logic for reading input stream by calling the method getInputStream().

What can be possible issues in the case if I will not close this input stream in my project? It will be useful for me to get the info about possible issues with not closing output streams which are used for http connections.

TestName
  • 378
  • 2
  • 13
  • you should call close() or disconnect() in your finally block, see here for more info about pooling URLConnections that may be useful to you: https://stackoverflow.com/questions/35208950/java-httpurlconnection-and-pooling – ItFreak Aug 01 '19 at 07:10

1 Answers1

0

Operating systems and servers usually have limits to the amount of resources which can be opened at any given time. Failing to close resources could eventually lead to resource exhaustion, leading to a number of errors which could occur. Whether it's streams, result sets, files, ... always close your resources either in a finally block or with the try-with-resources construct, there is no excuse not to do it.

TheWhiteRabbit
  • 1,253
  • 1
  • 5
  • 18