当前位置:网站首页>The bottom implementation principle of thread - static agent mode
The bottom implementation principle of thread - static agent mode
2022-04-23 06:01:00 【hanyc..】
Static proxy :
- The names and parameters of real methods and proxy methods are the same , The method body is different ,
- The proxy class and the proxy class establish a relationship by implementing the same interface
- Proxy object (WeddingCompany The object of ) To delegate real objects (You The object of )
Advantages of static agents :
- Proxy objects can do a lot of things that real objects can't
- Real objects focus on doing their own things
package creatthread;
public class StaticProxy {
public static void main(String[] args) {
System.out.println(" Static proxy demo :");
You person = new You();
// Go to WeddingCompany Throw one of the constructors to realize Marry The object of
WeddingCompany wc = new WeddingCompany(person);
wc.happyMarry();
System.out.println();
System.out.println(" The embodiment of static agent in thread :");
// Go to Thread Throw one of the constructors to realize Runnable Object of the interface
Thread thread = new Thread(() -> System.out.println("you get married."));
thread.start();
}
}
// Public interface
interface Marry {
void happyMarry();
}
// Surrogate class
class You implements Marry {
@Override
public void happyMarry() {
System.out.println("you get married.");
}
}
// proxy class
class WeddingCompany implements Marry {
// Real object
private Marry person;
public WeddingCompany(Marry person) {
this.person = person;
}
// Functions that need to be completed by the proxy class itself , Call the method with the object of the proxy class inside the method
@Override
public void happyMarry() {
beforeMarry();
person.happyMarry();
afterMarry();
}
private void beforeMarry() {
System.out.println(" Set up the venue ");
}
private void afterMarry() {
System.out.println(" Remove the venue layout ");
}
}
result :

版权声明
本文为[hanyc..]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230541159319.html
边栏推荐
- Opensips (1) -- detailed process of installing opensips
- LDCT图像重建论文——Eformer: Edge Enhancement based Transformer for Medical Image Denoising
- 在Jupyter notebook中用matplotlib.pyplot出现服务器挂掉、崩溃的问题
- What is the difference between the basic feasible solution and the basic feasible solution in linear programming?
- Protected (members modified by protected are visible to this package and its subclasses)
- Get the value of state in effects in DVA
- 对比学习论文——[MoCo,CVPR2020]Momentum Contrast for Unsupervised Visual Representation Learning
- 事实最终变量与最终变量
- Pytorch Learning record (XIII): Recurrent Neural Network
- Viewer: introduce MySQL date function
猜你喜欢
随机推荐
Pyqy5 learning (4): qabstractbutton + qradiobutton + qcheckbox
PyTorch笔记——实现线性回归完整代码&手动或自动计算梯度代码对比
ValueError: loaded state dict contains a parameter group that doesn‘t match the size of optimizer‘s
Remedy after postfix becomes a spam transit station
解决报错:ImportError: IProgress not found. Please update jupyter and ipywidgets
自動控制(韓敏版)
JSP syntax and JSTL tag
SQL注入
Pytorch学习记录(九):Pytorch中卷积神经网络
常用编程记录——parser = argparse.ArgumentParser()
异常的处理:抓抛模型
umi官网yarn create @umijs/umi-app 报错:文件名、目录名或卷标语法不正确
Font shape `OMX/cmex/m/n‘ in size <10.53937> not available (Font) size <10.95> substituted.
深度学习基础——简单了解meta learning(来自李宏毅课程笔记)
基于thymeleaf实现数据库图片展示到浏览器表格
Create binary tree
去噪论文阅读——[CVPR2022]Blind2Unblind: Self-Supervised Image Denoising with Visible Blind Spots
Pytorch学习记录(四):参数初始化
编写一个自己的 RedisTemplate
Linear algebra Chapter 2 - matrices and their operations




![去噪论文阅读——[RIDNet, ICCV19]Real Image Denoising with Feature Attention](/img/4e/1a51636853d11544e6f5c37a588730.png)



