In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to achieve the static proxy mode in multithreading in Java. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
Preface
Proxy pattern is a kind of design pattern, which provides additional access to the target object, that is, to access the target object through the proxy object, so that it can provide additional functional operations without modifying the original target object. extend the functionality of the target object.
In short, the proxy mode is to set up an intermediate agent to control access to the original target object, so as to enhance the function of the original object and simplify the way of access.
Static agents belong to the agent pattern in the design pattern. On the contrary, there are dynamic agents, which will not be discussed in this article, and those who are interested can do their own Google research.
In fact, inheriting Thread is also a kind of static agent, so learning static proxy here can help us learn multithreading.
Static agent
Advantage: the function of the target object can be extended without modifying the target object.
Disadvantages:
redundancy. Because the proxy object wants to implement an interface consistent with the target object, there will be too many proxy classes.
It's not easy to maintain. Once methods are added to the interface, both the target object and the proxy object are modified.
I. static agent
Actual case: buying a house
The buyer of the house
Buying a house as an agent
Common behavior to buy a house
Code implementation case:
Class MyI implements BuyHouse {/ / for me, I just need to take the money and sign @ Override public void Buy () {System.out.println ("1 million, sign the contract, the house is mine!") ;}} class Agent implements BuyHouse {private BuyHouse buyHouse; public Agent (BuyHouse buyHouse) {this.buyHouse = buyHouse;} / / help me prepare the contract and other materials public void work1 () {System.out.println ("prepare the contract and other materials ~");} / / take me to the Housing Administration to go through the formalities public void work2 () {System.out.println ("take the customer to the formalities ~") } / / the agent charged me money, he had to help me prepare the purchase materials, take me to the purchase process and so on @ Override public void Buy () {work1 (); work2 (); / / customer purchase buyHouse.Buy () }} this is the end of the article on "how to implement the static proxy mode in multithreading in Java". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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.