java 函数独占锁

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

@RestController
@RequiredArgsConstructor
@RequestMapping("/smartpark" )
@Tag(description  = "开放接口", name =  "开放接口")
//@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)

public class SmartParkController {

    @Autowired
    private CustomSqlService customSqlService;

    private Lock accountLock = new ReentrantLock();

    @Operation(summary = "数字接口", description = "数字接口")
    @GetMapping("/synchrodataByGarden1/{id}")
    @Inner(false)
    public Map<String,Object> synchrodataByGarden1(@PathVariable("id") String strYear){
        accountLock.lock();
        Map<String, Object> mResult = new HashMap<>();
        try {
            //过程

        }catch (Exception ex){
            mResult.put("接口异常",ex.toString());

        }finally {
            accountLock.unlock();
            return mResult;
        }
    }
}
posted @ 2023-07-27 13:40  寒冷的雨呢  阅读(28)  评论(0编辑  收藏  举报