public ResultBean issue(String originID, final Long userID, final String fromIp) { try { if (!cacheSessionStorage.lock(ISSUING_LOCK + userID)) { return ResultBean.failed(Result.GLOBAL.FAIL.getCode(), "由于当前正在提现申请等原因,提现额度可能发生变化,发标失败,请稍后重试。"); } Subject subjectDraft = subjectDraftDAO.getByOriginID(originID); int limitCategory = subjectDraft.getLimitCategory().intValue(); if (LimitCategory.NET_VALUE.getType() == limitCategory) { return issueNetValue(originID, userID, fromIp); } else if (LimitCategory.CREDIT_LIMIT.getType() == limitCategory) { return issueCredit(originID, userID, fromIp); } else if (LimitCategory.FAST_LIMIT.getType() == limitCategory || LimitCategory.SPECIFIC.getType() == limitCategory || LimitCategory.DISCUSS.getType() == limitCategory || LimitCategory.ESSENCE.getType() == limitCategory || LimitCategory.GONGXIN.getType() == limitCategory) { return issueFastLoan(originID, userID, fromIp); } else if (LimitCategory.ASSETS_LIMIT.getType() == limitCategory) { return issueAssets(originID, userID, fromIp); } else { throw new UserException(BeanCode.GLOBAL.FAIL.getCode(), "发标类型不存在!"); } }catch (Exception e){ throw new UserException(BeanCode.GLOBAL.FAIL.getCode(), e.getMessage()); }finally { cacheSessionStorage.unlock(ISSUING_LOCK + userID); } } 2.除了使用redis锁行,还有利用数据库行锁,如果要锁的表比较大,而且只是记录一个业务操作, 通常使用中间表,表示这个业务状态,加行锁。
利用redis缓存锁记录,数据库锁行
猜你喜欢
转载自496677829.iteye.com/blog/2311486
今日推荐
周排行