Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the two key parameters in the Java connection pool

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article focuses on "what are the two key parameters in the Java connection pool". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what are the two key parameters in the Java connection pool.

Analysis process

MaxTotalConnections, it's easy to understand. Since it is a connection pool, what is the maximum capacity of a pool? This parameter defaults to 20. Of course, this parameter may be different in different connection pooling implementations, which is not my focus.

MaxConnectionsPerHost, which represents the maximum number of pooled connections per route in a connection pool. This value, the default is 2, I have seen many failures caused by not setting this value. This is not the focus of my attention, my question is, what is routing? What is a connection? What is the relationship between routing and connectivity?

What is the connection first? The concept is clear: the connection is the logical concept formed by the source ip: the source port plus the destination ip: the destination port, and the related information.

So what is routing? My head, it's a mess. There are no good articles on the Internet that can answer my questions. My guess is that the destination host+port port is the route. For example, you need to visit Baidu in your project. Then baidu.com+80 is a route. You also need to access csdn, so csdn.net+80 is also a route. But it's just my guess.

Then look at the source code. Different versions of http client are implemented in different ways. The projects I have on hand are 3.x and 4.x. I took a brief look at it, but the problem with the source code is that there are both host and localAddress in the implementation class of route.

In order to continue to answer my questions, let's just debug. Simply write a unit test, something like this.

Then I saw this message, taking the 3.x source code as an example, the 4.x principle is consistent.

The process of getting a connection in which the HostConfiguration has local address information, but the value is empty. So it's host that really works for route.

After obtaining the connection, check whether the connection is open. If not, execute the open method, and localAddress will be set. That is, a real connection is created.

Next, let's take a look at the connection pool of Http to see what it looks like when we have data.

At this point, it is clear that connection pooling is based on host (remote services such as baidu.com) as a group to establish connection pooling. MaxConnectionsPerHost is used to control the number of connection pools in a group, that is, as mentioned by some students, to control the number of concurrent access to a service.

At this point, I believe you have a deeper understanding of "what are the two key parameters in the Java connection pool?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report