[Java] httpclient has an odd stalecheck Option

Source: Internet
Author: User

Enabling stale check will consume an additional 15 milliseconds for each HTTP request. The stalecheck option is enabled by default.

Is this necessary ????

When a web API service is called in the LAN, it will become dead.

Http://stackoverflow.com/questions/11219325/why-does-defaulthttpclient-send-data-over-a-half-closed-socket
Http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html
Http://www.mail-archive.com/httpclient-users@hc.apache.org/msg02710.html

I checked some information and found that stalecheck should be disabled for performance.

Someone suggested that the Java httpclient should add an idle Monitor thread in the connection pool to remove the Broken connection. Otherwise, the stale connection of re-use may be disconnected by the server, which may cause an exception.

However, because Java's traditional communication method is blocking, The Global idle Monitor thread cannot be universal. To support a large number of connections, configuring a Monitor thread for each connection is not feasible.

Therefore, the official Apache httpclient documentation is recommended as follows:

Clientconnectionmanager # closeexpiredconnections ()
Clientconnectionmanager # closeidleconnections ()
The caller needs to call one of the above two methods on a regular basis to reduce broken stale connections

At the same time, the caller needs to decide whether to retry the IO exception.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.