当前位置:网站首页>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
边栏推荐
- Pyqy5 learning (III): qlineedit + qtextedit
- 去噪论文阅读——[RIDNet, ICCV19]Real Image Denoising with Feature Attention
- 自動控制(韓敏版)
- 开发环境 EAS登录 license 许可修改
- Pytorch learning record (XI): data enhancement, torchvision Explanation of various functions of transforms
- Protected (members modified by protected are visible to this package and its subclasses)
- 基于thymeleaf实现数据库图片展示到浏览器表格
- PyQy5学习(二):QMainWindow+QWidget+QLabel
- Anaconda installed pyqt5 and pyqt5 tools without designer Exe problem solving
- Pytorch introduction notes - use a simple example to observe the output size of each layer of forward propagation
猜你喜欢
Solve the error: importerror: iprogress not found Please update jupyter and ipywidgets
Multithreading and high concurrency (3) -- synchronized principle
JVM family (4) -- memory overflow (OOM)
线性代数第二章-矩阵及其运算
去噪论文阅读——[RIDNet, ICCV19]Real Image Denoising with Feature Attention
Pyemd installation and simple use
In depth understanding of the relationship between dncblevel and noise denoising in the paper
Pytorch学习记录(十):数据预处理+Batch Normalization批处理(BN)
Denoising paper - [noise2void, cvpr19] noise2void learning denoising from single noise images
The user name and password of users in the domain accessing the samba server outside the domain are wrong
随机推荐
开发环境 EAS登录 license 许可修改
In depth understanding of the relationship between dncblevel and noise denoising in the paper
图像恢复论文——[RED-Net, NIPS16]Image Restoration Using Very Deep Convolutional Encoder-Decoder Networks wi
线性代数第二章-矩阵及其运算
创建企业邮箱账户命令
Reading of denoising paper - [ridnet, iccv19] real image denoising with feature attention
filebrowser实现私有网盘
Pytorch notes - get familiar with the network construction method by building RESNET (complete code)
In depth source code analysis servlet first program
Create binary tree
Anaconda安装PyQt5 和 pyqt5-tools后没有出现designer.exe的问题解决
解决报错:ImportError: IProgress not found. Please update jupyter and ipywidgets
Remedy after postfix becomes a spam transit station
Filebrowser realizes private network disk
interviewter:介绍一下MySQL日期函数
Latex快速入门
创建二叉树
给yarn配置国内镜像加速器
PyEMD安装及简单使用
Pytorch learning record (XII): learning rate attenuation + regularization