zoukankan      html  css  js  c++  java
  • 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;
        }
    }
  • 相关阅读:
    Go 指针
    Go 字符串
    Go Maps
    Go 可变参数函数
    Go 数组和切片
    pyqt5实现窗口跳转并关闭上一个窗口
    spy++查找窗口句柄
    Python中Tk模块简单窗口设计
    pyqt5无边框拖动
    pyqt5 GUI教程
  • 原文地址:https://www.cnblogs.com/felixzh/p/12753103.html
Copyright © 2011-2022 走看看