使用synchronized解决Controller层两个需要互斥访问的方法

Controller层的两个方法不可以同时执行

public WelfareScope createGhWelfareScope(WelfareScopeInput scopeInput,Boolean needDeptBranch) {
        synchronized (WelfareConstants.FETCH_LOCK) {
            return welfareScopeService.createGhWelfareScope(scopeInput, true,needDeptBranch);
        }
    }

public List createGhWelfareScopes(List scopeInputs,Boolean needDeptBranch) {
        synchronized (WelfareConstants.FETCH_LOCK) {
            return welfareScopeService.createGhWelfareScopes(scopeInputs,needDeptBranch);
        }
    }

使用synchronized实现

public class WelfareConstants {
    public static final byte[] FETCH_LOCK = new byte[0];
}

你可能感兴趣的:(源码,锁,java,spring,boot)