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

package com.a;

import java.util.concurrent.Callable;

/**
 * @author 夜灬瞬
 * @date 2021年12月17日 14:43
 */
public class Test124 implements Callable<Integer> {
    static Integer money = 2000;

    @Override
    public Integer call() throws Exception {
        boolean flag = true;
        while (flag) {
            synchronized (this) {
                if (money > 0) {
                    System.out.println(Thread.currentThread().getName() + "取200元,银行四余额" + (money -= 200));
                } else {
                    flag = false;
                }
            }
        }
        return null;
    }
}

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

相关推荐

自由水:笑死了,敢这么面试不敢让别人说
点赞 评论 收藏
分享
评论
3
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务