当前位置:网站首页>多线程打印ABC(继承+进阶)
多线程打印ABC(继承+进阶)
2022-08-03 05:41:00 【是小鱼儿哈】
基础

进阶

public class Demo {
private static Object locker1 = new Object();
private static Object locker2 = new Object();
private static Object locker3 = new Object();
public static void main(String[] args) throws InterruptedException {
Thread t1 = new Thread(() -> {
try {
for (int i = 0; i < 10; i++) {
synchronized (locker1) {
locker1.wait();
}
System.out.print("A");
synchronized (locker2) {
locker2.notify();
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
});
Thread t2 = new Thread(() -> {
try {
for (int i = 0; i < 10; i++) {
synchronized (locker2) {
locker2.wait();
}
System.out.print("B");
synchronized (locker3) {
locker3.notify();
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
});
Thread t3 = new Thread(() -> {
try {
for (int i = 0; i < 10; i++) {
synchronized (locker3) {
locker3.wait();
}
System.out.println("C");
synchronized (locker1) {
locker1.notify();
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
});
t1.start();
t2.start();
t3.start();
Thread.sleep(1000);
// 从线程 t1 启动
synchronized (locker1) {
locker1.notify();
}
}
}边栏推荐
- html+css+php+mysql实现注册+登录+修改密码(附完整代码)
- 关于任命韩文弢博士代理NOI科学委员会主席的公告
- Charles capture shows
solution - Redis-记一次docker下使用redis
- Scala 高阶(七):集合内容汇总(上篇)
- 解决plt.imshow()不显示图片cv2.imshw()不显示图片
- Basic syntax of MySQL DDL and DML and DQL
- UniApp scroll-view 事件不生效(@scroll、@scrolltolower、@scrolltoupper ...)
- SQLServer2019安装(Windows)
- CCF NOI 2022笔试题库
猜你喜欢

Nacos单机模式的安装与启动

sql优化常用的几种方法

el-table获取读取数据表中某一行的数据属性

MySQL之DQL——查询语言

Content type ‘applicationx-www-form-urlencoded;charset=UTF-8‘ not supported“【已解决】

CISP-PTE真题演示

postman配置中文

信息学奥赛一本通T1446:素数方阵

Example of embedding code for continuous features

El - table column filter functions, control columns show and hide (effect and easy to implement full marks)
随机推荐
Mysql去除重复数据
MySQL日期和时间戳的转换
Charles capture shows
solution Embedding two implementations of the torch code
零代码工具拖拽流程图
CISP-PTE Zhenti Demonstration
Flink对比Spark
Nacos与Eureka的区别
Chrome插件开发入门
el-table实现列筛选功能,控制列的显示和隐藏(实现简单,效果满分)
单节点部署 gpmall 商城系统(一)
Docker-compose安装mysql
Autowired注解与Resource注解的区别
Detailed explanation of AutoInt network and pytorch reproduction
MySql之json_extract函数处理json字段
连续型特征做embedding代码示例
2021年PHP-Laravel面试题问卷题 答案记录
SQLSERVER将子查询数据合并拼接成一个字段
Getting started with el-tabs (tab bar)
cookie和session区别