In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "how to use netty channelPool connection pool". In the operation of practical cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Scenario: when we initiate a connection to the server as a client, use channel [multiple different business data] if the target server has only one request or may have multiple requests at the same time. Then we can pool the channel connect on the server. It is convenient to improve the utilization of channel.
If streaming data push [continuous data push to the server, it is not necessary to use channelPool. There is no need to release channel]
Core interface: ChannelPool
Public ChannelPool newPool (Bootstrap bootstrap) {return new FixedChannelPool (bootstrap, iridiumClientChannelHandler, protocolOptions.getMaxConnections ());}}
Core implementation class:
Public class FixedChannelPool extends SimpleChannelPool
An abstract class
Public abstract class AbstractChannelPoolHandler implements ChannelPoolHandler {@ Override public void channelAcquired (@ SuppressWarnings ("unused") Channel ch) throws Exception {/ / NOOP} @ Override public void channelReleased (@ SuppressWarnings ("unused") Channel ch) throws Exception {/ / NOOP}}
Channel.close () does not disconnect but removes logout from eventLoop
About channelPool health check: just before getting the connection
The class ChannelHealthChecker can determine whether the chanel in the connection pool is valid.
Public interface ChannelPoolHandler {
/ * *
* Called once a {@ link Channel} was released by calling {@ link ChannelPool#release (Channel)} or
* {@ link ChannelPool#release (Channel, Promise)}.
*
* This method will be called by the {@ link EventLoop} of the {@ link Channel}.
, /
Void channelReleased (Channel ch) throws Exception
/ * *
* Called once a {@ link Channel} was acquired by calling {@ link ChannelPool#acquire ()} or
* {@ link ChannelPool#acquire (Promise)}.
*
* This method will be called by the {@ link EventLoop} of the {@ link Channel}.
, /
Void channelAcquired (Channel ch) throws Exception
/ * *
* Called once a new {@ link Channel} is created in the {@ link ChannelPool}.
*
* This method will be called by the {@ link EventLoop} of the {@ link Channel}.
, /
Void channelCreated (Channel ch) throws Exception
}
/ * add channelhandler when the link is created. It will be created only if the channel is insufficient, but the maximum number of channel will not exceed the limit * /
@ Override
Protected void initChannel (Channel ch) throws Exception {
ChannelPoolHandler.channelCreated (ch)
}
} this is the end of "how to use netty channelPool connection Pool". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.