秒殺系統實際上是針對庫存作的系統。用戶成功秒殺商品,對於咱們系統的操做就是減庫存和記錄用戶的購買明細。用戶的購買明細包括記錄誰購買成功、購買成功的時間和付款信息。而對於減庫存操做,須要考慮到如下兩個問題:java
(1)如果用戶成功秒殺商品,咱們記錄了其購買明細,卻沒有減庫存。會致使商品的超賣。web
(2)減了庫存卻沒有記錄用戶的購買明細,致使商品的少賣。數據庫
對於上述兩個問題,能夠經過MySQL內置的事務機制進行處理,它能夠準確的幫咱們完成減庫存和記錄用戶購買明細的過程。瀏覽器
對於秒殺系統,咱們只是實現秒殺的一些功能:架構
(1)秒殺接口的暴露。併發
(2)執行秒殺的操做。app
(3)相關查詢,好比說列表查詢,詳情頁查詢。框架
秒殺系統包括包括三個模塊的設計,DAO層、Service層和Web層的設計,另外考慮到系統高併發的問題,從而設計了系統高併發的處理。在系統設計以前,爲了更好地理解系統的開發過程,對相關技術進行描述。ide
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.