当前位置:网站首页>模仿线程扣除
模仿线程扣除
2022-07-27 16:18:00 【懒起来】
@SpringBootTest
public class DanTest {
@Resource(name = "redisTemplate")
private ValueOperations valueOperations;
private final String key123 = "class#208";
@Test
public void DanTest() {
//设置商品库存
valueOperations.set(key123, 5l);
ExecutorService executorService = Executors.newCachedThreadPool();
//模仿并发操作
for (int i = 0; i < 10; i++) {
Long decrement = valueOperations.decrement(key123, 1);
executorService.execute(() -> {
if (decrement >= 0) {
System.out.println(StrUtil.format("扣除成功,线程{},剩余量{}", Thread.currentThread().getName(), decrement));
} else {
System.out.println(StrUtil.format("扣除失败,线程{},剩余量{}", Thread.currentThread().getName(), decrement));
}
});
}
ThreadUtil.safeSleep(1000 * 10);
}
}边栏推荐
- Class not found: "the com.parkmanagement.dao.daotest test cannot find the test class
- 虚拟偶像的歌声原来是这样生成的!
- 机器学习分类任务效果评估指标大全(包含ROC和AUC)
- 一个案例理解mysql视图
- Canvas draws graphics according to coordinate points
- JPA connection database password field blob
- 面试官:你觉得你最大的缺点是什么?
- 如何实现Word、PDF、TXT文件的全文内容检索?
- Order timeout cancellation and commodity query by category
- 百度地图技术概述,及基本API与WebApi的应用开发
猜你喜欢

Jianmu continuous integration platform v2.5.2 release

"MySQL things" explains the indexing principle in detail

家用静音驱蚊灯芯片-DLTAP703SD-杰力科创

Log4j epic loopholes, big companies like jd.com have been recruited

迷你洗衣机触摸芯片-DLT8MA12TS-杰力科创

Run the uniapp to the mobile phone (real machine debugging)

Log4j 史诗级漏洞,京东这样的大厂都中招了

怎么会不喜欢呢,CI/CD中轻松发送邮件

nacos显示服务注册地址错误

idea 2020.1社区版下载体验
随机推荐
Alibaba architects spent 280 hours sorting out 1015 pages of distributed full stack pamphlets to easily start the distributed system
Uni app for wechat login (to be finished)
Modify placeholder style in input
订单超时取消 及 按类别查询商品
The combination of text and words perfectly explains the implementation process of MySQL logical backup
浅谈JVM(面试常考)
JS tool - Cookie simple encapsulation
2021.7.28 notes
Idea 2020.1 Community Edition download experience
20000 words + 30 pictures | what's the use of chatting about MySQL undo log, redo log and binlog?
Knowledge map pyhanlp realizes named body recognition (with named body recognition code)
Examples of map search
Using Jieba and pyhanlp tools to extract keyword words and sentences
Vue uses keep alive to realize page caching
这样的API网关查询接口优化,我是被迫的
Mode= "widthfix" attribute in image tag
EN 1155 building hardware swing door opener - CE certification
Jianmu continuous integration platform v2.5.2 release
Idea packaging war package and war package location
ridis命令笔记