├── .gitignore ├── README.md ├── .settings ├── org.eclipse.wst.jsdt.ui.superType.name ├── org.eclipse.wst.jsdt.ui.superType.container ├── org.eclipse.wst.validation.prefs ├── org.eclipse.m2e.core.prefs ├── org.eclipse.core.resources.prefs ├── org.eclipse.wst.common.project.facet.core.xml ├── .jsdtscope ├── org.eclipse.wst.common.component └── org.eclipse.jdt.core.prefs ├── 高并发秒杀系统.txt ├── src ├── main │ ├── java │ │ └── org │ │ │ └── seckill │ │ │ ├── seckill │ │ │ └── App.java │ │ │ ├── dao │ │ │ ├── SuccessKilledDao.java │ │ │ └── SeckillDao.java │ │ │ └── entity │ │ │ ├── SuccessKilled.java │ │ │ └── Seckill.java │ ├── webapp │ │ └── WEB-INF │ │ │ └── web.xml │ └── sql │ │ └── schema.sql └── test │ └── java │ └── org │ └── seckill │ └── seckill │ └── AppTest.java ├── LICENSE ├── .classpath ├── .project └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # seckill 2 | 高并发秒杀系统 3 | -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /高并发秒杀系统.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/theanswer910725/seckill/HEAD/高并发秒杀系统.txt -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.validation.prefs: -------------------------------------------------------------------------------- 1 | disabled=06target 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/test/java=UTF-8 4 | encoding/=UTF-8 5 | encoding/\u9AD8\u5E76\u53D1\u79D2\u6740\u7CFB\u7EDF.txt=GBK 6 | -------------------------------------------------------------------------------- /src/main/java/org/seckill/seckill/App.java: -------------------------------------------------------------------------------- 1 | package org.seckill.seckill; 2 | 3 | /** 4 | * Hello world! 5 | * 6 | */ 7 | public class App { 8 | public static void main( String[] args ) { 9 | System.out.println( "Hello World!" ); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/main/java/org/seckill/dao/SuccessKilledDao.java: -------------------------------------------------------------------------------- 1 | package org.seckill.dao; 2 | 3 | import org.seckill.entity.SuccessKilled; 4 | 5 | public interface SuccessKilledDao { 6 | 7 | /** 8 | * 插入购买明细,可过滤重复(联合唯一主键) 9 | * @param seckillId 10 | * @param userPhone 11 | * @return 插入的结果集数量 12 | */ 13 | int insertSuccessKilled(long seckillId,long userPhone); 14 | 15 | /** 16 | * 查询SuccessKilled并携带秒杀产品对象实体 17 | * @param seckillId 18 | * @return 19 | */ 20 | SuccessKilled queryByIdWithSeckill(long seckillId); 21 | } 22 | -------------------------------------------------------------------------------- /.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/main/java/org/seckill/dao/SeckillDao.java: -------------------------------------------------------------------------------- 1 | package org.seckill.dao; 2 | 3 | import java.util.Date; 4 | import java.util.List; 5 | 6 | import org.seckill.entity.Seckill; 7 | 8 | public interface SeckillDao { 9 | 10 | /** 11 | * 减少库存 12 | * @param seckillId 13 | * @param killTime 14 | * @return 如果影响行数>1,表示更新的记录行数 15 | */ 16 | int reduceNumber(long seckillId,Date killTime); 17 | 18 | /** 19 | * 根据ID查询 20 | * @param seckillId 21 | * @return 22 | */ 23 | Seckill queryById(long seckillId); 24 | 25 | /** 26 | * 根据偏移量查询秒杀商品列表 27 | * @param offset 28 | * @param limit 29 | * @return 30 | */ 31 | List queryAll(int offset,int limit); 32 | } 33 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.7 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 13 | org.eclipse.jdt.core.compiler.source=1.7 14 | -------------------------------------------------------------------------------- /src/test/java/org/seckill/seckill/AppTest.java: -------------------------------------------------------------------------------- 1 | package org.seckill.seckill; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * Unit test for simple App. 9 | */ 10 | public class AppTest 11 | extends TestCase 12 | { 13 | /** 14 | * Create the test case 15 | * 16 | * @param testName name of the test case 17 | */ 18 | public AppTest( String testName ) 19 | { 20 | super( testName ); 21 | } 22 | 23 | /** 24 | * @return the suite of tests being tested 25 | */ 26 | public static Test suite() 27 | { 28 | return new TestSuite( AppTest.class ); 29 | } 30 | 31 | /** 32 | * Rigourous Test :-) 33 | */ 34 | public void testApp() 35 | { 36 | assertTrue( true ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Lin。 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | seckill 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.jsdt.core.javascriptValidator 10 | 11 | 12 | 13 | 14 | org.eclipse.wst.common.project.facet.core.builder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.wst.validation.validationbuilder 25 | 26 | 27 | 28 | 29 | org.eclipse.m2e.core.maven2Builder 30 | 31 | 32 | 33 | 34 | 35 | org.eclipse.jem.workbench.JavaEMFNature 36 | org.eclipse.wst.common.modulecore.ModuleCoreNature 37 | org.eclipse.jdt.core.javanature 38 | org.eclipse.m2e.core.maven2Nature 39 | org.eclipse.wst.common.project.facet.core.nature 40 | org.eclipse.wst.jsdt.core.jsNature 41 | 42 | 43 | -------------------------------------------------------------------------------- /src/main/java/org/seckill/entity/SuccessKilled.java: -------------------------------------------------------------------------------- 1 | package org.seckill.entity; 2 | 3 | import java.util.Date; 4 | 5 | /** 6 | * Entity 7 | * @author Lin. 8 | * @date 2016/7/12 9 | */ 10 | public class SuccessKilled { 11 | private long seckillId; 12 | private long userPhone; 13 | private short state; 14 | private Date createTime; 15 | 16 | //多对一, 17 | private Seckill seckill; 18 | 19 | public long getSeckillId() { 20 | return seckillId; 21 | } 22 | public void setSeckillId(long seckillId) { 23 | this.seckillId = seckillId; 24 | } 25 | public long getUserPhone() { 26 | return userPhone; 27 | } 28 | public void setUserPhone(long userPhone) { 29 | this.userPhone = userPhone; 30 | } 31 | public short getState() { 32 | return state; 33 | } 34 | public void setState(short state) { 35 | this.state = state; 36 | } 37 | public Date getCreateTime() { 38 | return createTime; 39 | } 40 | public void setCreateTime(Date createTime) { 41 | this.createTime = createTime; 42 | } 43 | public Seckill getSeckill() { 44 | return seckill; 45 | } 46 | public void setSeckill(Seckill seckill) { 47 | this.seckill = seckill; 48 | } 49 | 50 | 51 | @Override 52 | public String toString() { 53 | 54 | return "SuccessKilled{" 55 | +"seckillId:"+seckillId+ 56 | ",userPhone:"+userPhone+ 57 | ",state:"+state+ 58 | ",createTime:"+createTime+"" 59 | + "}"; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/org/seckill/entity/Seckill.java: -------------------------------------------------------------------------------- 1 | package org.seckill.entity; 2 | 3 | import java.util.Date; 4 | 5 | /** 6 | * Entity 7 | * @author Lin. 8 | * @date 2016/7/12 9 | */ 10 | public class Seckill { 11 | private long seckillId; 12 | private String name; 13 | private int number; 14 | private Date startTime; 15 | private Date endTime; 16 | private Date createTime; 17 | 18 | public long getSeckillId() { 19 | return seckillId; 20 | } 21 | public void setSeckillId(long seckillId) { 22 | this.seckillId = seckillId; 23 | } 24 | public String getName() { 25 | return name; 26 | } 27 | public void setName(String name) { 28 | this.name = name; 29 | } 30 | public int getNumber() { 31 | return number; 32 | } 33 | public void setNumber(int number) { 34 | this.number = number; 35 | } 36 | public Date getStartTime() { 37 | return startTime; 38 | } 39 | public void setStartTime(Date startTime) { 40 | this.startTime = startTime; 41 | } 42 | public Date getEndTime() { 43 | return endTime; 44 | } 45 | public void setEndTime(Date endTime) { 46 | this.endTime = endTime; 47 | } 48 | public Date getCreateTime() { 49 | return createTime; 50 | } 51 | public void setCreateTime(Date createTime) { 52 | this.createTime = createTime; 53 | } 54 | 55 | 56 | @Override 57 | public String toString() { 58 | 59 | return "Seckill{" 60 | +"seckillId:"+seckillId+ 61 | ",name:"+name+ 62 | ",number:"+number+ 63 | ",startTime:"+startTime+ 64 | ",endTime:"+endTime+ 65 | ",createTime:"+createTime+"" 66 | + "}"; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/main/sql/schema.sql: -------------------------------------------------------------------------------- 1 | -- 数据库初始化脚本 2 | 3 | --创建数据库 4 | CREATE DATABASE seckill; 5 | --使用数据库 6 | use seckill; 7 | --创建秒杀库存表 8 | CREATE TABLE seckill( 9 | `seckill_id` bigint primary key AUTO_INCREMENT COMMENT '商品库存id', 10 | `name` varchar(120) NOT NULL COMMENT '商品名称', 11 | `number` int NOT NULL COMMENT '库存数量', 12 | `start_time` timestamp NOT NULL COMMENT '秒杀开启时间', 13 | `end_time` timestamp NOT NULL COMMENT '秒杀结束时间', 14 | `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', 15 | key idx_start_time(start_time), 16 | key idx_end_time(end_time), 17 | key idx_create_time(create_time) 18 | )ENGINE=InnoDB AUTO_INCREMENT=1000 DEFAULT CHARSET=UTF8 COMMENT='秒杀库存表'; 19 | 20 | --初始化数据 21 | insert into seckill(name,number,start_time,end_time) 22 | values 23 | ('100元秒杀iPhone6s Plus',100,'2016-7-15 00:00:00','2016-7-16 00:00:00'), 24 | ('500元秒杀SAMSUNG Galaxy S7edge',200,'2016-7-15 00:00:00','2016-7-16 00:00:00'), 25 | ('10元秒杀iPad2',300,'2016-7-15 00:00:00','2016-7-16 00:00:00'), 26 | ('1元秒杀MI 5',400,'2016-7-15 00:00:00','2016-7-16 00:00:00'); 27 | 28 | --秒杀成功明细表 29 | --用户登录认证相关信息 30 | create table success_killed( 31 | `seckill_id` bigint NOT NULL COMMENT '秒杀商品ID', 32 | `user_phone` bigint NOT NULL COMMENT '用户手机号', 33 | `state` tinyint NOT NULL DEFAULT -1 COMMENT '状态标识:-1:无效 0:成功 1:已付款 2:已发货', 34 | `create_time` timestamp NOT NULL COMMENT '创建时间', 35 | PRIMARY KEY(seckill_id,user_phone),/*联合主键*/ 36 | key idx_create_time(create_time) 37 | )ENGINE=InnoDB DEFAULT CHARSET=UTF8 COMMENT='秒杀成功明细表'; 38 | 39 | 40 | --上线v1.1 DDL 41 | ALTER TABLE seckill 42 | DROP INDEX idx_create_time, 43 | ADD INDEX idx_c_s(start_time,create_time); -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | org.seckill 6 | seckill 7 | 0.0.1-SNAPSHOT 8 | war 9 | 10 | seckill 11 | http://maven.apache.org 12 | 13 | 14 | UTF-8 15 | 16 | 17 | 18 | seckill 19 | 20 | 21 | org.apache.maven.plugins 22 | maven-compiler-plugin 23 | 2.3.2 24 | 25 | 1.7 26 | 1.7 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | junit 36 | junit 37 | 4.11 38 | test 39 | 40 | 41 | 46 | 47 | org.slf4j 48 | slf4j-api 49 | 1.7.12 50 | 51 | 52 | ch.qos.logback 53 | logback-core 54 | 1.1.1 55 | 56 | 57 | 58 | ch.qos.logback 59 | logback-classic 60 | 1.1.1 61 | 62 | 63 | 64 | mysql 65 | mysql-connector-java 66 | 5.1.35 67 | runtime 68 | 69 | 70 | c3p0 71 | c3p0 72 | 0.9.1.2 73 | 74 | 75 | 76 | org.mybatis 77 | mybatis 78 | 3.4.1 79 | 80 | 81 | 82 | org.mybatis 83 | mybatis-spring 84 | 1.3.0 85 | 86 | 87 | 88 | taglibs 89 | standard 90 | 1.1.2 91 | 92 | 93 | jstl 94 | jstl 95 | 1.2 96 | 97 | 98 | com.fasterxml.jackson.core 99 | jackson-databind 100 | 2.9.10.5 101 | 102 | 103 | javax.servlet 104 | javax.servlet-api 105 | 3.1.0 106 | 107 | 108 | 109 | 110 | org.springframework 111 | spring-core 112 | 4.3.18 113 | 114 | 115 | org.springframework 116 | spring-beans 117 | 4.1.6.RELEASE 118 | 119 | 120 | org.springframework 121 | spring-context 122 | 4.1.6.RELEASE 123 | 124 | 125 | 126 | org.springframework 127 | spring-jdbc 128 | 4.1.6.RELEASE 129 | 130 | 131 | org.springframework 132 | spring-tx 133 | 4.1.6.RELEASE 134 | 135 | 136 | 137 | org.springframework 138 | spring-web 139 | 4.1.6.RELEASE 140 | 141 | 142 | org.springframework 143 | spring-webmvc 144 | 4.1.6.RELEASE 145 | 146 | 147 | 148 | org.springframework 149 | spring-test 150 | 4.1.6.RELEASE 151 | 152 | 153 | 154 | 155 | --------------------------------------------------------------------------------