提交threadlocal讲解

This commit is contained in:
qiurunze 2018-09-21 23:11:31 +08:00
parent 133946bdff
commit 9c73ca56a5
17 changed files with 467 additions and 301 deletions

View File

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: com.google.guava:guava:18.0">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/google/guava/guava/18.0/guava-18.0.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/com/google/guava/guava/18.0/guava-18.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/com/google/guava/guava/18.0/guava-18.0-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -2,9 +2,18 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="59bd24de-7908-4982-927f-6d236db7e416" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__com_google_guava_guava_18_0.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/DemoTask.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/Test.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/controller/RateLimiterController.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
<change beforePath="$PROJECT_DIR$/miaosha.iml" beforeDir="false" afterPath="$PROJECT_DIR$/miaosha.iml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/config/UserArgumentResolver.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/config/UserArgumentResolver.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/controller/MiaoshaController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/controller/MiaoshaController.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/target/classes/com/geekq/miaosha/config/UserArgumentResolver.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/com/geekq/miaosha/config/UserArgumentResolver.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/target/classes/com/geekq/miaosha/controller/MiaoshaController.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/com/geekq/miaosha/controller/MiaoshaController.class" afterDir="false" />
</list>
<ignored path="$PROJECT_DIR$/target/" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@ -20,57 +29,59 @@
<session id="-262413793">
<usages-collector id="statistics.lifecycle.project">
<counts>
<entry key="project.closed" value="7" />
<entry key="project.open.time.1" value="1" />
<entry key="project.open.time.10" value="3" />
<entry key="project.open.time.2" value="1" />
<entry key="project.open.time.6" value="1" />
<entry key="project.closed" value="11" />
<entry key="project.open.time.1" value="2" />
<entry key="project.open.time.10" value="4" />
<entry key="project.open.time.12" value="1" />
<entry key="project.open.time.15" value="1" />
<entry key="project.open.time.2" value="3" />
<entry key="project.open.time.6" value="2" />
<entry key="project.open.time.7" value="1" />
<entry key="project.open.time.8" value="3" />
<entry key="project.open.time.9" value="1" />
<entry key="project.opened" value="11" />
<entry key="project.opened" value="18" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.extensions.open">
<counts>
<entry key="DemoController" value="1" />
<entry key="class" value="22" />
<entry key="class" value="24" />
<entry key="finanacial" value="1" />
<entry key="htm" value="12" />
<entry key="html" value="12" />
<entry key="java" value="179" />
<entry key="java" value="194" />
<entry key="js" value="1" />
<entry key="md" value="2" />
<entry key="md" value="3" />
<entry key="properties" value="6" />
<entry key="sql" value="1" />
<entry key="ts" value="1" />
<entry key="txt" value="9" />
<entry key="xml" value="4" />
<entry key="xml" value="5" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.types.open">
<counts>
<entry key="CLASS" value="22" />
<entry key="CLASS" value="24" />
<entry key="HTML" value="24" />
<entry key="JAVA" value="179" />
<entry key="JAVA" value="194" />
<entry key="JavaScript" value="1" />
<entry key="Markdown" value="2" />
<entry key="Markdown" value="3" />
<entry key="PLAIN_TEXT" value="10" />
<entry key="Properties" value="6" />
<entry key="SQL" value="1" />
<entry key="TypeScript" value="1" />
<entry key="UML" value="1" />
<entry key="XML" value="4" />
<entry key="XML" value="5" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.extensions.edit">
<counts>
<entry key="class" value="1" />
<entry key="dummy" value="18" />
<entry key="dummy" value="30" />
<entry key="htm" value="1" />
<entry key="html" value="7" />
<entry key="java" value="6990" />
<entry key="md" value="414" />
<entry key="java" value="7525" />
<entry key="md" value="587" />
<entry key="properties" value="55" />
<entry key="regexp" value="11" />
<entry key="txt" value="615" />
@ -81,9 +92,9 @@
<counts>
<entry key="CLASS" value="1" />
<entry key="HTML" value="8" />
<entry key="JAVA" value="6990" />
<entry key="Markdown" value="414" />
<entry key="PLAIN_TEXT" value="633" />
<entry key="JAVA" value="7525" />
<entry key="Markdown" value="587" />
<entry key="PLAIN_TEXT" value="645" />
<entry key="Properties" value="55" />
<entry key="RegExp" value="11" />
<entry key="XML" value="7" />
@ -93,67 +104,38 @@
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/controller/MiaoshaController.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-130">
<caret line="89" column="13" selection-start-line="84" selection-start-column="4" selection-end-line="89" selection-end-column="13" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/resources/static/order_detail.htm">
<provider selected="true" editor-type-id="text-editor" />
</entry>
</file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/README.md">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="332">
<caret line="18" column="42" selection-start-line="18" selection-start-column="42" selection-end-line="18" selection-end-column="42" />
<state relative-caret-position="337">
<caret line="117" column="27" lean-forward="true" selection-start-line="117" selection-start-column="27" selection-end-line="117" selection-end-column="27" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/redis/KeyPrefix.java">
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/DemoTask.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="44">
<caret line="2" column="16" selection-start-line="2" selection-start-column="7" selection-end-line="2" selection-end-column="16" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/redis/BasePrefix.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="264">
<caret line="12" column="5" lean-forward="true" selection-start-line="12" selection-start-column="5" selection-end-line="12" selection-end-column="5" />
<state relative-caret-position="277">
<caret line="32" column="41" selection-start-line="32" selection-start-column="41" selection-end-line="32" selection-end-column="41" />
<folding>
<element signature="e#333#334#0" expanded="true" />
<element signature="e#362#363#0" expanded="true" />
<element signature="e#410#411#0" expanded="true" />
<element signature="e#457#458#0" expanded="true" />
<element signature="imports" expanded="true" />
<element signature="e#298#460#0" expanded="true" />
<element signature="e#459#460#0" expanded="true" />
<element signature="e#569#570#0" expanded="true" />
<element signature="e#606#607#0" expanded="true" />
<element signature="e#858#995#0" expanded="true" />
<element signature="e#994#995#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/redis/GoodsKey.java">
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/Test.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="154">
<caret line="9" column="64" selection-start-line="9" selection-start-column="64" selection-end-line="9" selection-end-column="64" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/resources/static/goods_detail.htm">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1474">
<caret line="67" column="89" selection-start-line="67" selection-start-column="89" selection-end-line="67" selection-end-column="89" />
<state relative-caret-position="220">
<caret line="10" column="38" lean-forward="true" selection-start-line="10" selection-start-column="38" selection-end-line="10" selection-end-column="38" />
</state>
</provider>
</entry>
@ -161,8 +143,8 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/access/AccessLimit.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="154">
<caret line="11" column="12" selection-start-line="11" selection-start-column="12" selection-end-line="11" selection-end-column="12" />
<state relative-caret-position="132">
<caret line="10" column="18" selection-start-line="10" selection-start-column="18" selection-end-line="10" selection-end-column="18" />
</state>
</provider>
</entry>
@ -170,27 +152,61 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/access/AccessInterceptor.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="814">
<caret line="52" column="42" selection-start-line="52" selection-start-column="42" selection-end-line="52" selection-end-column="42" />
<state relative-caret-position="396">
<caret line="33" column="21" selection-start-line="33" selection-start-column="21" selection-end-line="33" selection-end-column="21" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/access/AccessKey.java">
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/access/UserContext.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="176">
<caret line="11" column="23" selection-start-line="11" selection-start-column="23" selection-end-line="11" selection-end-column="23" />
<state relative-caret-position="132">
<caret line="6" column="27" selection-start-line="6" selection-start-column="27" selection-end-line="6" selection-end-column="27" />
<folding>
<element signature="e#178#179#0" expanded="true" />
<element signature="e#213#214#0" expanded="true" />
<element signature="e#272#273#0" expanded="true" />
<element signature="e#324#325#0" expanded="true" />
<element signature="e#244#245#0" expanded="true" />
<element signature="e#271#272#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="jar:///usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar!/java/lang/ThreadLocal.class">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1980">
<caret line="112" column="8" selection-start-line="112" selection-start-column="8" selection-end-line="112" selection-end-column="8" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/config/UserArgumentResolver.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="616">
<caret line="40" column="21" selection-start-line="40" selection-start-column="21" selection-end-line="40" selection-end-column="21" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/config/WebConfig.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="110">
<caret line="10" column="13" selection-start-line="10" selection-start-column="13" selection-end-line="10" selection-end-column="13" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/service/MiaoShaUserService.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="462">
<caret line="35" column="24" selection-start-line="35" selection-start-column="20" selection-end-line="35" selection-end-column="24" />
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="FileTemplateManagerImpl">
@ -208,6 +224,8 @@
<find>refreshVerifyCode</find>
<find>path</find>
<find>/path</find>
<find>UserContext</find>
<find>user</find>
</findStrings>
</component>
<component name="Git.Settings">
@ -216,12 +234,6 @@
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/Md5Utils/MD5Utils.java" />
<option value="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/vo/LoginVO.java" />
<option value="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/service/UserService.java" />
<option value="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/validator/isMobile.java" />
<option value="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/validator/IsMobile.java" />
<option value="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/utils/ValidatorUtil.java" />
<option value="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/vo/LoginVo.java" />
<option value="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/domain/MiaoshaUser.java" />
<option value="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/service/MiaoshaUser.java" />
@ -235,7 +247,6 @@
<option value="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/redis/BasePrefix.java" />
<option value="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/exception/GlobleExceptionandler.java" />
<option value="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/config/WebConfig.java" />
<option value="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/config/UserArgumentResolver.java" />
<option value="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/vo/GoodsVo.java" />
<option value="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/dao/MiaoshaUserDao.java" />
<option value="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/service/MiaoshaUserService.java" />
@ -265,7 +276,14 @@
<option value="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/access/UserContext.java" />
<option value="$PROJECT_DIR$/src/main/resources/static/goods_detail.htm" />
<option value="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/redis/RedisService.java" />
<option value="$PROJECT_DIR$/pom.xml" />
<option value="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/RateLimiterDemo.java" />
<option value="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/controller/RateLimiterController.java" />
<option value="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/controller/MiaoshaController.java" />
<option value="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/config/UserArgumentResolver.java" />
<option value="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/Demo1.java" />
<option value="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/Test.java" />
<option value="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/DemoTask.java" />
<option value="$PROJECT_DIR$/README.md" />
</list>
</option>
@ -313,9 +331,6 @@
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="AndroidView" />
<pane id="Scope" />
<pane id="PackagesPane" />
<pane id="ProjectPane">
<subPane>
<expand>
@ -349,33 +364,6 @@
<item name="java" type="462c0819:PsiDirectoryNode" />
<item name="miaosha" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="miaosha_1" type="b2602c69:ProjectViewProjectNode" />
<item name="miaosha_1" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
<item name="main" type="462c0819:PsiDirectoryNode" />
<item name="java" type="462c0819:PsiDirectoryNode" />
<item name="miaosha" type="462c0819:PsiDirectoryNode" />
<item name="access" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="miaosha_1" type="b2602c69:ProjectViewProjectNode" />
<item name="miaosha_1" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
<item name="main" type="462c0819:PsiDirectoryNode" />
<item name="java" type="462c0819:PsiDirectoryNode" />
<item name="miaosha" type="462c0819:PsiDirectoryNode" />
<item name="controller" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="miaosha_1" type="b2602c69:ProjectViewProjectNode" />
<item name="miaosha_1" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
<item name="main" type="462c0819:PsiDirectoryNode" />
<item name="java" type="462c0819:PsiDirectoryNode" />
<item name="miaosha" type="462c0819:PsiDirectoryNode" />
<item name="redis" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="miaosha_1" type="b2602c69:ProjectViewProjectNode" />
<item name="miaosha_1" type="462c0819:PsiDirectoryNode" />
@ -399,6 +387,9 @@
<select />
</subPane>
</pane>
<pane id="PackagesPane" />
<pane id="Scope" />
<pane id="AndroidView" />
</panes>
</component>
<component name="PropertiesComponent">
@ -410,7 +401,7 @@
<property name="RequestMappingsPanelWidth2" value="75" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="aspect.path.notification.shown" value="true" />
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1537284032538" />
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1537542591345" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
@ -449,7 +440,20 @@
</list>
</option>
</component>
<component name="RunManager" selected="Spring Boot.eekQMainApplication">
<component name="RunManager" selected="Application.Test">
<configuration name="DemoTask" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="com.geekq.miaosha.DemoTask" />
<module name="miaosha" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="com.geekq.miaosha.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="MD5Utils" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="com.geekq.miaosha.Md5Utils.MD5Utils" />
<module name="miaosha" />
@ -463,6 +467,19 @@
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="Test" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="com.geekq.miaosha.Test" />
<module name="miaosha" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="com.geekq.miaosha.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="MainApplication" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot" temporary="true" nameIsGenerated="true">
<module name="miaosha" />
<extension name="coverage">
@ -493,9 +510,13 @@
<item itemvalue="Spring Boot.MainApplication" />
<item itemvalue="Spring Boot.eekQMainApplication" />
<item itemvalue="Application.MD5Utils" />
<item itemvalue="Application.DemoTask" />
<item itemvalue="Application.Test" />
</list>
<recent_temporary>
<list>
<item itemvalue="Application.Test" />
<item itemvalue="Application.DemoTask" />
<item itemvalue="Spring Boot.eekQMainApplication" />
<item itemvalue="Application.MD5Utils" />
<item itemvalue="Spring Boot.MainApplication" />
@ -522,12 +543,19 @@
<workItem from="1536975289539" duration="26867000" />
<workItem from="1537060950052" duration="25966000" />
<workItem from="1537148890283" duration="12735000" />
<workItem from="1537236248667" duration="3148000" />
<workItem from="1537236248667" duration="4356000" />
<workItem from="1537323473437" duration="1365000" />
<workItem from="1537371216363" duration="161000" />
<workItem from="1537430338514" duration="600000" />
<workItem from="1537452261581" duration="3188000" />
<workItem from="1537495273344" duration="740000" />
<workItem from="1537508189682" duration="5476000" />
<workItem from="1537538826651" duration="3455000" />
</task>
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="102818000" />
<option name="totallyTimeSpent" value="119011000" />
</component>
<component name="TodoView">
<todo-panel id="selected-file">
@ -542,7 +570,7 @@
<frame x="-1" y="29" width="1922" height="1025" extended-state="6" />
<editor active="true" />
<layout>
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.25079873" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.25346112" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Designer" order="2" />
<window_info id="Image Layers" order="3" />
@ -551,14 +579,14 @@
<window_info id="Capture Tool" order="6" />
<window_info id="Web" order="7" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" weight="0.10391062" />
<window_info anchor="bottom" id="Run" order="2" sideWeight="0.8951012" weight="0.40335196" />
<window_info anchor="bottom" id="Debug" order="3" sideWeight="0.786475" weight="0.3150838" />
<window_info anchor="bottom" id="Find" order="1" visible="true" weight="0.1631285" />
<window_info active="true" anchor="bottom" id="Run" order="2" sideWeight="0.8951012" visible="true" weight="0.3821229" />
<window_info anchor="bottom" id="Debug" order="3" sideWeight="0.786475" weight="0.46815643" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" weight="0.32960895" />
<window_info anchor="bottom" id="Spring" order="7" />
<window_info anchor="bottom" id="Terminal" order="8" visible="true" weight="0.32960895" />
<window_info anchor="bottom" id="Terminal" order="8" weight="0.32960895" />
<window_info anchor="bottom" id="Event Log" order="9" sideWeight="0.21352503" side_tool="true" weight="0.4111732" />
<window_info anchor="bottom" id="Messages" order="10" sideWeight="0.49946752" weight="0.32960895" />
<window_info anchor="bottom" id="Java Enterprise" order="11" />
@ -621,7 +649,7 @@
<breakpoints>
<line-breakpoint type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/controller/MiaoshaController.java</url>
<line>122</line>
<line>132</line>
<properties />
<option name="timeStamp" value="10" />
</line-breakpoint>
@ -633,7 +661,7 @@
</line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/controller/MiaoshaController.java</url>
<line>94</line>
<line>104</line>
<properties />
<option name="timeStamp" value="13" />
</line-breakpoint>
@ -645,7 +673,7 @@
</line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/controller/MiaoshaController.java</url>
<line>108</line>
<line>118</line>
<properties />
<option name="timeStamp" value="17" />
</line-breakpoint>
@ -673,6 +701,12 @@
<properties />
<option name="timeStamp" value="24" />
</line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/service/MiaoShaUserService.java</url>
<line>81</line>
<properties />
<option name="timeStamp" value="26" />
</line-breakpoint>
</breakpoints>
<breakpoints-dialog>
<breakpoints-dialog />
@ -704,62 +738,6 @@
</expressions>
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/vo/OrderDetailVo.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="132">
<caret line="6" column="18" lean-forward="true" selection-start-line="6" selection-start-column="18" selection-end-line="6" selection-end-column="18" />
</state>
</provider>
</entry>
<entry file="jar://$MAVEN_REPOSITORY$/org/springframework/spring-aop/4.3.12.RELEASE/spring-aop-4.3.12.RELEASE.jar!/org/springframework/aop/framework/ReflectiveMethodInvocation.class">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="199">
<caret line="63" selection-start-line="63" selection-end-line="63" />
</state>
</provider>
</entry>
<entry file="jar://$MAVEN_REPOSITORY$/org/springframework/spring-aop/4.3.12.RELEASE/spring-aop-4.3.12.RELEASE.jar!/org/springframework/aop/framework/CglibAopProxy.class">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="199">
<caret line="476" selection-start-line="476" selection-end-line="476" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/domain/OrderInfo.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="88">
<caret line="4" column="24" lean-forward="true" selection-start-line="4" selection-start-column="24" selection-end-line="4" selection-end-column="24" />
</state>
</provider>
</entry>
<entry file="jar://$MAVEN_REPOSITORY$/org/springframework/amqp/spring-amqp/1.7.4.RELEASE/spring-amqp-1.7.4.RELEASE.jar!/org/springframework/amqp/core/AmqpTemplate.class">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="289">
<caret line="18" column="9" selection-start-line="18" selection-start-column="9" selection-end-line="18" selection-end-column="9" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/rabbitmq/MiaoshaMessage.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="88">
<caret line="4" column="27" selection-start-line="4" selection-start-column="13" selection-end-line="4" selection-end-column="27" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/rabbitmq/MQSender.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="330">
<caret line="20" column="30" lean-forward="true" selection-start-line="20" selection-start-column="30" selection-end-line="20" selection-end-column="30" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/resources/application.properties">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="217">
<caret line="51" column="30" selection-start-line="51" selection-start-column="30" selection-end-line="51" selection-end-column="30" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/dao/MiaoShaUserDao.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="352">
@ -872,13 +850,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/rabbitmq/MQReceiver.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="396">
<caret line="50" column="31" lean-forward="true" selection-start-line="50" selection-start-column="31" selection-end-line="50" selection-end-column="31" />
</state>
</provider>
</entry>
<entry file="jar://$MAVEN_REPOSITORY$/org/springframework/spring-web/4.3.12.RELEASE/spring-web-4.3.12.RELEASE.jar!/org/springframework/web/method/support/InvocableHandlerMethod.class">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="171">
@ -886,13 +857,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/service/OrderService.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="286">
<caret line="24" column="24" selection-start-line="24" selection-start-column="24" selection-end-line="24" selection-end-column="24" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/controller/OrderController.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="141">
@ -907,48 +871,10 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/access/UserContext.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="132">
<caret line="6" column="37" lean-forward="true" selection-start-line="6" selection-start-column="37" selection-end-line="6" selection-end-column="37" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/readme.txt" />
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/service/MiaoshaService.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="704">
<caret line="48" selection-start-line="48" selection-end-line="48" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/service/MiaoShaUserService.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1958">
<caret line="103" column="19" selection-start-line="103" selection-start-column="19" selection-end-line="103" selection-end-column="19" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/miaosha.sql">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/eekQMainApplication.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="198">
<caret line="10" column="5" lean-forward="true" selection-start-line="8" selection-start-column="2" selection-end-line="10" selection-end-column="5" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/pom.xml">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-1650">
<caret line="13" lean-forward="true" selection-start-line="13" selection-end-line="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/redis/RedisConfig.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="132">
@ -963,16 +889,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/controller/GoodsController.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1122">
<caret line="74" selection-start-line="74" selection-end-line="74" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/redis/RedisPoolFactory.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="176">
@ -990,40 +906,6 @@
<entry file="file://$PROJECT_DIR$/src/main/resources/static/order_detail.htm">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/src/main/resources/static/goods_detail.htm">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1474">
<caret line="67" column="89" selection-start-line="67" selection-start-column="89" selection-end-line="67" selection-end-column="89" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/access/AccessLimit.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="154">
<caret line="11" column="12" selection-start-line="11" selection-start-column="12" selection-end-line="11" selection-end-column="12" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/access/AccessInterceptor.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="814">
<caret line="52" column="42" selection-start-line="52" selection-start-column="42" selection-end-line="52" selection-end-column="42" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/access/AccessKey.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="176">
<caret line="11" column="23" selection-start-line="11" selection-start-column="23" selection-end-line="11" selection-end-column="23" />
<folding>
<element signature="e#178#179#0" expanded="true" />
<element signature="e#213#214#0" expanded="true" />
<element signature="e#272#273#0" expanded="true" />
<element signature="e#324#325#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/redis/KeyPrefix.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="44">
@ -1034,13 +916,7 @@
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/redis/BasePrefix.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="264">
<caret line="12" column="5" lean-forward="true" selection-start-line="12" selection-start-column="5" selection-end-line="12" selection-end-column="5" />
<folding>
<element signature="e#333#334#0" expanded="true" />
<element signature="e#362#363#0" expanded="true" />
<element signature="e#410#411#0" expanded="true" />
<element signature="e#457#458#0" expanded="true" />
</folding>
<caret line="12" column="5" selection-start-line="12" selection-start-column="5" selection-end-line="12" selection-end-column="5" />
</state>
</provider>
</entry>
@ -1051,17 +927,173 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/resources/static/goods_detail.htm">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1474">
<caret line="67" column="89" selection-start-line="67" selection-start-column="89" selection-end-line="67" selection-end-column="89" />
</state>
</provider>
</entry>
<entry file="jar://$MAVEN_REPOSITORY$/com/google/guava/guava/18.0/guava-18.0.jar!/com/google/common/util/concurrent/RateLimiter.class">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="264">
<caret line="22" column="30" selection-start-line="22" selection-start-column="30" selection-end-line="22" selection-end-column="30" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/controller/GoodsController.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="88">
<caret line="27" selection-start-line="27" selection-end-line="28" selection-end-column="25" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/pom.xml">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="660">
<caret line="30" column="21" selection-start-line="30" selection-start-column="21" selection-end-line="30" selection-end-column="21" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/controller/RateLimiterController.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="154">
<caret line="8" selection-start-line="8" selection-end-line="8" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/eekQMainApplication.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="264">
<caret line="13" lean-forward="true" selection-start-line="8" selection-start-column="2" selection-end-line="10" selection-end-column="5" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/rabbitmq/MQReceiver.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="132">
<caret line="32" column="39" selection-start-line="32" selection-start-column="31" selection-end-line="32" selection-end-column="39" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/service/OrderService.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="142">
<caret line="50" selection-start-line="50" selection-end-line="50" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/service/MiaoshaService.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="142">
<caret line="67" column="19" selection-start-line="67" selection-start-column="19" selection-end-line="67" selection-end-column="19" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/access/AccessKey.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="206">
<caret line="11" column="23" selection-start-line="11" selection-start-column="23" selection-end-line="11" selection-end-column="23" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/controller/MiaoshaController.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-130">
<caret line="89" column="13" selection-start-line="84" selection-start-column="4" selection-end-line="89" selection-end-column="13" />
<state relative-caret-position="726">
<caret line="59" column="12" selection-start-line="59" selection-start-column="12" selection-end-line="59" selection-end-column="12" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/domain/MiaoshaUser.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="88">
<caret line="4" column="13" selection-start-line="4" selection-start-column="13" selection-end-line="4" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/access/AccessLimit.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="132">
<caret line="10" column="18" selection-start-line="10" selection-start-column="18" selection-end-line="10" selection-end-column="18" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/access/AccessInterceptor.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="396">
<caret line="33" column="21" selection-start-line="33" selection-start-column="21" selection-end-line="33" selection-end-column="21" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/access/UserContext.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="132">
<caret line="6" column="27" selection-start-line="6" selection-start-column="27" selection-end-line="6" selection-end-column="27" />
<folding>
<element signature="e#244#245#0" expanded="true" />
<element signature="e#271#272#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="jar:///usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar!/java/lang/ThreadLocal.class">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1980">
<caret line="112" column="8" selection-start-line="112" selection-start-column="8" selection-end-line="112" selection-end-column="8" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/config/UserArgumentResolver.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="616">
<caret line="40" column="21" selection-start-line="40" selection-start-column="21" selection-end-line="40" selection-end-column="21" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/config/WebConfig.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="110">
<caret line="10" column="13" selection-start-line="10" selection-start-column="13" selection-end-line="10" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/service/MiaoShaUserService.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="462">
<caret line="35" column="24" selection-start-line="35" selection-start-column="20" selection-end-line="35" selection-end-column="24" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/DemoTask.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="277">
<caret line="32" column="41" selection-start-line="32" selection-start-column="41" selection-end-line="32" selection-end-column="41" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#298#460#0" expanded="true" />
<element signature="e#459#460#0" expanded="true" />
<element signature="e#569#570#0" expanded="true" />
<element signature="e#606#607#0" expanded="true" />
<element signature="e#858#995#0" expanded="true" />
<element signature="e#994#995#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/Test.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="220">
<caret line="10" column="38" lean-forward="true" selection-start-line="10" selection-start-column="38" selection-end-line="10" selection-end-column="38" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/README.md">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="332">
<caret line="18" column="42" selection-start-line="18" selection-start-column="42" selection-end-line="18" selection-end-column="42" />
<state relative-caret-position="337">
<caret line="117" column="27" lean-forward="true" selection-start-line="117" selection-start-column="27" selection-end-line="117" selection-end-column="27" />
</state>
</provider>
</entry>

