package xyz.coolblog.ti;
/**
* @Auther: miv
* @Date: 2019-09-08 16:34
* @Web: www.xiejx.cn
* @Email: 787824374@qq.com
* @Description:
*/
public class Test {
volatile int i = 1;
public static void main(String[] args) throws Exception {
Test obj = new Test();
Runnable runnable = new Runnable() {
@Override
public void run() {
while (obj.i <= 100) {
// 上锁当前对象
synchronized (this) {
三个线程交替打印1-100
最新推荐文章于 2024-04-23 09:20:36 发布