秒杀系统-介绍

秒杀系统

秒杀系统其实是针对库存做的系统。用户成功秒杀商品,对于我们系统的操作就是减库存和记录用户的购买明细。用户的购买明细包括记录谁购买成功、购买成功的时间和付款信息。而对于减库存操作,需要考虑到以下两个问题:

(1)若是用户成功秒杀商品,我们记录了其购买明细,却没有减库存。会导致商品的超卖。

(2)减了库存却没有记录用户的购买明细,导致商品的少卖。

对于上述两个问题,可以通过MySQL内置的事务机制进行处理,它可以准确的帮我们完成减库存和记录用户购买明细的过程。

对于秒杀系统,我们只是实现秒杀的一些功能:

(1)秒杀接口的暴露。

(2)执行秒杀的操作。

(3)相关查询,比如说列表查询,详情页查询。

秒杀系统包括包括三个模块的设计,DAO层、Service层和Web层的设计,另外考虑到系统高并发的问题,从而设计了系统高并发的处理。在系统设计之前,为了更好地理解系统的开发过程,对相关技术进行描述。

6.3.1 相关技术介绍

MySQL:

创建相关表、事务的应用和行级锁。

DAO:

数据访问对象基本上是一个对象或接口,它提供对基础数据库或任何其他持久存储的访问。

MyBatis:

MyBATIS是支持自定义SQL、存储过程和高级映射的第一类持久性框架。MybATIS消除了几乎所有的JDBC代码和手动设置参数和检索结果。MyBatis可以使用简单的XML或注释的配置和地图图元,地图接口和java POJO(Plain Old java对象)到数据库的记录。

SLF4J:

java的简单日志门面(是slf4j)作为一个简单的立面或抽象的各种日志框架(例如java.util.logging,logback,log4j)允许用户插入所需的部署时间日志框架。

登录项目

Logback:

回溯的目的是作为流行的Log4J项目的继承者,拿起Log4J离开的地方。

日志回退的架构足够通用,以便在不同的情况下应用。目前,回溯被分为三个模块:回溯核心、回溯经典和回溯访问。

回溯核心模块为其他两个模块奠定基础。LogLogic经典模块可以被同化到Log4J的一个显著改进的版本中。此外,回溯经典本身实现了SLF4J API,这样您就可以轻松地在回溯和其他日志记录框架之间来回切换,例如Log4J或JavaUTIL日志(JUL)。

回溯访问模块与Servlet容器(如Tomcat和JETTY)集成,提供HTTP访问日志功能。注意,您可以轻松地在LogCub核心之上构建自己的模块。

C3P0:

C3P0是一个易于使用的库,通过使用JDBC3规范定义的功能和JDBC2的可选扩展来增强传统JDBC驱动程序“企业就绪”。

Spring framework:

Spring框架是java平台的一个应用框架和反转控制容器。该框架的核心功能,可以在任何java应用程序使用,但也有在顶部的java EE平台构建Web应用的扩展。

Spring MVC框架:

Spring WebMVC框架提供了模型视图控制器(MVC)体系结构和准备好的组件,这些组件可以用来开发灵活和松散耦合的Web应用程序。MVC模式导致分离应用程序的不同方面(输入逻辑、业务逻辑和UI逻辑),同时在这些元素之间提供松散耦合。

该模型封装应用程序数据,一般来说,它们将由POJO组成。

视图负责渲染模型数据,一般来说,它生成客户端浏览器可以解释的HTML输出。

控制器负责处理用户请求并建立适当的模型并将其传递给视图进行渲染。

taglib:

TAGLIB指令声明您的JSP页面使用一组自定义标记,标识库的位置,并提供一种标识JSP页面中自定义标记的方法。

JSTL:

JavaServer页面标准标签库(JSTL)是一个有用的JSP标签集合,它封装了许多JSP应用程序共同的核心功能。JSTL支持常见的结构化任务,如迭代和条件语句、用于操纵XML文档的标记、国际化标记和SQL标记。

protostuff:

具有支持后向兼容性(模式演进)和验证的内置支持的序列化库。

MySQL:

Create related tables,the applications of transaction and row-level lock.

DAO

The Data Access Object is basically an object or an interface that provides access to an underlying database or any other persistence storage.

MyBatis:

MyBatis is a first class persistence framework with support for custom SQL, stored procedures and advanced mappings. MyBatis eliminates almost all of the JDBC code and manual setting of parameters and retrieval of results. MyBatis can use simple XML or Annotations for configuration and map primitives, Map interfaces and Java POJOs (Plain Old Java Objects) to database records.

SLF4J

The Simple Logging Facade for Java (SLF4J) serves as a simple facade or abstraction for various logging frameworks (e.g. java.util.logging, logback, log4j) allowing the end user to plug in the desired logging framework at deployment time.

Logback Project

Logback

Logback is intended as a successor to the popular log4j project, picking up where log4j leaves off.

Logback's architecture is sufficiently generic so as to apply under different circumstances. At present time, logback is divided into three modules, logback-core, logback-classic and logback-access.

The logback-core module lays the groundwork for the other two modules. The logback-classic module can be assimilated to a significantly improved version of log4j. Moreover, logback-classic natively implements the SLF4J API so that you can readily switch back and forth between logback and other logging frameworks such as log4j or java.util.logging (JUL).

The logback-access module integrates with Servlet containers, such as Tomcat and Jetty, to provide HTTP-access log functionality. Note that you could easily build your own module on top of logback-core.

c3p0

c3p0 is an easy-to-use library for making traditional JDBC drivers "enterprise-ready" by augmenting them with functionality defined by the jdbc3 spec and the optional extensions to jdbc2.

Spring framework

The Spring Framework is an application frameworkand inversion of control container for the Java platform. The framework's core features can be used by any Java application, but there are extensions for building web applications on top of the Java EE platform.

Spring - MVC Framework

The Spring Web MVC framework provides Model-View-Controller (MVC) architecture and ready components that can be used to develop flexible and loosely coupled web applications. The MVC pattern results in separating the different aspects of the application (input logic, business logic, and UI logic), while providing a loose coupling between these elements.

The Model encapsulates the application data and in general they will consist of POJO.

The View is responsible for rendering the model data and in general it generates HTML output that the client's browser can interpret.

The Controller is responsible for processing user requests and building an appropriate model and passes it to the view for rendering.

taglib:

The taglib directive declares that your JSP page uses a set of custom tags, identifies the location of the library, and provides a means for identifying the custom tags in your JSP page.

JSTL

The JavaServer Pages Standard Tag Library (JSTL) is a collection of useful JSP tags which encapsulates the core functionality common to many JSP applications. JSTL has support for common, structural tasks such as iteration and conditionals, tags for manipulating XML documents, internationalization tags, and SQL tags.

protostuff

A serialization library with built-in support for forward-backward compatibility (schema evolution) and validation.

猜你喜欢

转载自www.cnblogs.com/smuxiaolei/p/8979707.html