Synchronization Mode

同步模型 是一种最基本的传统计算模型.
基本特征就是,主线程必须要停下来,等待外部调用返回,然后才能继续执行主线程的代码.

alt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
public class Main {

private static String externalService() throws InterruptedException {
Thread.sleep(5000);
return "Rugal";
}

public static void main(String[] args) throws InterruptedException {
System.out.println("Do other work");
String value = externalService();
System.out.println(value);
System.out.println("Do other work");
}
}

显然 同步模型 有很大的资源浪费的问题,因为主线程在这一期间只能等待,卡在调用点上无法动弹.


Synchronization Mode
https://rug.al/2021/2021-12-31-synchronization-mode/
Author
Rugal Bernstein
Posted on
December 31, 2021
Licensed under