当前位置:网站首页>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
边栏推荐
- Anaconda
- Pytorch学习记录(十三):循环神经网络((Recurrent Neural Network)
- Pytoch -- data loading and processing
- Pytorch学习记录(七):处理数据和训练模型的技巧
- Traitement des séquelles du flux de Tensor - exemple simple d'enregistrement de torche. Utils. Données. Dataset. Problème de dimension de l'image lors de la réécriture de l'ensemble de données
- JSP syntax and JSTL tag
- K/3 WISE系统考勤客户端日期只能选到2019年问题
- Denoising paper - [noise2void, cvpr19] noise2void learning denoising from single noise images
- Solution record of slow access speed of SMB service in redhat6
- 线性代数第一章-行列式
猜你喜欢
Pytorch Learning record (XIII): Recurrent Neural Network
Unsupervised denoising - [tmi2022] ISCL: dependent self cooperative learning for unpaired image denoising
Understand the current commonly used encryption technology system (symmetric, asymmetric, information abstract, digital signature, digital certificate, public key system)
PyEMD安装及简单使用
容器
给yarn配置国内镜像加速器
Pytorch學習記錄(十三):循環神經網絡((Recurrent Neural Network)
Pytorch学习记录(五):反向传播+基于梯度的优化器(SGD,Adagrad,RMSporp,Adam)
图像恢复论文简记——Uformer: A General U-Shaped Transformer for Image Restoration
基于thymeleaf实现数据库图片展示到浏览器表格
随机推荐
实操—Nacos安装与配置
无监督去噪——[TMI2022]ISCL: Interdependent Self-Cooperative Learning for Unpaired Image Denoising
创建二叉树
Fundamentals of SQL: first knowledge of database and SQL - installation and basic introduction - Alibaba cloud Tianchi
PyTorch笔记——实现线性回归完整代码&手动或自动计算梯度代码对比
给yarn配置国内镜像加速器
protected( 被 protected 修饰的成员对于本包和其子类可见)
Anaconda installed pyqt5 and pyqt5 tools without designer Exe problem solving
Pytorch learning record (XII): learning rate attenuation + regularization
Linear algebra Chapter 2 - matrices and their operations
Pyemd installation and simple use
图解numpy数组矩阵
Pyqy5 learning (4): qabstractbutton + qradiobutton + qcheckbox
Chapter 4 of line generation - linear correlation of vector systems
Reading of denoising papers - [cvpr2022] blind2blind: self supervised image denoising with visible blind spots
Pyqy5 learning (2): qmainwindow + QWidget + qlabel
Dva中在effects中获取state的值
Filebrowser realizes private network disk
Rsync for file server backup
常用编程记录——parser = argparse.ArgumentParser()