View File

@ -92,7 +92,33 @@ redis的数量不是库存,他的作用仅仅只是为了阻挡多余的请求
1.具体我会有时间更新关于redis的知识
### <font color=#0099ff size=3 >15.rabbitmq如何做到消息不重复不丢失即使服务器重启</font><br>
1.exchange持久化2.queue持久化3.发送消息设置MessageDeliveryMode.persisent这个也是默认的行为4.手动确认
### <font color=#0099ff size=3 >15.为什么threadlocal存储user对象原理</font><br>
![整体流程](http://i2.bvimg.com/601558/3293e36cc2c7e303.png)
1.并发编程中重要的问题就是数据共享,当你在一个线程中改变任意属性时,所有的线程都会因此受到影响,同时会看到第一个线程修改后的值<br>
有时我们希望如此,比如:多个线程增大或减小同一个计数器变量<br>
但是,有时我们希望确保每个线程,只能工作在它自己的线程实例的拷贝上,同时不会影响其他线程的数据<br>
举例: 举个例子想象你在开发一个电子商务应用你需要为每一个控制器处理的顾客请求生成一个唯一的事务ID同时将其传到管理器或DAO的业务方法中以便记录日志。一种方案是将事务ID作为一个参数传到所有的业务方法中。但这并不是一个好的方案它会使代码变得冗余。
你可以使用ThreadLocal类型的变量解决这个问题。首先在控制器或者任意一个预处理器拦截器中生成一个事务ID
然后在ThreadLocal中 设置事务ID最后不论这个控制器调用什么方法都能从threadlocal中获取事务ID
而且这个应用的控制器可以同时处理多个请求,
同时在框架 层面因为每一个请求都是在一个单独的线程中处理的所以事务ID对于每一个线程都是唯一的而且可以从所有线程的执行路径获取
运行结果可以看出每个线程都在维护自己的变量:
Starting Thread: 0 : Fri Sep 21 23:05:34 CST 2018<br>
Starting Thread: 2 : Fri Sep 21 23:05:34 CST 2018<br>
Starting Thread: 1 : Fri Jan 02 05:36:17 CST 1970<br>
Thread Finished: 1 : Fri Jan 02 05:36:17 CST 1970<br>
Thread Finished: 0 : Fri Sep 21 23:05:34 CST 2018<br>
Thread Finished: 2 : Fri Sep 21 23:05:34 CST 2018<br>
局部线程通常使用在这样的情况下当你有一些对象并不满足线程安全但是你想避免在使用synchronized关键字<br>
块时产生的同步访问,那么,让每个线程拥有它自己的对象实例<br>
注意:局部变量是同步或局部线程的一个好的替代,它总是能够保证线程安全。唯一可能限制你这样做的是你的应用设计约束<br>
所以设计threadlocal存储user不会对对象产生影响每次进来一个请求都会产生自身的线程变量来存储

View File

@ -49,6 +49,7 @@
<orderEntry type="library" name="Maven: org.springframework:spring-context:4.3.12.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-webmvc:4.3.12.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-expression:4.3.12.RELEASE" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:guava:18.0" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-thymeleaf:1.5.8.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.thymeleaf:thymeleaf-spring4:2.1.5.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.thymeleaf:thymeleaf:2.1.5.RELEASE" level="project" />

View File

@ -24,7 +24,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>

View File

@ -0,0 +1,54 @@
package com.geekq.miaosha;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
public class DemoTask implements Runnable
{
// Atomic integer containing the next thread ID to be assigned
private static final AtomicInteger nextId = new AtomicInteger(0);
// Thread local variable containing each thread's ID
private static final ThreadLocal<Integer> threadId = new ThreadLocal<Integer>()
{
@Override
protected Integer initialValue()
{
return nextId.getAndIncrement();
}
};
// Returns the current thread's unique ID, assigning it if necessary
public int getThreadId()
{
return threadId.get();
}
// Returns the current thread's starting timestamp
private static final ThreadLocal<Date> startDate = new ThreadLocal<Date>()
{
protected Date initialValue()
{
if(threadId.get()==1){
return new Date(77777777L);
}
return new Date();
}
};
@Override
public void run()
{
System.out.printf("Starting Thread: %s : %s\n", getThreadId(), startDate.get());
try
{
TimeUnit.SECONDS.sleep((int) Math.rint(Math.random() * 10));
} catch (InterruptedException e)
{
e.printStackTrace();
}
System.out.printf("Thread Finished: %s : %s\n", getThreadId(), startDate.get());
}
}

View File

@ -0,0 +1,15 @@
package com.geekq.miaosha;
public class Test {
public static void main(String[] args) {
DemoTask demoTask = new DemoTask();
DemoTask demoTask1 = new DemoTask();
DemoTask demoTask2 = new DemoTask();
Thread t = new Thread(demoTask);
t.start();
new Thread(demoTask).start();
new Thread(demoTask2).start();
}
}

View File

@ -1,8 +1,8 @@
package com.geekq.miaosha.config;
import com.geekq.miaosha.access.UserContext;
import com.geekq.miaosha.domain.MiaoshaUser;
import com.geekq.miaosha.service.MiaoShaUserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.MethodParameter;
import org.springframework.stereotype.Service;
@ -13,7 +13,6 @@ import org.springframework.web.method.support.ModelAndViewContainer;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Service
public class UserArgumentResolver implements HandlerMethodArgumentResolver {
@ -28,16 +27,18 @@ public class UserArgumentResolver implements HandlerMethodArgumentResolver {
@Override
public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer modelAndViewContainer, NativeWebRequest webRequest, WebDataBinderFactory webDataBinderFactory) throws Exception {
HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class);
HttpServletResponse response = webRequest.getNativeResponse(HttpServletResponse.class);
String paramToken = request.getParameter(MiaoShaUserService.COOKIE_NAME_TOKEN);
String cookieToken = getCookieValue(request, MiaoShaUserService.COOKIE_NAME_TOKEN);
if(StringUtils.isEmpty(cookieToken) && StringUtils.isEmpty(paramToken)) {
return null;
}
String token = StringUtils.isEmpty(paramToken)?cookieToken:paramToken;
return userService.getByToken(response, token);
// HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class);
// HttpServletResponse response = webRequest.getNativeResponse(HttpServletResponse.class);
//
// String paramToken = request.getParameter(MiaoShaUserService.COOKIE_NAME_TOKEN);
// String cookieToken = getCookieValue(request, MiaoShaUserService.COOKIE_NAME_TOKEN);
// if(StringUtils.isEmpty(cookieToken) && StringUtils.isEmpty(paramToken)) {
// return null;
// }
// String token = StringUtils.isEmpty(paramToken)?cookieToken:paramToken;
// return userService.getByToken(response, token);
//threadlocal 存储线程副本 保证线程不冲突
return UserContext.getUser();
}
private String getCookieValue(HttpServletRequest request, String cookiName) {

View File

@ -66,12 +66,22 @@ public class MiaoshaController implements InitializingBean {
return Result.error(CodeMsg.SESSION_ERROR);
}
//验证path
boolean check = miaoshaService.checkPath(user, goodsId, path);
if(!check){
return Result.error(CodeMsg.REQUEST_ILLEGAL);
}
// //使用RateLimiter 限流
// RateLimiter rateLimiter = RateLimiter.create(10);
// //判断能否在1秒内得到令牌如果不能则立即返回false不会阻塞程序
// if (!rateLimiter.tryAcquire(1000, TimeUnit.MILLISECONDS)) {
// System.out.println("短期无法获取令牌,真不幸,排队也瞎排");
// return Result.error(CodeMsg.MIAOSHA_FAIL);
//
// }
//是否已经秒杀到
MiaoshaOrder order = orderService.getMiaoshaOrderByUserIdGoodsId(user.getId(), goodsId);
if(order!=null){

View File

@ -0,0 +1,10 @@
package com.geekq.miaosha.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/ratelimiter")
public class RateLimiterController {
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.