当前位置:网站首页>模仿线程扣除
模仿线程扣除
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);
}
}边栏推荐
- Nacos display service registration address error
- Wechat applet obtains openid, sessionkey, unionid
- Modify placeholder style in input
- What does the number of network request interface layers (2/3 layers) mean
- Visual studio code installation tutorial (super detailed)
- pygame飞机大战游戏背景实现
- 2021.8.9 note request
- 「MySQL那些事」一文详解索引原理
- EN 1155 building hardware swing door opener - CE certification
- 瑞吉外卖sql表
猜你喜欢

智能失眠治疗仪产品-DLT8P68SA-杰力科创

MySQL learning Day1 DDL, DML, DQL basic query

Must the MySQL query column be consistent with the group by field?

mysql基础语句

2021.7.30 note index

Wechat applet obtains openid, sessionkey, unionid

Uni app label jump

Canvas draws graphics according to coordinate points

知识图谱 — pyhanlp实现命名体识别(附命名体识别代码)

Commodity comment information and comment information classification
随机推荐
Basic operations of MySQL view
音乐律动七彩渐变灯芯片--DLT8S04A-杰力科创
ERROR 1366 (HY000): Incorrect string value: ‘\xE8\xB5\xB5\xE9\x9B\xB7‘ for column ‘s_ name‘ at row 1
2021.8.1 notes DBA
C basic concepts list description suggestions collection
The hero of the aircraft war comes out with bullets
2 万字 + 30 张图 | 细聊 MySQL undo log、redo log、binlog 有什么用?
内网的公司邮箱服务器怎么发外部邮件
I was forced to optimize the API gateway query interface
mysql基础语句
JPA connection database password field blob
Uni app for wechat login (to be finished)
Was not registered for synchronization because synchronization is not active[resolved]
Quick access to website media resources
机器学习——SVM训练集只有一类标签数据而引发的错误
Class not found: "the com.parkmanagement.dao.daotest test cannot find the test class
搭建一个简单的知识问答系统
2021.7.17 notes MySQL other commands
How to realize the full-text content retrieval of word, PDF and txt files?
浴室带除雾化妆镜触摸芯片-DLT8T10S