有余额2000,两个线程每次取200(Runnable)

package com.a;

/**
 * @author 夜灬瞬
 * @date 2021年12月17日 14:30
 */
public class Test123 implements Runnable {

    Integer money = 2000;

    @Override
    public void run() {
        boolean flag = true;
        while (flag) {
            synchronized (this) {
                if (money > 0) {
                    System.out.println(Thread.currentThread().getName() + "取200元,银行三余额" + (money -= 200));
                } else {
                    flag = false;
                }
            }
        }
    }
}

#学习路径#
全部评论
感谢大佬分享!!!!
点赞 回复 分享
发布于 2022-01-12 20:37

相关推荐

不愿透露姓名的神秘牛友
07-02 18:35
简历上把1个月实习写成了3个月,会进行背调吗?
码农索隆:一个月有一个月的实习经历,三个月有三个月的实习经历
点赞 评论 收藏
分享
06-07 19:59
门头沟学院 C++
补药卡我啊😭:都快15年前的了还在11新特性
你的简历改到第几版了
点赞 评论 收藏
分享
_mos_:我以为手抄报简历就已经很顶了,没想到还有表格简历
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务