• springboot处理并发接口,简单实用


    public int updateTsakSuatusByTaskIdAuthorId(Integer authorId, Integer taskCode, Integer status) {
        TaskInfoDetailVo taskDetail = null;
        TaskAuthorVo taskAuthor = null;
        //处理并发事件 定义资源的总数量
        Semaphore semaphore = new Semaphore(1);
        //获取可用资源数
        int availablePermits = semaphore.availablePermits();
        if (availablePermits > 0) {
            try {
                //请求占用一个资源
                semaphore.acquire(1);
                taskDetail = taskSR.getTaskDetail(taskCode);
                taskAuthor = taskSR.getCount(authorId, taskCode);
            } catch (Exception e) {
                log.error("修改抢单状态之前查询状态判断异常", e.getMessage());
            } finally {
                //释放一个资源
                semaphore.release(1);
            }
    
            if (taskDetail == null) {
                return -1;
            }
            if (null == taskAuthor) {
                return -2;
            }
            if (taskDetail.getStatus() != (int) EnumTaskStatus.DCP.getKey() && taskAuthor.status != (int) EnumTaskAuthorStauts.TASK0.getKey()) {
                return -3;
            }
            //0作者待接受,1作者待审核,2作者已拒绝,3已选中,4被拒绝,
            int updateStatus = updateTaskSR.updateTsakSuatusByTaskIdAuthorId(authorId, taskCode, status, String.valueOf(new Date()));
            return updateStatus;
        } else {
    
            System.out.println("*********资源已被占用,稍后再试***********");
            return 0;
        }
    }
  • 相关阅读:
    滴滴日送400万红包,仅仅为人群不冷漠?
    C++提供的四种新式转换--const_cast dynamic_cast reinterpret_cast static_cast
    GreenDao开源ORM框架浅析
    Python 计数器
    Linux虚拟内存的添加
    Linux iptables
    Python set
    Python dict get items pop update
    Python contains
    Python reverse
  • 原文地址:https://www.cnblogs.com/felixzh/p/12753103.html
Copyright © 2020-2023  润新知