Get into the habit of closing all InputStreams and OutputStreams that are no longer in use, regardless of whether the implementation behind the API automatically closes them for you. If written in Java 1.7+, it is very simple to use try-with-resource:
JDBC’s PreparedStatement, ResultSet, etc. all implement the AutoCloseable interface. In theory, as long as the Connection is closed, the PreparedStatement, ResultSet, etc. generated by it will also be automatically closed. However, it is strongly recommended that you use try-with when generating these resources. -resource to manage.
The same goes for resources such as getInputStream/getOutputStream in ServletRequest/ServletResponse.
Get into the habit of closing all InputStreams and OutputStreams that are no longer in use, regardless of whether the implementation behind the API automatically closes them for you.
If written in Java 1.7+, it is very simple to use try-with-resource:
Similar scenes include:
JDBC’s PreparedStatement, ResultSet, etc. all implement the AutoCloseable interface. In theory, as long as the Connection is closed, the PreparedStatement, ResultSet, etc. generated by it will also be automatically closed. However, it is strongly recommended that you use try-with when generating these resources. -resource to manage.
The same goes for resources such as getInputStream/getOutputStream in ServletRequest/ServletResponse.
Need
In the case of very high concurrent operations, if you do not close it, the overhead on system resources will be relatively large.