This paper mainly uses springboot, Realize a single version of seckill demo, Through stand-alone version , Can have a certain understanding of basic concurrent seckill knowledge .

First, provide seckill service implementation class :
/** * spring Annotation added to implementation class */ @Service @Transactional public class OrderServiceImpl
implements OrderService { @Autowired private StockMapper stockMapper;
@Autowired private StockOrderMapper orderMapper; @Autowired private
StringRedisTemplate redisTemplate; // Method synchronized modification , Pessimistic lock added to stand-alone application
// be careful , And @Transactional Used together yes , Will not take effect , If you want to use it, use it where the method is called synchronized Code block
// reason :Transactional Transaction started before lock , A wide range of business , When a thread lock is released , But the business hasn't been committed yet , The next thread is , Commit last transaction together
// Generally not recommended , Threads will be used individually , Reduce efficiency , And don't add in business code synchronized @Override public int
kill(Integer id) { // join redis Cache time limited rush , Even if the token is obtained, it cannot be snapped up if it is not within the active time // check redis Is China seckill finished if
(!redisTemplate.hasKey("kill"+id)) { throw new
RuntimeException(" The current rush to buy is over !"); } // Verify inventory StockDO stockDO = checkStock(id);
// Deduct inventory updateStock(stockDO); // Create order

Technology
©2019-2020 Toolsou All rights reserved,
data structure C Parking management of language 300 million people are working hard Java Share five face to face experience ,offer Taken ! Byte three side remote ,Java+Redis+ network + database + algorithm , Easy to kill interviewers ?C/C++ The 11th Blue Bridge Cup provincial competition B Group 2 Junior college background Java Post , Who says that there is no spring for college programmers ? new iPhone I won't support it 5G Will lead to further decline in shipment Not yet Spring? Ali P8 Summative 100 Analysis of Dao interview , Let you hammer the interviewer Upright code analysis __ Principle of two wheel balance car 【C language 】 Mine clearance game details Some suggestions for novice programmers to write practical business code in confusion