package com.itheima.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/*****
 * @Author: http://www.itheima.com
 * @Description: com.itheima.controller.LockController
 ****/
@RestController
public class LockController {

    /***
     * 分布式锁测试
     * @return
     */
    @GetMapping(value = "/lock")
    public String lock(){
        //获取锁
        System.out.println("进"+Thread.currentThread().getId());
        //如果key在redis缓存，则表示商品信息在Redis中进行操作
//        boolean bo =distributedLocker.lock("ITHEIMA", 10L, TimeUnit.MINUTES,10L);
//        if(bo){
            System.out.println("拿到！"+Thread.currentThread().getId());
            String a = "";
            for (int i = 0; i <1000000000 ; i++) {
                a+=i+",";
            }
            System.out.println("出："+Thread.currentThread().getId());
   
        //释放锁
//            distributedLocker.unlock("ITHEIMA");
//        }

        return "OK";
    }
}
