当前位置:网站首页>多线程——静态代理模式
多线程——静态代理模式
2022-07-25 09:27:00 【看小虫子】
静态代理模式的总结
真实对象和代理对象都要实现同一接口
代理对象要代理真实角色
好处:1,代理对象可以左很多真实对象做不了的事情
2,真实对象专注做自己的事情
通过runnable接口启动线程是用了静态代理的方法
package StaticProxy;
public class Demo01 {
public static void main(String[] args) {
You you=new You();
you.HappyMarry();
WeddingCompany we=new WeddingCompany(you);
we.HappyMarry();
}
}
interface Marry{
void HappyMarry();
}
//真实角色
class You implements Marry{
@Override
public void HappyMarry() {
System.out.println("开心的,超开心");
}
}
//代理角色
class WeddingCompany implements Marry{
//代理谁--》真实目标角色
private Marry target;
public WeddingCompany(Marry target) {
this.target = target;
}
@Override
public void HappyMarry() {
before();
this.target.HappyMarry();//这是真实对象
after();
}
private void after() {
System.out.println("结婚之后,收尾款");
}
private void before() {
System.out.println("结婚前布置现场");
}
}
在这里,婚庆公司相当于(Thread)
you相当于要调用线程的对象
调用的方法以及run()就是最后实现的方法
边栏推荐
- 小程序企业发放红包功能
- Debug篇快捷键入门
- 鼠标监听,画笔
- CCF 201512-4 delivery
- 动态规划,购物单问题
- 常用类的小知识
- TensorFlow raw_ RNN - implement the seq2seq mode to take the output of the previous time as the input of the next time
- Yarn quick reference manual
- Probability theory and mathematical statistics 3 discrete random variables and probability distributions (Part 2)
- Filter过滤器详解(监听器以及它们的应用)
猜你喜欢

See how a junior student of double non-2 (0 Internship) can get an offer from Alibaba and Tencent

力扣刷题组合问题总结(回溯)

小程序H5获取手机号方案

Probabilistic robot learning notes Chapter 2

Redux使用和剖析

数论--负进制转换

Configuring ROS development environment with vscode: Causes and solutions to the problem of ineffective code modification
![[necessary for growth] Why do I recommend you to write a blog? May you be what you want to be in years to come.](/img/f5/e6739083f0dce8da1d09d078321633.png)
[necessary for growth] Why do I recommend you to write a blog? May you be what you want to be in years to come.

CentOs安装redis

Subtotal of rospy odometry sinkhole
随机推荐
CCF 201509-4 Expressway
C3D模型pytorch源码逐句详析(三)
[necessary for growth] Why do I recommend you to write a blog? May you be what you want to be in years to come.
Is binary cross entropy really suitable for multi label classification?
基础背包问题
数论---最大公约数最小公倍数
概率论与数理统计 4 Continuous Random Variables and Probability Distributions(连续随机变量与概率分布)(上篇)
The first week of the fifth stage
Pow(x,n)
Summary of most consistency problems
常用类的小知识
MVC three-tier architecture understanding
Common methods of nodejs version upgrade or switching
一.初始MySQL,MySQL安装、配置环境、初始化
多线程——Callable接口,lambda
[recommended collection] with these learning methods, I joined the world's top 500 - the "fantastic skills and extravagance" in the Internet age
ES6 detailed explanation
VLAN的配置及其应用(以华为eNSP为例)
Pnpm Brief
JDBC总结