(6) Actual combat of inventory oversold cases – using mysql distributed locks to solve the “oversold” problem

Foreword This section is the final article on using distributed locks to solve the “oversold” problem of concurrent access. In the previous chapters, we introduced the use of mysql’s row locks, optimistic locks, and pessimistic locks to solve the oversold problem caused by concurrent access. There are The problem is that row locks, optimistic locks, […]

Implementing eventually consistent distributed transactions for placing orders and reducing inventory based on RabbitMQ

The National Day holiday really gave me a break, and the update progress was slow. Now that the status has finally been adjusted back, continue to update. Without further ado, let me show you the overall data flow diagram. Text Interpretation Step 1: The user places an order and calls the order service. We directly […]

Use Servlet to modify the fruit inventory system and use PostMan to test Servlet requests

<packaging>war</packaging> <dependencies> <dependency> <groupId>jakarta.servlet</groupId> <artifactId>jakarta.servlet-api</artifactId> <version>6.0.0</version> </dependency> <dependency> <groupId>com.csdn</groupId> <artifactId>pro03-fruit-optimize</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies> pro03-fruit-optimize is a jar package packaged by myself. Its function is to realize the addition, deletion, modification and check of the fruit system 1. Query fruit list IndexServlet package com.csdn.fruit.servlet; import com.csdn.fruit.dao.FruitDao; import com.csdn.fruit.dao.impl.FruitDaoImpl; import com.csdn.fruit.pojo.Fruit; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; […]

(4) Practical combat of oversold inventory cases – optimizing redis distributed locks

Foreword In the previous section, we have implemented the use of redis distributed locks to solve the problem of “oversold” products. This section is about the optimization of redis distributed locks. In the redis distributed lock in the previous section, our lock has two issues that can be optimized. First, the lock needs to be […]

Upgrade the fruit inventory system using jdbc technology (final version of the backend, not including the frontend)

1. Configuration dependencies <dependencies> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.10</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.28</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.2.16</version> </dependency> </dependencies> 2. Fruit entity class package com.csdn.fruit.pojo; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import java.io.Serializable; @Data @NoArgsConstructor @AllArgsConstructor public class Fruit implements Serializable { private Integer fid; private String fname; […]

Upgrade the fruit inventory system using jdbc technology (optimized version)

Extract execution update method Extract query method – ResultSetMetaData <strong>ResultSetMetaData rsmd = rs.getMetaData();//Metadata, structural data of the result set</strong> Extract query method – parse the result set and encapsulate it into an entity object Extract methods to obtain connections and release resources Transfer database configuration information to configuration file <dependencies> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.10</version> </dependency> […]

(3) Actual combat of inventory oversold cases – using redis distributed locks to solve the “oversold” problem

Foreword In the previous section, we introduced how to use traditional locks (row locks, optimistic locks, pessimistic locks) of the MySQL database to solve the “oversold problem” caused by concurrent access. Although mysql’s traditional lock can solve the problem of concurrent access very well, in terms of performance, mysql’s performance does not seem to be […]

Upgrade fruit inventory system using jdbc technology

<dependencies> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.10</version> <scope>compile</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.28</version> <scope>compile</scope> </dependency> </dependencies> package com.csdn.fruit.pojo; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import java.io.Serializable; @Data @NoArgsConstructor @AllArgsConstructor public class Fruit implements Serializable { private Integer fid; private String fname; private Integer price; private Integer fcount; private String remark; public […]

How does the flash sale system avoid oversold inventory?

public String buy(Long goodsId, Integer goodsNum) { //Query product inventory Goods goods = goodsMapper.selectById(goodsId); //If the current inventory is 0, it will prompt that the product has been sold out. if (goods.getGoodsInventory() <= 0) { return “The product has been sold out!”; } //If the current purchase quantity is greater than the inventory, it will […]

(2) Actual combat of inventory oversold cases – using traditional locks to solve the “oversold” problem

Foreword In the previous section, we introduced in detail the causes of the oversold problem and how to solve the oversold problem in single-application projects – controlling concurrent access through jvm local locks to solve the “oversold problem”. At the same time, we also proposed that local locks can only solve the overselling problem of […]