Timeout exception of HttpURLConnection

HttpURLConnection is based on the HTTP protocol, and its bottom layer is implemented through socket communication. If the timeout is not set, in the case of abnormal network, the program may freeze and not continue to execute. It may be disconnected after 3 minutes and an exception will be thrown.
This will affect the normal operation of the system.
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(3000); 
connection.setReadTimeout(1000); 
After setting, an exception can be returned quickly, so that the system can quickly handle the abnormal situation.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326884226&siteId=291194637