<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="text">linzhi's Site</title>
  <id>http://linzhiteng.postach.io/feed.xml</id>
  <updated>2020-02-03T03:14:19.195000Z</updated>
  <link href="http://linzhiteng.postach.io/" />
  <link href="http://linzhiteng.postach.io/feed.xml" rel="self" />
  <generator>Werkzeug</generator>
  <entry xml:base="http://linzhiteng.postach.io/feed.xml">
    <title type="text">工作总结</title>
    <id>https://linzhiteng.postach.io/post/gong-zuo-zong-jie</id>
    <updated>2020-02-03T03:14:19.195000Z</updated>
    <published>2019-12-03T07:28:12Z</published>
    <link href="https://linzhiteng.postach.io/post/gong-zuo-zong-jie" />
    <author>
      <name>linzhi teng</name>
    </author>
    <category term="gong-zuo" />
    <content type="html">&lt;div&gt;&lt;div style=&quot;font-size: 14px; margin: 0; padding: 0; width: 100%;&quot;&gt;&lt;div style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;工作总结
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;TODO
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;spring拦截器 过滤器
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;线程+线程池
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;文件系统
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;消息队列mq
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;activi 流程
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;maven
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;settings.xml
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;日志写法
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;工具类
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;业务写法
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1. controller
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2. swagger注解：
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;打包
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1. jar包：
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2. war包：
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3. assembly插件
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;分页
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;mybatis
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;response/request
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h1 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 41px; border-bottom: 3px double #999; color: #000; margin-top: 14px;&quot;&gt;工作总结&lt;/h1&gt;
&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;TODO&lt;/h2&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;spring拦截器 过滤器&lt;/h4&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;线程+线程池&lt;/h4&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;文件系统&lt;/h4&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;消息队列mq&lt;/h4&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;activi 流程&lt;/h4&gt;
&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;maven&lt;/h2&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;加入本地jar包&lt;br/&gt;
mvn install:install-file -DgroupId=cn.com.citycloud -DartifactId=authorization -Dversion=1.0 -Dpackaging=jar -Dfile=authorization.jar完整路径&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;mvn install:install-file -DgroupId=com.citycloud.qcloud -DartifactId=qcloud-oauth2-client -Dversion=2.2.0 -Dpackaging=jar -Dfile=qcloud-oauth2-resource-2.2.0.RELEASE.jar&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ol start=&quot;2&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;本地的包放在本地文件夹，加入pom文件&lt;/li&gt;
&lt;/ol&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;scope&lt;/span&gt;&gt;&lt;/span&gt;system&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;scope&lt;/span&gt;&gt;&lt;/span&gt;
&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;systemPath&lt;/span&gt;&gt;&lt;/span&gt;${project.basedir}/lib/xxx.jar&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;systemPath&lt;/span&gt;&gt;&lt;/span&gt;

## 这种方式引入的jar包在打包时不会被包含在war包中
&lt;/code&gt;&lt;/pre&gt;
&lt;ol start=&quot;3&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;pom&lt;/li&gt;
&lt;/ol&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;
&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;groupId&lt;/span&gt;&gt;&lt;/span&gt;xxx&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;groupId&lt;/span&gt;&gt;&lt;/span&gt; 通常使用全限定的包名区分该项目和其他项目。
&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;artifactId&lt;/span&gt;&gt;&lt;/span&gt;xxx&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;artifactId&lt;/span&gt;&gt;&lt;/span&gt; 通常和项目名称保持统一
&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;packaging&lt;/span&gt;&gt;&lt;/span&gt; jar &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;packaging&lt;/span&gt;&gt;&lt;/span&gt;

&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;repositories&lt;/span&gt;&gt;&lt;/span&gt; 发现依赖和扩展的远程仓库列表
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;repository&lt;/span&gt;&gt;&lt;/span&gt;
        &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;id&lt;/span&gt;&gt;&lt;/span&gt;alimaven&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;id&lt;/span&gt;&gt;&lt;/span&gt;
        &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;name&lt;/span&gt;&gt;&lt;/span&gt;aliyun maven&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;name&lt;/span&gt;&gt;&lt;/span&gt;       
        &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;url&lt;/span&gt;&gt;&lt;/span&gt;http://maven.aliyun.com/nexus/content/groups/public/&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;url&lt;/span&gt;&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;repository&lt;/span&gt;&gt;&lt;/span&gt;
&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;repositories&lt;/span&gt;&gt;&lt;/span&gt;

&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;dependencies&lt;/span&gt;&gt;&lt;/span&gt;
&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;!--compile 默认就是compile,依赖项目需要参与当前项目的编译，后续的测试，运行test 依赖项目仅仅参与测试相关的工作，包括测试代码的编译，执行provided 打包的时候可以不用包进去system 被依赖项不会从maven仓库抓，而是从本地文件系统拿，一定需要配合systemPath属性使用--&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;scope&lt;/span&gt;&gt;&lt;/span&gt;test&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;scope&lt;/span&gt;&gt;&lt;/span&gt;
    从依赖构件列表里，列出被排除的依赖构件集,此元素主要用于解决版本冲突问题       
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;exclusions&lt;/span&gt;&gt;&lt;/span&gt;
        &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;exclusion&lt;/span&gt;&gt;&lt;/span&gt;
            &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;artifactId&lt;/span&gt;&gt;&lt;/span&gt;spring-core&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;artifactId&lt;/span&gt;&gt;&lt;/span&gt;
            &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;groupId&lt;/span&gt;&gt;&lt;/span&gt;org.springframework&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;groupId&lt;/span&gt;&gt;&lt;/span&gt;
        &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;exclusion&lt;/span&gt;&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;exclusions&lt;/span&gt;&gt;&lt;/span&gt;
&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;dependencies&lt;/span&gt;/&gt;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;settings.xml&lt;/h4&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;MIrrors&lt;/li&gt;
&lt;/ol&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;使用镜像的一些原因：互联网上有一个同步镜像，地理位置更近，速度更快&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;您希望将特定存储库替换为您可以更好地控制的内部存储库&lt;/li&gt;
&lt;/ul&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;
&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;mirrors&lt;/span&gt;&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;mirror&lt;/span&gt;&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;!--id，name：id必须唯一(不要与仓库id一样)，name随意--&gt;&lt;/span&gt;
      &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;id&lt;/span&gt;&gt;&lt;/span&gt;planetmirror.com&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;id&lt;/span&gt;&gt;&lt;/span&gt;
      &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;name&lt;/span&gt;&gt;&lt;/span&gt;PlanetMirror Australia&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;name&lt;/span&gt;&gt;&lt;/span&gt;
      &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;!--url：镜像的地址--&gt;&lt;/span&gt;
      &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;url&lt;/span&gt;&gt;&lt;/span&gt;http://downloads.planetmirror.com/pub/maven2&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;url&lt;/span&gt;&gt;&lt;/span&gt;
      &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;!--mirrorOf：需要被镜像的仓库id。例如，要指向Maven中央存储库（https://repo.maven.apache.org/maven2/）的镜像，请将此元素设置为central--&gt;&lt;/span&gt;
      &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;mirrorOf&lt;/span&gt;&gt;&lt;/span&gt;central&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;mirrorOf&lt;/span&gt;&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;mirror&lt;/span&gt;&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;mirrors&lt;/span&gt;&gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;
&lt;ol start=&quot;2&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;Profiles&lt;br/&gt;
settings.xml中的profile元素是pom.xml profile元素的精简版本。&lt;br/&gt;
它由activation，repositories，pluginRepositories和properties元素组成.&lt;br/&gt;
&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;如果profile在settings.xml中被激活，则其值将覆盖POM或profiles.xml文件中任何等效的ID配置。&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt; &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;profile&lt;/span&gt;&gt;&lt;/span&gt;  
     &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;id&lt;/span&gt;&gt;&lt;/span&gt;downloadSources&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;id&lt;/span&gt;&gt;&lt;/span&gt;  
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;properties&lt;/span&gt;&gt;&lt;/span&gt;  
      &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;downloadSources&lt;/span&gt;&gt;&lt;/span&gt;true&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;downloadSources&lt;/span&gt;&gt;&lt;/span&gt;  
      &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;downloadJavadocs&lt;/span&gt;&gt;&lt;/span&gt;true&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;downloadJavadocs&lt;/span&gt;&gt;&lt;/span&gt;             
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;properties&lt;/span&gt;&gt;&lt;/span&gt;  
  &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;profile&lt;/span&gt;&gt;&lt;/span&gt;  

&lt;/code&gt;&lt;/pre&gt;
&lt;ol start=&quot;3&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;Repositories&lt;br/&gt;
Repositories是Maven用于填充构建系统的本地存储库的项目的远程集合。它来自这个本地存储库，Maven称之为插件和依赖项。不同的远程存储库可能包含不同的项目，并且在启用的profile下，可以搜索它们以查找匹配的版本或快照工件。&lt;/p&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;Plugin Repositories&lt;br/&gt;
pluginRepositories元素块的结构类似于repositories元素。 pluginRepository元素指定Maven可以在哪里找到新插件的远程位置。&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;profile&lt;/span&gt;&gt;&lt;/span&gt;  
      &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;id&lt;/span&gt;&gt;&lt;/span&gt;nexus_150&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;id&lt;/span&gt;&gt;&lt;/span&gt;  
      &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;repositories&lt;/span&gt;&gt;&lt;/span&gt;  
        &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;repository&lt;/span&gt;&gt;&lt;/span&gt;	
          &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;id&lt;/span&gt;&gt;&lt;/span&gt;maven-releases&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;id&lt;/span&gt;&gt;&lt;/span&gt;  
          &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;name&lt;/span&gt;&gt;&lt;/span&gt;local private nexus&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;name&lt;/span&gt;&gt;&lt;/span&gt;  
          &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;url&lt;/span&gt;&gt;&lt;/span&gt;http://115.231.97.150/nexus/repository/releases/&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;url&lt;/span&gt;&gt;&lt;/span&gt;  
          &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;releases&lt;/span&gt;&gt;&lt;/span&gt;  
            &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;enabled&lt;/span&gt;&gt;&lt;/span&gt;true&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;enabled&lt;/span&gt;&gt;&lt;/span&gt;  
          &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;releases&lt;/span&gt;&gt;&lt;/span&gt;  
          &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;snapshots&lt;/span&gt;&gt;&lt;/span&gt;  
            &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;enabled&lt;/span&gt;&gt;&lt;/span&gt;false&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;enabled&lt;/span&gt;&gt;&lt;/span&gt;  
          &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;snapshots&lt;/span&gt;&gt;&lt;/span&gt;  
        &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;repository&lt;/span&gt;&gt;&lt;/span&gt;  
        &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;repository&lt;/span&gt;&gt;&lt;/span&gt;  
          &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;id&lt;/span&gt;&gt;&lt;/span&gt;maven-snapshots&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;id&lt;/span&gt;&gt;&lt;/span&gt;  
          &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;name&lt;/span&gt;&gt;&lt;/span&gt;local private nexus&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;name&lt;/span&gt;&gt;&lt;/span&gt;  
          &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;url&lt;/span&gt;&gt;&lt;/span&gt;http://115.231.97.150/nexus/repository/maven-snapshots/&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;url&lt;/span&gt;&gt;&lt;/span&gt;  
          &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;releases&lt;/span&gt;&gt;&lt;/span&gt;  
            &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;enabled&lt;/span&gt;&gt;&lt;/span&gt;false&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;enabled&lt;/span&gt;&gt;&lt;/span&gt;  
          &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;releases&lt;/span&gt;&gt;&lt;/span&gt;  
          &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;snapshots&lt;/span&gt;&gt;&lt;/span&gt;  
            &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;enabled&lt;/span&gt;&gt;&lt;/span&gt;true&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;enabled&lt;/span&gt;&gt;&lt;/span&gt;  
          &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;snapshots&lt;/span&gt;&gt;&lt;/span&gt;  
        &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;repository&lt;/span&gt;&gt;&lt;/span&gt;

&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;!--
  qcloud-oauth2-client-1.1.0

--&gt;&lt;/span&gt;
&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;!--		&lt;repository&gt;
         &lt;id&gt;cci-snapshots&lt;/id&gt;
         &lt;url&gt;http://10.10.81.107:8080/nexus/content/repositories/snapshots/&lt;/url&gt;
        &lt;/repository&gt;
        &lt;repository&gt;
         &lt;id&gt;cci-releases&lt;/id&gt;
         &lt;url&gt;http://10.10.81.107:8080/nexus/content/groups/public/&lt;/url&gt;
        &lt;/repository&gt;--&gt;&lt;/span&gt;
      &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;repositories&lt;/span&gt;&gt;&lt;/span&gt;  
      
      &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;pluginRepositories&lt;/span&gt;&gt;&lt;/span&gt;  
        &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;pluginRepository&lt;/span&gt;&gt;&lt;/span&gt;  
          &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;id&lt;/span&gt;&gt;&lt;/span&gt;maven-releases&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;id&lt;/span&gt;&gt;&lt;/span&gt;  
          &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;name&lt;/span&gt;&gt;&lt;/span&gt;local private nexus&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;name&lt;/span&gt;&gt;&lt;/span&gt;  
          &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;url&lt;/span&gt;&gt;&lt;/span&gt;http://115.231.97.150/nexus/repository/releases/&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;url&lt;/span&gt;&gt;&lt;/span&gt;  
          &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;releases&lt;/span&gt;&gt;&lt;/span&gt;  
            &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;enabled&lt;/span&gt;&gt;&lt;/span&gt;true&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;enabled&lt;/span&gt;&gt;&lt;/span&gt;  
          &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;releases&lt;/span&gt;&gt;&lt;/span&gt;  
          &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;snapshots&lt;/span&gt;&gt;&lt;/span&gt;  
            &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;enabled&lt;/span&gt;&gt;&lt;/span&gt;false&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;enabled&lt;/span&gt;&gt;&lt;/span&gt;  
          &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;snapshots&lt;/span&gt;&gt;&lt;/span&gt;  
        &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;pluginRepository&lt;/span&gt;&gt;&lt;/span&gt;  
        &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;pluginRepository&lt;/span&gt;&gt;&lt;/span&gt;  
          &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;id&lt;/span&gt;&gt;&lt;/span&gt;maven-snapshots&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;id&lt;/span&gt;&gt;&lt;/span&gt;  
          &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;name&lt;/span&gt;&gt;&lt;/span&gt;local private nexus&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;name&lt;/span&gt;&gt;&lt;/span&gt;  
          &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;url&lt;/span&gt;&gt;&lt;/span&gt;http://115.231.97.150/nexus/repository/maven-snapshots/&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;url&lt;/span&gt;&gt;&lt;/span&gt;  
          &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;releases&lt;/span&gt;&gt;&lt;/span&gt;  
            &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;enabled&lt;/span&gt;&gt;&lt;/span&gt;false&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;enabled&lt;/span&gt;&gt;&lt;/span&gt;  
          &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;releases&lt;/span&gt;&gt;&lt;/span&gt;  
          &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;snapshots&lt;/span&gt;&gt;&lt;/span&gt;  
            &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;enabled&lt;/span&gt;&gt;&lt;/span&gt;true&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;enabled&lt;/span&gt;&gt;&lt;/span&gt;  
          &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;snapshots&lt;/span&gt;&gt;&lt;/span&gt;  
        &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;pluginRepository&lt;/span&gt;&gt;&lt;/span&gt;  
      &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;pluginRepositories&lt;/span&gt;&gt;&lt;/span&gt; 
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;profile&lt;/span&gt;&gt;&lt;/span&gt;  
&lt;/code&gt;&lt;/pre&gt;
&lt;ol start=&quot;5&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;启用Profiles&lt;/li&gt;
&lt;/ol&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;  &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;activeProfiles&lt;/span&gt;&gt;&lt;/span&gt;  
  &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;activeProfile&lt;/span&gt;&gt;&lt;/span&gt;nexus_150&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;activeProfile&lt;/span&gt;&gt;&lt;/span&gt;
      &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;!--    &lt;activeProfile&gt;downloadSources&lt;/activeProfile&gt;  
        &lt;activeProfile&gt;public-snapshots&lt;/activeProfile&gt;   --&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;activeProfiles&lt;/span&gt;&gt;&lt;/span&gt; 

&lt;/code&gt;&lt;/pre&gt;
&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;日志写法&lt;/h2&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;使用alibab Java Coding Guidelinec插件规范代码&lt;/p&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;什么时候写？&lt;br/&gt;
--- 方法入口处(info)&lt;br/&gt;
---方法退出前(debug,info)&lt;br/&gt;
----流程分支(info,warn)&lt;br/&gt;
----异常分支(error)&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;写的内容&lt;br/&gt;
---入参(必选)&lt;br/&gt;
---方法调用(可选) debug&lt;br/&gt;
---返回值（可选）&lt;br/&gt;
---中间变量(可选)&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;写的时候在日志中加入可以查询的条件，以便分辨搜索，如&lt;/li&gt;
&lt;/ol&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;log.warn(&quot;[系统名 模块名] xxxxxx&quot;);
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;工具类&lt;/h2&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;所有的变量和方法都是static&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;如果需要用到其他的service，通过spring容器去取&lt;/li&gt;
&lt;/ol&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//需要强转类型&lt;/span&gt;
(xxxService)SpringContextUtils.getBean(&lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;xxxService&quot;&lt;/span&gt;); 
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;业务写法&lt;/h2&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1. controller&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;接受多个对象时，必须把多个对象封装成一个VO类来接受&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2. swagger注解：&lt;/h4&gt;
&lt;table style=&quot;margin: 2px 0 14px; color: #333; width: auto; border-collapse: collapse; box-sizing: border-box;&quot;&gt;&lt;thead style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;作用范围&lt;/th&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;API&lt;/th&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;使用位置&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;对象属性&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;@ApiModelProperty&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;用在出入参数对象的字段上&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;协议集描述&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;@Api&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;用于controller类上&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;协议描述&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;@ApiOperation&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;用在controller的方法上&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;Response集&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;@ApiResponses&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;用在controller的方法上&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;Response&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;@ApiResponse&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;用在 @ApiResponses里边&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;非对象参数集&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;@ApiImplicitParams&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;用在controller的方法上&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;非对象参数描述&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;@ApiImplicitParam&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;用在@ApiImplicitParams的方法里边&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;描述返回对象的意义&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;@ApiModel&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;用在返回对象类上&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;hr style=&quot;line-height: 160%; box-sizing: content-box; border-top: 1px solid #eee; margin: 16px 0;&quot;/&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;@ApiImplicitParam&lt;/p&gt;
&lt;table style=&quot;margin: 2px 0 14px; color: #333; width: auto; border-collapse: collapse; box-sizing: border-box;&quot;&gt;&lt;thead style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;属性&lt;/th&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;取值&lt;/th&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;作用&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;paramType&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;查询参数类型&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;path&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;以地址的形式提交数据&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;query&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;直接跟参数完成自动映射赋值&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;body&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;以流的形式提交 仅支持POST&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;header&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;参数在request headers 里边提交&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;form&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;以form表单的形式提交 仅支持POST&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;dataType&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;参数的数据类型&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;只作为标志说明，并没有实际验证&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;Long&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;String&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;name&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;接收参数名&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;value&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;接收参数的意义描述&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;required&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;参数是否必填&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;true&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;必填&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;false&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;非必填&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;defaultValue&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;默认值&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;
&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;@ApiImplicitParams&lt;/span&gt;({ &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;@ApiImplicitParam&lt;/span&gt;(paramType = &lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;body&quot;&lt;/span&gt;, dataType = &lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;MessageParam&quot;&lt;/span&gt;, 
name = &lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;param&quot;&lt;/span&gt;, value = &lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;信息参数&quot;&lt;/span&gt;, required = &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;true&lt;/span&gt;) })

&lt;/code&gt;&lt;/pre&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;在controller类上&lt;br/&gt;
@Api(value=&quot;用户controller&quot;,tags={&quot;用户操作接口&quot;})&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;在controller方法上&lt;br/&gt;
@ApiOperation(value=&quot;获取用户信息&quot;,tags={&quot;获取用户信息copy&quot;})&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;在实体类上&lt;br/&gt;
@ApiModel(value=&quot;user对象&quot;,description=&quot;用户对象user&quot;)&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;在实体方法上&lt;br/&gt;
@ApiModelProperty(value=&quot;用户名&quot;,name=&quot;username&quot;)&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;swagger依赖：&lt;/p&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;dependency&lt;/span&gt;&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;groupId&lt;/span&gt;&gt;&lt;/span&gt;io.springfox&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;groupId&lt;/span&gt;&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;artifactId&lt;/span&gt;&gt;&lt;/span&gt;springfox-swagger2&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;artifactId&lt;/span&gt;&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;version&lt;/span&gt;&gt;&lt;/span&gt;${springfox-swagger2.version}&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;version&lt;/span&gt;&gt;&lt;/span&gt;
&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;dependency&lt;/span&gt;&gt;&lt;/span&gt;
&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;dependency&lt;/span&gt;&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;groupId&lt;/span&gt;&gt;&lt;/span&gt;io.springfox&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;groupId&lt;/span&gt;&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;artifactId&lt;/span&gt;&gt;&lt;/span&gt;springfox-swagger-ui&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;artifactId&lt;/span&gt;&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;version&lt;/span&gt;&gt;&lt;/span&gt;${springfox-swagger-ui.version}&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;version&lt;/span&gt;&gt;&lt;/span&gt;
&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;dependency&lt;/span&gt;&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;hr style=&quot;line-height: 160%; box-sizing: content-box; border-top: 1px solid #eee; margin: 16px 0;&quot;/&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;Do类继承Model,不写其他通用的属性，注释属性中文注释lombak，主键注解@Id&lt;/p&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;Dto类继承BaseDto，可以写入其他的Do类作为属性(有其他属性，需注解lombak)&lt;/p&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;Vo类，在controller里作为参数使用注解@ApiModel，@ApiModelProperty，注解lombak&lt;/p&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;mapper接口，方法参数使用Do类，参数名为record，注解@Mapper&lt;/p&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;Service 接受参数为Dto,传给mapper的参数为Dto.getRecord(),返回类型为SWrapper&lt;/p&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;controller extends BaseController方法接受参数Vo，传给service的为Dto,需要把Vo转成Dto通过toDto(Vo,OperateType)方法 返回类型RWrapper&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;打包&lt;/h2&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1. jar包：&lt;/h4&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;build&lt;/span&gt;&gt;&lt;/span&gt;
&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;!-- 打成war不需要这个maven插件，如果打成jar则是必须的 --&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;plugins&lt;/span&gt;&gt;&lt;/span&gt;
        &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;plugin&lt;/span&gt;&gt;&lt;/span&gt;
            &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;groupId&lt;/span&gt;&gt;&lt;/span&gt;org.springframework.boot&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;groupId&lt;/span&gt;&gt;&lt;/span&gt;
            &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;artifactId&lt;/span&gt;&gt;&lt;/span&gt;spring-boot-maven-plugin&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;artifactId&lt;/span&gt;&gt;&lt;/span&gt;
        &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;plugin&lt;/span&gt;&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;plugins&lt;/span&gt;&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;finalName&lt;/span&gt;&gt;&lt;/span&gt;springbootdemo&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;finalName&lt;/span&gt;&gt;&lt;/span&gt;
&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;build&lt;/span&gt;&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;spring-boot 默认提供内嵌的tomcat，所以打包直接生成jar 包，用java -jar 命令就可以启动。&lt;br/&gt;
//nohup 意思是不挂断运行命令,当账户退出或终端关闭时,程序仍然运行&lt;br/&gt;
//当用 nohup 命令执行作业时，缺省情况下该作业的所有输出被重定向到nohup.out的文件中&lt;br/&gt;
&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;nohup java -jar test.jar &gt;temp.txt &amp;&lt;/code&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;Spring程序会按优先级从下面这些路径来加载application.properties配置文件&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;当前目录下的/config目录&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;当前目录&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;classpath里的/config目录&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;classpath 跟目录&lt;/li&gt;
&lt;/ul&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;nohup java -jar -Dspring.config.location=D:\config\config.properties xxx.jar&gt; /xx/nohup.out 2&gt;&amp;1 &amp;&lt;/code&gt;&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2. war包：&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;有时候我们更希望一个tomcat 来管理多个项目，这种情况下就需要项目是war 格式的。&lt;/p&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;dependency&lt;/span&gt;&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;groupId&lt;/span&gt;&gt;&lt;/span&gt;org.springframework.boot&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;groupId&lt;/span&gt;&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;artifactId&lt;/span&gt;&gt;&lt;/span&gt;spring-boot-starter-tomcat&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;artifactId&lt;/span&gt;&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;scope&lt;/span&gt;&gt;&lt;/span&gt;provided&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;scope&lt;/span&gt;&gt;&lt;/span&gt;
&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;dependency&lt;/span&gt;&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;spring-boot-starter-tomcat 是原来被传递过来的依赖，默认会打到包里，所以我们再次引入此依赖，并指定依赖范围为provided，这样tomcat 相关的jar就不会打包到war 里了&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;添加ServletInitializer将项目打成war包，部署到外部的tomcat中，这个时候，不能直接访问spring boot 项目中配置文件配置的端口。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;application.yml中配置的server.port配置的是spring boot内置的tomcat的端口号, &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;打成war包部署在独立的tomcat上之后, 你配置的server.port是不起作用的&lt;/strong&gt;。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3. assembly插件&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;为什么需要Assembly插件呢？因为对于&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;服务类型的后台程序&lt;/strong&gt;，线上运行时一般通过脚本的方式启动和停止，而项目中的目录结构复杂且不够直观，且&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;项目文件也需要合并和过滤&lt;/strong&gt;，Assembly插件就可以帮助我们完成。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;比如现在我们的项目目录如下：&lt;/p&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;+ src 
    + main 
        + java 
        + resources 
            + jdbc.properties 
        + bin 
            + start.sh 
            + stop.sh 
        + assembly 
            + assembly.xml
&lt;/code&gt;&lt;/pre&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;最终想要的目录：&lt;/p&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;+ bin 
    start.sh 
    stop.sh 
+ conf
    jdbc.properties 
+ lib(依赖jar包目录) 
    xxx.jar
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;分页&lt;/h2&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;依赖&lt;/li&gt;
&lt;/ol&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;dependency&lt;/span&gt;&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;groupId&lt;/span&gt;&gt;&lt;/span&gt;org.springframework.data&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;groupId&lt;/span&gt;&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;artifactId&lt;/span&gt;&gt;&lt;/span&gt;spring-data-commons&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;artifactId&lt;/span&gt;&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;version&lt;/span&gt;&gt;&lt;/span&gt;2.1.8.RELEASE&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;version&lt;/span&gt;&gt;&lt;/span&gt;
&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;dependency&lt;/span&gt;&gt;&lt;/span&gt;
&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;dependency&lt;/span&gt;&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;groupId&lt;/span&gt;&gt;&lt;/span&gt;com.github.pagehelper&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;groupId&lt;/span&gt;&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;artifactId&lt;/span&gt;&gt;&lt;/span&gt;pagehelper-spring-boot-starter&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;artifactId&lt;/span&gt;&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;version&lt;/span&gt;&gt;&lt;/span&gt;1.2.12&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;version&lt;/span&gt;&gt;&lt;/span&gt;
&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;dependency&lt;/span&gt;&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;2.分页封装工具类&lt;/p&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;PageInfoAdapter&lt;/span&gt;&lt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;T&lt;/span&gt;&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;extends&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;PageImpl&lt;/span&gt;&lt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;T&lt;/span&gt;&gt; &lt;/span&gt;{
&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;PageInfoAdapter&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(Page&lt;T&gt; page)&lt;/span&gt; &lt;/span&gt;{
&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;super&lt;/span&gt;(page.getResult(), PageRequest.of(page.getPageNum() - &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1&lt;/span&gt;, page.getPageSize()), page.getTotal());
}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;ol start=&quot;3&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;controller&lt;/li&gt;
&lt;/ol&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; RWrapper &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;listTaskPlan&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(Pageable pageable,TaskPlan taskPlan)&lt;/span&gt;
&lt;/span&gt;{
&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; RWrapper(taskPlanService.listTaskPlan(pageable,taskPlan));
}
&lt;/code&gt;&lt;/pre&gt;
&lt;ol start=&quot;4&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;servicepublic&lt;/li&gt;
&lt;/ol&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;Page&lt;Map&lt;String, Object&gt;&gt; listTaskPlan(Pageable pageable, TaskPlan taskPlan) 
{
    com.github.pagehelper.Page&lt;Map&lt;String, Object&gt;&gt; pageInfo =  PageHelper.startPage(pageable.getPageNumber(),pageable.getPageSize())
.doSelectPage(() -&gt;  taskPlanQueryMapper.listTaskPlan(taskPlan));
    &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; PageInfoAdapter(pageInfo);
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;mybatis&lt;/h2&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;mybatis逆向工程&lt;br/&gt;
generatorConfig.xml文件需要加上不生成注释&lt;br/&gt;
自定义的生成文件依赖&lt;/li&gt;
&lt;/ol&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;plugin&lt;/span&gt;&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;groupId&lt;/span&gt;&gt;&lt;/span&gt;org.mybatis.generator&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;groupId&lt;/span&gt;&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;artifactId&lt;/span&gt;&gt;&lt;/span&gt;mybatis-generator-maven-plugin&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;artifactId&lt;/span&gt;&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;version&lt;/span&gt;&gt;&lt;/span&gt;1.3.5&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;version&lt;/span&gt;&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;configuration&lt;/span&gt;&gt;&lt;/span&gt;     
  &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;configurationFile&lt;/span&gt;&gt;&lt;/span&gt;src/main/resources/mybatis/generatorConfig.xml
  &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;configurationFile&lt;/span&gt;&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;verbose&lt;/span&gt;&gt;&lt;/span&gt;true&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;verbose&lt;/span&gt;&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;overwrite&lt;/span&gt;&gt;&lt;/span&gt;true&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;overwrite&lt;/span&gt;&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;configuration&lt;/span&gt;&gt;&lt;/span&gt;
&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;plugin&lt;/span&gt;&gt;&lt;/span&gt;

&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;dependency&lt;/span&gt;&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;groupId&lt;/span&gt;&gt;&lt;/span&gt;org.mybatis.generator&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;groupId&lt;/span&gt;&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;artifactId&lt;/span&gt;&gt;&lt;/span&gt;mybatis-generator-core&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;artifactId&lt;/span&gt;&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;version&lt;/span&gt;&gt;&lt;/span&gt;1.3.5&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;version&lt;/span&gt;&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;scope&lt;/span&gt;&gt;&lt;/span&gt;provided&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;scope&lt;/span&gt;&gt;&lt;/span&gt;
&lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;dependency&lt;/span&gt;&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;response/request&lt;/h2&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;给前端返回json格式数据&lt;/li&gt;
&lt;/ol&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;String json = JsonUtil.bean2Json(object);

response.setCharacterEncoding(&lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;utf-8&quot;&lt;/span&gt;);

response.setContentType(&lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;application/json; charset=utf-8&quot;&lt;/span&gt;);

PrintWriter writer = response.getWriter();

writer.write(json);

&lt;/code&gt;&lt;/pre&gt;
&lt;ol start=&quot;2&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;取得request请求地址&lt;/li&gt;
&lt;/ol&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;referUri = request.getScheme() + &lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;://&quot;&lt;/span&gt; + request.getServerName() 
+ &lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;:&quot;&lt;/span&gt; + request.getServerPort() + request.getServletPath();

&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;if&lt;/span&gt; (request.getQueryString() != &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;null&lt;/span&gt;) 
{  
    referUri += &lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;?&quot;&lt;/span&gt; + request.getQueryString();
}
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;center style='display:none !important;visibility:collapse !important;height:0 !important;white-space:nowrap;width:100%;overflow:hidden'&gt;%5Btoc%5D%0A%23%20%E5%B7%A5%E4%BD%9C%E6%80%BB%E7%BB%93%0A%0A%23%23%20TODO%0A%23%23%23%23%20spring%E6%8B%A6%E6%88%AA%E5%99%A8%20%E8%BF%87%E6%BB%A4%E5%99%A8%0A%23%23%23%23%20%20%E7%BA%BF%E7%A8%8B%2B%E7%BA%BF%E7%A8%8B%E6%B1%A0%0A%23%23%23%23%20%E6%96%87%E4%BB%B6%E7%B3%BB%E7%BB%9F%0A%23%23%23%23%20%E6%B6%88%E6%81%AF%E9%98%9F%E5%88%97mq%0A%23%23%23%23%20activi%20%E6%B5%81%E7%A8%8B%0A%0A%0A%0A%0A%23%23%20maven%0A%0A1.%20%E5%8A%A0%E5%85%A5%E6%9C%AC%E5%9C%B0jar%E5%8C%85%0Amvn%20install%3Ainstall-file%20-DgroupId%3Dcn.com.citycloud%20-DartifactId%3Dauthorization%20-Dversion%3D1.0%20-Dpackaging%3Djar%20-Dfile%3Dauthorization.jar%E5%AE%8C%E6%95%B4%E8%B7%AF%E5%BE%84%0A%3Emvn%20install%3Ainstall-file%20-DgroupId%3Dcom.citycloud.qcloud%20-DartifactId%3Dqcloud-oauth2-client%20-Dversion%3D2.2.0%20-Dpackaging%3Djar%20-Dfile%3Dqcloud-oauth2-resource-2.2.0.RELEASE.jar%0A2.%20%E6%9C%AC%E5%9C%B0%E7%9A%84%E5%8C%85%E6%94%BE%E5%9C%A8%E6%9C%AC%E5%9C%B0%E6%96%87%E4%BB%B6%E5%A4%B9%EF%BC%8C%E5%8A%A0%E5%85%A5pom%E6%96%87%E4%BB%B6%0A%60%60%60xml%0A%3Cscope%3Esystem%3C%2Fscope%3E%0A%3CsystemPath%3E%24%7Bproject.basedir%7D%2Flib%2Fxxx.jar%3C%2FsystemPath%3E%0A%0A%23%23%20%E8%BF%99%E7%A7%8D%E6%96%B9%E5%BC%8F%E5%BC%95%E5%85%A5%E7%9A%84jar%E5%8C%85%E5%9C%A8%E6%89%93%E5%8C%85%E6%97%B6%E4%B8%8D%E4%BC%9A%E8%A2%AB%E5%8C%85%E5%90%AB%E5%9C%A8war%E5%8C%85%E4%B8%AD%0A%60%60%60%0A3.%20pom%0A%60%60%60xml%0A%0A%3CgroupId%3Exxx%3C%2FgroupId%3E%20%E9%80%9A%E5%B8%B8%E4%BD%BF%E7%94%A8%E5%85%A8%E9%99%90%E5%AE%9A%E7%9A%84%E5%8C%85%E5%90%8D%E5%8C%BA%E5%88%86%E8%AF%A5%E9%A1%B9%E7%9B%AE%E5%92%8C%E5%85%B6%E4%BB%96%E9%A1%B9%E7%9B%AE%E3%80%82%0A%3CartifactId%3Exxx%3C%2FartifactId%3E%20%E9%80%9A%E5%B8%B8%E5%92%8C%E9%A1%B9%E7%9B%AE%E5%90%8D%E7%A7%B0%E4%BF%9D%E6%8C%81%E7%BB%9F%E4%B8%80%0A%3Cpackaging%3E%20jar%20%3C%2Fpackaging%3E%0A%0A%3Crepositories%3E%20%E5%8F%91%E7%8E%B0%E4%BE%9D%E8%B5%96%E5%92%8C%E6%89%A9%E5%B1%95%E7%9A%84%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93%E5%88%97%E8%A1%A8%0A%20%20%20%20%3Crepository%3E%0A%20%20%20%20%20%20%20%20%3Cid%3Ealimaven%3C%2Fid%3E%0A%20%20%20%20%20%20%20%20%3Cname%3Ealiyun%20maven%3C%2Fname%3E%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%3Curl%3Ehttp%3A%2F%2Fmaven.aliyun.com%2Fnexus%2Fcontent%2Fgroups%2Fpublic%2F%3C%2Furl%3E%0A%20%20%20%20%3C%2Frepository%3E%0A%3C%2Frepositories%3E%0A%0A%3Cdependencies%3E%0A%3C!--compile%20%E9%BB%98%E8%AE%A4%E5%B0%B1%E6%98%AFcompile%2C%E4%BE%9D%E8%B5%96%E9%A1%B9%E7%9B%AE%E9%9C%80%E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%E7%B4%A0%E4%B8%BB%E8%A6%81%E7%94%A8%E4%BA%8E%E8%A7%A3%E5%86%B3%E7%89%88%E6%9C%AC%E5%86%B2%E7%AA%81%E9%97%AE%E9%A2%98%20%20%20%20%20%20%20%0A%20%20%20%20%3Cexclusions%3E%0A%20%20%20%20%20%20%20%20%3Cexclusion%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3CartifactId%3Espring-core%3C%2FartifactId%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3CgroupId%3Eorg.springframework%3C%2FgroupId%3E%0A%20%20%20%20%20%20%20%20%3C%2Fexclusion%3E%0A%20%20%20%20%3C%2Fexclusions%3E%0A%3Cdependencies%2F%3E%0A%0A%60%60%60%0A%0A%23%23%23%23%20settings.xml%0A%0A1.%20MIrrors%0A*%20%E4%BD%BF%E7%94%A8%E9%95%9C%E5%83%8F%E7%9A%84%E4%B8%80%E4%BA%9B%E5%8E%9F%E5%9B%A0%EF%BC%9A%E4%BA%92%E8%81%94%E7%BD%91%E4%B8%8A%E6%9C%89%E4%B8%80%E4%B8%AA%E5%90%8C%E6%AD%A5%E9%95%9C%E5%83%8F%EF%BC%8C%E5%9C%B0%E7%90%86%E4%BD%8D%E7%BD%AE%E6%9B%B4%E8%BF%91%EF%BC%8C%E9%80%9F%E5%BA%A6%E6%9B%B4%E5%BF%AB%0A*%20%E6%82%A8%E5%B8%8C%E6%9C%9B%E5%B0%86%E7%89%B9%E5%AE%9A%E5%AD%98%E5%82%A8%E5%BA%93%E6%9B%BF%E6%8D%A2%E4%B8%BA%E6%82%A8%E5%8F%AF%E4%BB%A5%E6%9B%B4%E5%A5%BD%E5%9C%B0%E6%8E%A7%E5%88%B6%E7%9A%84%E5%86%85%E9%83%A8%E5%AD%98%E5%82%A8%E5%BA%93%0A%60%60%60xml%0A%0A%3Cmirrors%3E%0A%20%20%20%20%3Cmirror%3E%0A%20%20%20%20%3C!--id%EF%BC%8Cname%EF%BC%9Aid%E5%BF%85%E9%A1%BB%E5%94%AF%E4%B8%80(%E4%B8%8D%E8%A6%81%E4%B8%8E%E4%BB%93%E5%BA%93id%E4%B8%80%E6%A0%B7)%EF%BC%8Cname%E9%9A%8F%E6%84%8F--%3E%0A%20%20%20%20%20%20%3Cid%3Eplanetmirror.com%3C%2Fid%3E%0A%20%20%20%20%20%20%3Cname%3EPlanetMirror%20Australia%3C%2Fname%3E%0A%20%20%20%20%20%20%3C!--url%EF%BC%9A%E9%95%9C%E5%83%8F%E7%9A%84%E5%9C%B0%E5%9D%80--%3E%0A%20%20%20%20%20%20%3Curl%3Ehttp%3A%2F%2Fdownloads.planetmirror.com%2Fpub%2Fmaven2%3C%2Furl%3E%0A%20%20%20%20%20%20%3C!--mirrorOf%EF%BC%9A%E9%9C%80%E8%A6%81%E8%A2%AB%E9%95%9C%E5%83%8F%E7%9A%84%E4%BB%93%E5%BA%93id%E3%80%82%E4%BE%8B%E5%A6%82%EF%BC%8C%E8%A6%81%E6%8C%87%E5%90%91Maven%E4%B8%AD%E5%A4%AE%E5%AD%98%E5%82%A8%E5%BA%93%EF%BC%88https%3A%2F%2Frepo.maven.apache.org%2Fmaven2%2F%EF%BC%89%E7%9A%84%E9%95%9C%E5%83%8F%EF%BC%8C%E8%AF%B7%E5%B0%86%E6%AD%A4%E5%85%83%E7%B4%A0%E8%AE%BE%E7%BD%AE%E4%B8%BAcentral--%3E%0A%20%20%20%20%20%20%3CmirrorOf%3Ecentral%3C%2FmirrorOf%3E%0A%20%20%20%20%3C%2Fmirror%3E%0A%20%20%3C%2Fmirrors%3E%0A%0A%0A%60%60%60%0A%0A2.%20Profiles%0Asettings.xml%E4%B8%AD%E7%9A%84profile%E5%85%83%E7%B4%A0%E6%98%AFpom.xml%20profile%E5%85%83%E7%B4%A0%E7%9A%84%E7%B2%BE%E7%AE%80%E7%89%88%E6%9C%AC%E3%80%82%0A%E5%AE%83%E7%94%B1activation%EF%BC%8Crepositories%EF%BC%8CpluginRepositories%E5%92%8Cproperties%E5%85%83%E7%B4%A0%E7%BB%84%E6%88%90.%0A**%E5%A6%82%E6%9E%9Cprofile%E5%9C%A8settings.xml%E4%B8%AD%E8%A2%AB%E6%BF%80%E6%B4%BB%EF%BC%8C%E5%88%99%E5%85%B6%E5%80%BC%E5%B0%86%E8%A6%86%E7%9B%96POM%E6%88%96profiles.xml%E6%96%87%E4%BB%B6%E4%B8%AD%E4%BB%BB%E4%BD%95%E7%AD%89%E6%95%88%E7%9A%84ID%E9%85%8D%E7%BD%AE%E3%80%82**%0A%60%60%60xml%0A%20%3Cprofile%3E%20%20%0A%20%20%20%20%20%3Cid%3EdownloadSources%3C%2Fid%3E%20%20%0A%20%20%20%20%3Cproperties%3E%20%20%0A%20%20%20%20%20%20%3CdownloadSources%3Etrue%3C%2FdownloadSources%3E%20%20%0A%20%20%20%20%20%20%3CdownloadJavadocs%3Etrue%3C%2FdownloadJavadocs%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%3C%2Fproperties%3E%20%20%0A%20%20%3C%2Fprofile%3E%20%20%0A%0A%60%60%60%0A%0A3.%20Repositories%0ARepositories%E6%98%AFMaven%E7%94%A8%E4%BA%8E%E5%A1%AB%E5%85%85%E6%9E%84%E5%BB%BA%E7%B3%BB%E7%BB%9F%E7%9A%84%E6%9C%AC%E5%9C%B0%E5%AD%98%E5%82%A8%E5%BA%93%E7%9A%84%E9%A1%B9%E7%9B%AE%E7%9A%84%E8%BF%9C%E7%A8%8B%E9%9B%86%E5%90%88%E3%80%82%E5%AE%83%E6%9D%A5%E8%87%AA%E8%BF%99%E4%B8%AA%E6%9C%AC%E5%9C%B0%E5%AD%98%E5%82%A8%E5%BA%93%EF%BC%8CMaven%E7%A7%B0%E4%B9%8B%E4%B8%BA%E6%8F%92%E4%BB%B6%E5%92%8C%E4%BE%9D%E8%B5%96%E9%A1%B9%E3%80%82%E4%B8%8D%E5%90%8C%E7%9A%84%E8%BF%9C%E7%A8%8B%E5%AD%98%E5%82%A8%E5%BA%93%E5%8F%AF%E8%83%BD%E5%8C%85%E5%90%AB%E4%B8%8D%E5%90%8C%E7%9A%84%E9%A1%B9%E7%9B%AE%EF%BC%8C%E5%B9%B6%E4%B8%94%E5%9C%A8%E5%90%AF%E7%94%A8%E7%9A%84profile%E4%B8%8B%EF%BC%8C%E5%8F%AF%E4%BB%A5%E6%90%9C%E7%B4%A2%E5%AE%83%E4%BB%AC%E4%BB%A5%E6%9F%A5%E6%89%BE%E5%8C%B9%E9%85%8D%E7%9A%84%E7%89%88%E6%9C%AC%E6%88%96%E5%BF%AB%E7%85%A7%E5%B7%A5%E4%BB%B6%E3%80%82%0A%0A4.%20Plugin%20Repositories%0ApluginRepositories%E5%85%83%E7%B4%A0%E5%9D%97%E7%9A%84%E7%BB%93%E6%9E%84%E7%B1%BB%E4%BC%BC%E4%BA%8Erepositories%E5%85%83%E7%B4%A0%E3%80%82%C2%A0pluginRepository%E5%85%83%E7%B4%A0%E6%8C%87%E5%AE%9AMaven%E5%8F%AF%E4%BB%A5%E5%9C%A8%E5%93%AA%E9%87%8C%E6%89%BE%E5%88%B0%E6%96%B0%E6%8F%92%E4%BB%B6%E7%9A%84%E8%BF%9C%E7%A8%8B%E4%BD%8D%E7%BD%AE%E3%80%82%0A%0A%60%60%60xml%0A%3Cprofile%3E%20%20%0A%20%20%20%20%20%20%3Cid%3Enexus_150%3C%2Fid%3E%20%20%0A%20%20%20%20%20%20%3Crepositories%3E%20%20%0A%20%20%20%20%20%20%20%20%3Crepository%3E%09%0A%20%20%20%20%20%20%20%20%20%20%3Cid%3Emaven-releases%3C%2Fid%3E%20%20%0A%20%20%20%20%20%20%20%20%20%20%3Cname%3Elocal%20private%20nexus%3C%2Fname%3E%20%20%0A%20%20%20%20%20%20%20%20%20%20%3Curl%3Ehttp%3A%2F%2F115.231.97.150%2Fnexus%2Frepository%2Freleases%2F%3C%2Furl%3E%20%20%0A%20%20%20%20%20%20%20%20%20%20%3Creleases%3E%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cenabled%3Etrue%3C%2Fenabled%3E%20%20%0A%20%20%20%20%20%20%20%20%20%20%3C%2Freleases%3E%20%20%0A%20%20%20%20%20%20%20%20%20%20%3Csnapshots%3E%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cenabled%3Efalse%3C%2Fenabled%3E%20%20%0A%20%20%20%20%20%20%20%20%20%20%3C%2Fsnapshots%3E%20%20%0A%20%20%20%20%20%20%20%20%3C%2Frepository%3E%20%20%0A%20%20%20%20%20%20%20%20%3Crepository%3E%20%20%0A%20%20%20%20%20%20%20%20%20%20%3Cid%3Emaven-snapshots%3C%2Fid%3E%20%20%0A%20%20%20%20%20%20%20%20%20%20%3Cname%3Elocal%20private%20nexus%3C%2Fname%3E%20%20%0A%20%20%20%20%20%20%20%20%20%20%3Curl%3Ehttp%3A%2F%2F115.231.97.150%2Fnexus%2Frepository%2Fmaven-snapshots%2F%3C%2Furl%3E%20%20%0A%20%20%20%20%20%20%20%20%20%20%3Creleases%3E%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cenabled%3Efalse%3C%2Fenabled%3E%20%20%0A%20%20%20%20%20%20%20%20%20%20%3C%2Freleases%3E%20%20%0A%20%20%20%20%20%20%20%20%20%20%3Csnapshots%3E%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cenabled%3Etrue%3C%2Fenabled%3E%20%20%0A%20%20%20%20%20%20%20%20%20%20%3C%2Fsnapshots%3E%20%20%0A%20%20%20%20%20%20%20%20%3C%2Frepository%3E%0A%0A%3C!--%0A%20%20qcloud-oauth2-client-1.1.0%0A%0A--%3E%0A%3C!--%09%09%3Crepository%3E%0A%20%20%20%20%20%20%20%20%20%3Cid%3Ecci-snapshots%3C%2Fid%3E%0A%20%20%20%20%20%20%20%20%20%3Curl%3Ehttp%3A%2F%2F10.10.81.107%3A8080%2Fnexus%2Fcontent%2Frepositories%2Fsnapshots%2F%3C%2Furl%3E%0A%20%20%20%20%20%20%20%20%3C%2Frepository%3E%0A%20%20%20%20%20%20%20%20%3Crepository%3E%0A%20%20%20%20%20%20%20%20%20%3Cid%3Ecci-releases%3C%2Fid%3E%0A%20%20%20%20%20%20%20%20%20%3Curl%3Ehttp%3A%2F%2F10.10.81.107%3A8080%2Fnexus%2Fcontent%2Fgroups%2Fpublic%2F%3C%2Furl%3E%0A%20%20%20%20%20%20%20%20%3C%2Frepository%3E--%3E%0A%20%20%20%20%20%20%3C%2Frepositories%3E%20%20%0A%20%20%20%20%20%20%0A%20%20%20%20%20%20%3CpluginRepositories%3E%20%20%0A%20%20%20%20%20%20%20%20%3CpluginRepository%3E%20%20%0A%20%20%20%20%20%20%20%20%20%20%3Cid%3Emaven-releases%3C%2Fid%3E%20%20%0A%20%20%20%20%20%20%20%20%20%20%3Cname%3Elocal%20private%20nexus%3C%2Fname%3E%20%20%0A%20%20%20%20%20%20%20%20%20%20%3Curl%3Ehttp%3A%2F%2F115.231.97.150%2Fnexus%2Frepository%2Freleases%2F%3C%2Furl%3E%20%20%0A%20%20%20%20%20%20%20%20%20%20%3Creleases%3E%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cenabled%3Etrue%3C%2Fenabled%3E%20%20%0A%20%20%20%20%20%20%20%20%20%20%3C%2Freleases%3E%20%20%0A%20%20%20%20%20%20%20%20%20%20%3Csnapshots%3E%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cenabled%3Efalse%3C%2Fenabled%3E%20%20%0A%20%20%20%20%20%20%20%20%20%20%3C%2Fsnapshots%3E%20%20%0A%20%20%20%20%20%20%20%20%3C%2FpluginRepository%3E%20%20%0A%20%20%20%20%20%20%20%20%3CpluginRepository%3E%20%20%0A%20%20%20%20%20%20%20%20%20%20%3Cid%3Emaven-snapshots%3C%2Fid%3E%20%20%0A%20%20%20%20%20%20%20%20%20%20%3Cname%3Elocal%20private%20nexus%3C%2Fname%3E%20%20%0A%20%20%20%20%20%20%20%20%20%20%3Curl%3Ehttp%3A%2F%2F115.231.97.150%2Fnexus%2Frepository%2Fmaven-snapshots%2F%3C%2Furl%3E%20%20%0A%20%20%20%20%20%20%20%20%20%20%3Creleases%3E%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cenabled%3Efalse%3C%2Fenabled%3E%20%20%0A%20%20%20%20%20%20%20%20%20%20%3C%2Freleases%3E%20%20%0A%20%20%20%20%20%20%20%20%20%20%3Csnapshots%3E%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cenabled%3Etrue%3C%2Fenabled%3E%20%20%0A%20%20%20%20%20%20%20%20%20%20%3C%2Fsnapshots%3E%20%20%0A%20%20%20%20%20%20%20%20%3C%2FpluginRepository%3E%20%20%0A%20%20%20%20%20%20%3C%2FpluginRepositories%3E%20%0A%20%20%20%20%3C%2Fprofile%3E%20%20%0A%60%60%60%0A%0A5.%20%E5%90%AF%E7%94%A8Profiles%0A%60%60%60xml%0A%20%20%3CactiveProfiles%3E%20%20%0A%20%20%3CactiveProfile%3Enexus_150%3C%2FactiveProfile%3E%0A%20%20%20%20%20%20%3C!--%20%20%20%20%3CactiveProfile%3EdownloadSources%3C%2FactiveProfile%3E%20%20%0A%20%20%20%20%20%20%20%20%3CactiveProfile%3Epublic-snapshots%3C%2FactiveProfile%3E%20%20%20--%3E%0A%20%20%3C%2FactiveProfiles%3E%20%0A%0A%60%60%60%0A%0A%23%23%20%E6%97%A5%E5%BF%97%E5%86%99%E6%B3%95%0A%0A%E4%BD%BF%E7%94%A8alibab%20Java%20Coding%20Guidelinec%E6%8F%92%E4%BB%B6%E8%A7%84%E8%8C%83%E4%BB%A3%E7%A0%81%0A1.%20%E4%BB%80%E4%B9%88%E6%97%B6%E5%80%99%E5%86%99%EF%BC%9F%0A---%20%E6%96%B9%E6%B3%95%E5%85%A5%E5%8F%A3%E5%A4%84(info)%0A---%E6%96%B9%E6%B3%95%E9%80%80%E5%87%BA%E5%89%8D(debug%2Cinfo)%0A----%E6%B5%81%E7%A8%8B%E5%88%86%E6%94%AF(info%2Cwarn)%0A----%E5%BC%82%E5%B8%B8%E5%88%86%E6%94%AF(error)%0A2.%20%E5%86%99%E7%9A%84%E5%86%85%E5%AE%B9%0A---%E5%85%A5%E5%8F%82(%E5%BF%85%E9%80%89)%0A---%E6%96%B9%E6%B3%95%E8%B0%83%E7%94%A8(%E5%8F%AF%E9%80%89)%20debug%0A---%E8%BF%94%E5%9B%9E%E5%80%BC%EF%BC%88%E5%8F%AF%E9%80%89%EF%BC%89%0A---%E4%B8%AD%E9%97%B4%E5%8F%98%E9%87%8F(%E5%8F%AF%E9%80%89)%0A3.%20%E5%86%99%E7%9A%84%E6%97%B6%E5%80%99%E5%9C%A8%E6%97%A5%E5%BF%97%E4%B8%AD%E5%8A%A0%E5%85%A5%E5%8F%AF%E4%BB%A5%E6%9F%A5%E8%AF%A2%E7%9A%84%E6%9D%A1%E4%BB%B6%EF%BC%8C%E4%BB%A5%E4%BE%BF%E5%88%86%E8%BE%A8%E6%90%9C%E7%B4%A2%EF%BC%8C%E5%A6%82%0A%60%60%60%0Alog.warn(%22%5B%E7%B3%BB%E7%BB%9F%E5%90%8D%20%E6%A8%A1%E5%9D%97%E5%90%8D%5D%20xxxxxx%22)%3B%0A%60%60%60%0A%0A%23%23%20%E5%B7%A5%E5%85%B7%E7%B1%BB%0A1.%20%E6%89%80%E6%9C%89%E7%9A%84%E5%8F%98%E9%87%8F%E5%92%8C%E6%96%B9%E6%B3%95%E9%83%BD%E6%98%AFstatic%0A2.%20%E5%A6%82%E6%9E%9C%E9%9C%80%E8%A6%81%E7%94%A8%E5%88%B0%E5%85%B6%E4%BB%96%E7%9A%84service%EF%BC%8C%E9%80%9A%E8%BF%87spring%E5%AE%B9%E5%99%A8%E5%8E%BB%E5%8F%96%0A%60%60%60java%0A%2F%2F%E9%9C%80%E8%A6%81%E5%BC%BA%E8%BD%AC%E7%B1%BB%E5%9E%8B%0A(xxxService)SpringContextUtils.getBean(%22xxxService%22)%3B%20%0A%60%60%60%0A%0A%23%23%20%E4%B8%9A%E5%8A%A1%E5%86%99%E6%B3%95%0A%0A%23%23%23%23%201.%20controller%0A%E6%8E%A5%E5%8F%97%E5%A4%9A%E4%B8%AA%E5%AF%B9%E8%B1%A1%E6%97%B6%EF%BC%8C%E5%BF%85%E9%A1%BB%E6%8A%8A%E5%A4%9A%E4%B8%AA%E5%AF%B9%E8%B1%A1%E5%B0%81%E8%A3%85%E6%88%90%E4%B8%80%E4%B8%AAVO%E7%B1%BB%E6%9D%A5%E6%8E%A5%E5%8F%97%0A%23%23%23%23%202.%20swagger%E6%B3%A8%E8%A7%A3%EF%BC%9A%0A%0A%7C%20%E4%BD%9C%E7%94%A8%E8%8C%83%E5%9B%B4%20%7C%09API%20%7C%20%E4%BD%BF%E7%94%A8%E4%BD%8D%E7%BD%AE%20%7C%0A%7C%20---%20%7C%20---%20%7C%20---%20%7C%0A%7C%E5%AF%B9%E8%B1%A1%E5%B1%9E%E6%80%A7%09%7C%40ApiModelProperty%09%7C%E7%94%A8%E5%9C%A8%E5%87%BA%E5%85%A5%E5%8F%82%E6%95%B0%E5%AF%B9%E8%B1%A1%E7%9A%84%E5%AD%97%E6%AE%B5%E4%B8%8A%7C%0A%7C%E5%8D%8F%E8%AE%AE%E9%9B%86%E6%8F%8F%E8%BF%B0%09%7C%40Api%09%7C%E7%94%A8%E4%BA%8Econtroller%E7%B1%BB%E4%B8%8A%7C%0A%7C%E5%8D%8F%E8%AE%AE%E6%8F%8F%E8%BF%B0%09%7C%40ApiOperation%7C%09%E7%94%A8%E5%9C%A8controller%E7%9A%84%E6%96%B9%E6%B3%95%E4%B8%8A%7C%0A%7CResponse%E9%9B%86%09%7C%40ApiResponses%09%7C%E7%94%A8%E5%9C%A8controller%E7%9A%84%E6%96%B9%E6%B3%95%E4%B8%8A%7C%0A%7CResponse%7C%09%40ApiResponse%09%7C%E7%94%A8%E5%9C%A8%20%40ApiResponses%E9%87%8C%E8%BE%B9%7C%0A%7C%E9%9D%9E%E5%AF%B9%E8%B1%A1%E5%8F%82%E6%95%B0%E9%9B%86%09%7C%40ApiImplicitParams%09%7C%E7%94%A8%E5%9C%A8controller%E7%9A%84%E6%96%B9%E6%B3%95%E4%B8%8A%7C%0A%7C%E9%9D%9E%E5%AF%B9%E8%B1%A1%E5%8F%82%E6%95%B0%E6%8F%8F%E8%BF%B0%7C%09%40ApiImplicitParam%09%7C%E7%94%A8%E5%9C%A8%40ApiImplicitParams%E7%9A%84%E6%96%B9%E6%B3%95%E9%87%8C%E8%BE%B9%7C%0A%7C%E6%8F%8F%E8%BF%B0%E8%BF%94%E5%9B%9E%E5%AF%B9%E8%B1%A1%E7%9A%84%E6%84%8F%E4%B9%89%09%7C%40ApiModel%09%7C%E7%94%A8%E5%9C%A8%E8%BF%94%E5%9B%9E%E5%AF%B9%E8%B1%A1%E7%B1%BB%E4%B8%8A%7C%0A%0A-%20-%20-%0A%40ApiImplicitParam%0A%7C%E5%B1%9E%E6%80%A7%7C%09%E5%8F%96%E5%80%BC%7C%09%E4%BD%9C%E7%94%A8%7C%0A%7C---%7C---%7C---%7C%0A%7CparamType%09%7C%7C%09%E6%9F%A5%E8%AF%A2%E5%8F%82%E6%95%B0%E7%B1%BB%E5%9E%8B%7C%0A%7C%7Cpath%09%7C%E4%BB%A5%E5%9C%B0%E5%9D%80%E7%9A%84%E5%BD%A2%E5%BC%8F%E6%8F%90%E4%BA%A4%E6%95%B0%E6%8D%AE%7C%0A%7C%7Cquery%7C%09%E7%9B%B4%E6%8E%A5%E8%B7%9F%E5%8F%82%E6%95%B0%E5%AE%8C%E6%88%90%E8%87%AA%E5%8A%A8%E6%98%A0%E5%B0%84%E8%B5%8B%E5%80%BC%7C%20%0A%7C%7Cbody%7C%09%E4%BB%A5%E6%B5%81%E7%9A%84%E5%BD%A2%E5%BC%8F%E6%8F%90%E4%BA%A4%20%E4%BB%85%E6%94%AF%E6%8C%81POST%0A%7C%7Cheader%7C%09%E5%8F%82%E6%95%B0%E5%9C%A8request%20headers%20%E9%87%8C%E8%BE%B9%E6%8F%90%E4%BA%A4%0A%7C%7Cform%7C%09%E4%BB%A5form%E8%A1%A8%E5%8D%95%E7%9A%84%E5%BD%A2%E5%BC%8F%E6%8F%90%E4%BA%A4%20%E4%BB%85%E6%94%AF%E6%8C%81POST%0A%7CdataType%09%7C%09%E5%8F%82%E6%95%B0%E7%9A%84%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%20%7C%E5%8F%AA%E4%BD%9C%E4%B8%BA%E6%A0%87%E5%BF%97%E8%AF%B4%E6%98%8E%EF%BC%8C%E5%B9%B6%E6%B2%A1%E6%9C%89%E5%AE%9E%E9%99%85%E9%AA%8C%E8%AF%81%0A%7C%7CLong%09%7C%7C%0A%7C%7CString%09%7C%7C%0A%7Cname%09%7C%7C%09%E6%8E%A5%E6%94%B6%E5%8F%82%E6%95%B0%E5%90%8D%7C%0A%7Cvalue%09%7C%7C%09%E6%8E%A5%E6%94%B6%E5%8F%82%E6%95%B0%E7%9A%84%E6%84%8F%E4%B9%89%E6%8F%8F%E8%BF%B0%7C%0A%7Crequired%09%09%7C%7C%E5%8F%82%E6%95%B0%E6%98%AF%E5%90%A6%E5%BF%85%E5%A1%AB%7C%0A%7C%7Ctrue%7C%09%E5%BF%85%E5%A1%AB%7C%0A%7C%7Cfalse%7C%09%E9%9D%9E%E5%BF%85%E5%A1%AB%7C%0A%7CdefaultValue%09%7C%7C%09%E9%BB%98%E8%AE%A4%E5%80%BC%0A%0A%60%60%60java%0A%0A%40ApiImplicitParams(%7B%20%40ApiImplicitParam(paramType%20%3D%20%22body%22%2C%20dataType%20%3D%20%22MessageParam%22%2C%20%0Aname%20%3D%20%22param%22%2C%20value%20%3D%20%22%E4%BF%A1%E6%81%AF%E5%8F%82%E6%95%B0%22%2C%20required%20%3D%20true)%20%7D)%0A%0A%60%60%60%0A%0A%E5%9C%A8controller%E7%B1%BB%E4%B8%8A%0A%40Api(value%3D%22%E7%94%A8%E6%88%B7controller%22%2Ctags%3D%7B%22%E7%94%A8%E6%88%B7%E6%93%8D%E4%BD%9C%E6%8E%A5%E5%8F%A3%22%7D)%0A%0A%E5%9C%A8controller%E6%96%B9%E6%B3%95%E4%B8%8A%0A%40ApiOperation(value%3D%22%E8%8E%B7%E5%8F%96%E7%94%A8%E6%88%B7%E4%BF%A1%E6%81%AF%22%2Ctags%3D%7B%22%E8%8E%B7%E5%8F%96%E7%94%A8%E6%88%B7%E4%BF%A1%E6%81%AFcopy%22%7D)%0A%0A%E5%9C%A8%E5%AE%9E%E4%BD%93%E7%B1%BB%E4%B8%8A%0A%40ApiModel(value%3D%22user%E5%AF%B9%E8%B1%A1%22%2Cdescription%3D%22%E7%94%A8%E6%88%B7%E5%AF%B9%E8%B1%A1user%22)%0A%0A%E5%9C%A8%E5%AE%9E%E4%BD%93%E6%96%B9%E6%B3%95%E4%B8%8A%20%0A%40ApiModelProperty(value%3D%22%E7%94%A8%E6%88%B7%E5%90%8D%22%2Cname%3D%22username%22)%0A%0Aswagger%E4%BE%9D%E8%B5%96%EF%BC%9A%0A%60%60%60xml%0A%3Cdependency%3E%0A%20%20%20%20%3CgroupId%3Eio.springfox%3C%2FgroupId%3E%0A%20%20%20%20%3CartifactId%3Espringfox-swagger2%3C%2FartifactId%3E%0A%20%20%20%20%3Cversion%3E%24%7Bspringfox-swagger2.version%7D%3C%2Fversion%3E%0A%3C%2Fdependency%3E%0A%3Cdependency%3E%0A%20%20%20%20%3CgroupId%3Eio.springfox%3C%2FgroupId%3E%0A%20%20%20%20%3CartifactId%3Espringfox-swagger-ui%3C%2FartifactId%3E%0A%20%20%20%20%3Cversion%3E%24%7Bspringfox-swagger-ui.version%7D%3C%2Fversion%3E%0A%3C%2Fdependency%3E%0A%60%60%60%0A-%20-%20-%0A%0A1.%20Do%E7%B1%BB%E7%BB%A7%E6%89%BFModel%2C%E4%B8%8D%E5%86%99%E5%85%B6%E4%BB%96%E9%80%9A%E7%94%A8%E7%9A%84%E5%B1%9E%E6%80%A7%EF%BC%8C%E6%B3%A8%E9%87%8A%E5%B1%9E%E6%80%A7%E4%B8%AD%E6%96%87%E6%B3%A8%E9%87%8Alombak%EF%BC%8C%E4%B8%BB%E9%94%AE%E6%B3%A8%E8%A7%A3%40Id%0A%0A2.%20Dto%E7%B1%BB%E7%BB%A7%E6%89%BFBaseDto%EF%BC%8C%E5%8F%AF%E4%BB%A5%E5%86%99%E5%85%A5%E5%85%B6%E4%BB%96%E7%9A%84Do%E7%B1%BB%E4%BD%9C%E4%B8%BA%E5%B1%9E%E6%80%A7(%E6%9C%89%E5%85%B6%E4%BB%96%E5%B1%9E%E6%80%A7%EF%BC%8C%E9%9C%80%E6%B3%A8%E8%A7%A3lombak)%0A%0A3.%20Vo%E7%B1%BB%EF%BC%8C%E5%9C%A8controller%E9%87%8C%E4%BD%9C%E4%B8%BA%E5%8F%82%E6%95%B0%E4%BD%BF%E7%94%A8%E6%B3%A8%E8%A7%A3%40ApiModel%EF%BC%8C%40ApiModelProperty%EF%BC%8C%E6%B3%A8%E8%A7%A3lombak%0A%0A4.%20mapper%E6%8E%A5%E5%8F%A3%EF%BC%8C%E6%96%B9%E6%B3%95%E5%8F%82%E6%95%B0%E4%BD%BF%E7%94%A8Do%E7%B1%BB%EF%BC%8C%E5%8F%82%E6%95%B0%E5%90%8D%E4%B8%BArecord%EF%BC%8C%E6%B3%A8%E8%A7%A3%40Mapper%0A%0A5.%20Service%20%E6%8E%A5%E5%8F%97%E5%8F%82%E6%95%B0%E4%B8%BADto%2C%E4%BC%A0%E7%BB%99mapper%E7%9A%84%E5%8F%82%E6%95%B0%E4%B8%BADto.getRecord()%2C%E8%BF%94%E5%9B%9E%E7%B1%BB%E5%9E%8B%E4%B8%BASWrapper%0A%0A6.%20controller%20extends%20BaseController%E6%96%B9%E6%B3%95%E6%8E%A5%E5%8F%97%E5%8F%82%E6%95%B0Vo%EF%BC%8C%E4%BC%A0%E7%BB%99service%E7%9A%84%E4%B8%BADto%2C%E9%9C%80%E8%A6%81%E6%8A%8AVo%E8%BD%AC%E6%88%90Dto%E9%80%9A%E8%BF%87toDto(Vo%2COperateType)%E6%96%B9%E6%B3%95%20%E8%BF%94%E5%9B%9E%E7%B1%BB%E5%9E%8BRWrapper%0A%0A%0A%23%23%20%E6%89%93%E5%8C%85%0A%0A%23%23%23%23%201.%20jar%E5%8C%85%EF%BC%9A%0A%60%60%60xml%0A%3Cbuild%3E%0A%3C!--%20%E6%89%93%E6%88%90war%E4%B8%8D%E9%9C%80%E8%A6%81%E8%BF%99%E4%B8%AAmaven%E6%8F%92%E4%BB%B6%EF%BC%8C%E5%A6%82%E6%9E%9C%E6%89%93%E6%88%90jar%E5%88%99%E6%98%AF%E5%BF%85%E9%A1%BB%E7%9A%84%20--%3E%0A%20%20%20%20%3Cplugins%3E%0A%20%20%20%20%20%20%20%20%3Cplugin%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3CgroupId%3Eorg.springframework.boot%3C%2FgroupId%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3CartifactId%3Espring-boot-maven-plugin%3C%2FartifactId%3E%0A%20%20%20%20%20%20%20%20%3C%2Fplugin%3E%0A%20%20%20%20%3C%2Fplugins%3E%0A%20%20%20%20%3CfinalName%3Espringbootdemo%3C%2FfinalName%3E%0A%3C%2Fbuild%3E%0A%60%60%60%0Aspring-boot%20%E9%BB%98%E8%AE%A4%E6%8F%90%E4%BE%9B%E5%86%85%E5%B5%8C%E7%9A%84tomcat%EF%BC%8C%E6%89%80%E4%BB%A5%E6%89%93%E5%8C%85%E7%9B%B4%E6%8E%A5%E7%94%9F%E6%88%90jar%20%E5%8C%85%EF%BC%8C%E7%94%A8java%20-jar%20%E5%91%BD%E4%BB%A4%E5%B0%B1%E5%8F%AF%E4%BB%A5%E5%90%AF%E5%8A%A8%E3%80%82%0A%2F%2Fnohup%20%E6%84%8F%E6%80%9D%E6%98%AF%E4%B8%8D%E6%8C%82%E6%96%AD%E8%BF%90%E8%A1%8C%E5%91%BD%E4%BB%A4%2C%E5%BD%93%E8%B4%A6%E6%88%B7%E9%80%80%E5%87%BA%E6%88%96%E7%BB%88%E7%AB%AF%E5%85%B3%E9%97%AD%E6%97%B6%2C%E7%A8%8B%E5%BA%8F%E4%BB%8D%E7%84%B6%E8%BF%90%E8%A1%8C%0A%2F%2F%E5%BD%93%E7%94%A8%20nohup%20%E5%91%BD%E4%BB%A4%E6%89%A7%E8%A1%8C%E4%BD%9C%E4%B8%9A%E6%97%B6%EF%BC%8C%E7%BC%BA%E7%9C%81%E6%83%85%E5%86%B5%E4%B8%8B%E8%AF%A5%E4%BD%9C%E4%B8%9A%E7%9A%84%E6%89%80%E6%9C%89%E8%BE%93%E5%87%BA%E8%A2%AB%E9%87%8D%E5%AE%9A%E5%90%91%E5%88%B0nohup.out%E7%9A%84%E6%96%87%E4%BB%B6%E4%B8%AD%0A%60nohup%20java%20-jar%20test.jar%20%3Etemp.txt%20%26%60%0A%0ASpring%E7%A8%8B%E5%BA%8F%E4%BC%9A%E6%8C%89%E4%BC%98%E5%85%88%E7%BA%A7%E4%BB%8E%E4%B8%8B%E9%9D%A2%E8%BF%99%E4%BA%9B%E8%B7%AF%E5%BE%84%E6%9D%A5%E5%8A%A0%E8%BD%BDapplication.properties%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%0A*%20%E5%BD%93%E5%89%8D%E7%9B%AE%E5%BD%95%E4%B8%8B%E7%9A%84%2Fconfig%E7%9B%AE%E5%BD%95%0A*%20%E5%BD%93%E5%89%8D%E7%9B%AE%E5%BD%95%0A*%20classpath%E9%87%8C%E7%9A%84%2Fconfig%E7%9B%AE%E5%BD%95%0A*%20classpath%20%E8%B7%9F%E7%9B%AE%E5%BD%95%0A%0A%60nohup%20java%20-jar%20-Dspring.config.location%3DD%3A%5Cconfig%5Cconfig.properties%20xxx.jar%3E%20%2Fxx%2Fnohup.out%202%3E%261%20%26%60%0A%0A%23%23%23%23%202.%20war%E5%8C%85%EF%BC%9A%0A%E6%9C%89%E6%97%B6%E5%80%99%E6%88%91%E4%BB%AC%E6%9B%B4%E5%B8%8C%E6%9C%9B%E4%B8%80%E4%B8%AAtomcat%20%E6%9D%A5%E7%AE%A1%E7%90%86%E5%A4%9A%E4%B8%AA%E9%A1%B9%E7%9B%AE%EF%BC%8C%E8%BF%99%E7%A7%8D%E6%83%85%E5%86%B5%E4%B8%8B%E5%B0%B1%E9%9C%80%E8%A6%81%E9%A1%B9%E7%9B%AE%E6%98%AFwar%20%E6%A0%BC%E5%BC%8F%E7%9A%84%E3%80%82%0A%60%60%60xml%0A%3Cdependency%3E%0A%20%20%20%20%3CgroupId%3Eorg.springframework.boot%3C%2FgroupId%3E%0A%20%20%20%20%3CartifactId%3Espring-boot-starter-tomcat%3C%2FartifactId%3E%0A%20%20%20%20%3Cscope%3Eprovided%3C%2Fscope%3E%0A%3C%2Fdependency%3E%0A%60%60%60%0Aspring-boot-starter-tomcat%20%E6%98%AF%E5%8E%9F%E6%9D%A5%E8%A2%AB%E4%BC%A0%E9%80%92%E8%BF%87%E6%9D%A5%E7%9A%84%E4%BE%9D%E8%B5%96%EF%BC%8C%E9%BB%98%E8%AE%A4%E4%BC%9A%E6%89%93%E5%88%B0%E5%8C%85%E9%87%8C%EF%BC%8C%E6%89%80%E4%BB%A5%E6%88%91%E4%BB%AC%E5%86%8D%E6%AC%A1%E5%BC%95%E5%85%A5%E6%AD%A4%E4%BE%9D%E8%B5%96%EF%BC%8C%E5%B9%B6%E6%8C%87%E5%AE%9A%E4%BE%9D%E8%B5%96%E8%8C%83%E5%9B%B4%E4%B8%BAprovided%EF%BC%8C%E8%BF%99%E6%A0%B7tomcat%20%E7%9B%B8%E5%85%B3%E7%9A%84jar%E5%B0%B1%E4%B8%8D%E4%BC%9A%E6%89%93%E5%8C%85%E5%88%B0war%20%E9%87%8C%E4%BA%86%0A%0A%E6%B7%BB%E5%8A%A0ServletInitializer%E5%B0%86%E9%A1%B9%E7%9B%AE%E6%89%93%E6%88%90war%E5%8C%85%EF%BC%8C%E9%83%A8%E7%BD%B2%E5%88%B0%E5%A4%96%E9%83%A8%E7%9A%84tomcat%E4%B8%AD%EF%BC%8C%E8%BF%99%E4%B8%AA%E6%97%B6%E5%80%99%EF%BC%8C%E4%B8%8D%E8%83%BD%E7%9B%B4%E6%8E%A5%E8%AE%BF%E9%97%AEspring%20boot%20%E9%A1%B9%E7%9B%AE%E4%B8%AD%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E9%85%8D%E7%BD%AE%E7%9A%84%E7%AB%AF%E5%8F%A3%E3%80%82%0A%0Aapplication.yml%E4%B8%AD%E9%85%8D%E7%BD%AE%E7%9A%84server.port%E9%85%8D%E7%BD%AE%E7%9A%84%E6%98%AFspring%20boot%E5%86%85%E7%BD%AE%E7%9A%84tomcat%E7%9A%84%E7%AB%AF%E5%8F%A3%E5%8F%B7%2C%20**%E6%89%93%E6%88%90war%E5%8C%85%E9%83%A8%E7%BD%B2%E5%9C%A8%E7%8B%AC%E7%AB%8B%E7%9A%84tomcat%E4%B8%8A%E4%B9%8B%E5%90%8E%2C%20%E4%BD%A0%E9%85%8D%E7%BD%AE%E7%9A%84server.port%E6%98%AF%E4%B8%8D%E8%B5%B7%E4%BD%9C%E7%94%A8%E7%9A%84**%E3%80%82%0A%0A%23%23%23%23%203.%20assembly%E6%8F%92%E4%BB%B6%0A%0A%E4%B8%BA%E4%BB%80%E4%B9%88%E9%9C%80%E8%A6%81Assembly%E6%8F%92%E4%BB%B6%E5%91%A2%EF%BC%9F%E5%9B%A0%E4%B8%BA%E5%AF%B9%E4%BA%8E**%E6%9C%8D%E5%8A%A1%E7%B1%BB%E5%9E%8B%E7%9A%84%E5%90%8E%E5%8F%B0%E7%A8%8B%E5%BA%8F**%EF%BC%8C%E7%BA%BF%E4%B8%8A%E8%BF%90%E8%A1%8C%E6%97%B6%E4%B8%80%E8%88%AC%E9%80%9A%E8%BF%87%E8%84%9A%E6%9C%AC%E7%9A%84%E6%96%B9%E5%BC%8F%E5%90%AF%E5%8A%A8%E5%92%8C%E5%81%9C%E6%AD%A2%EF%BC%8C%E8%80%8C%E9%A1%B9%E7%9B%AE%E4%B8%AD%E7%9A%84%E7%9B%AE%E5%BD%95%E7%BB%93%E6%9E%84%E5%A4%8D%E6%9D%82%E4%B8%94%E4%B8%8D%E5%A4%9F%E7%9B%B4%E8%A7%82%EF%BC%8C%E4%B8%94**%E9%A1%B9%E7%9B%AE%E6%96%87%E4%BB%B6%E4%B9%9F%E9%9C%80%E8%A6%81%E5%90%88%E5%B9%B6%E5%92%8C%E8%BF%87%E6%BB%A4**%EF%BC%8CAssembly%E6%8F%92%E4%BB%B6%E5%B0%B1%E5%8F%AF%E4%BB%A5%E5%B8%AE%E5%8A%A9%E6%88%91%E4%BB%AC%E5%AE%8C%E6%88%90%E3%80%82%0A%0A%0A%E6%AF%94%E5%A6%82%E7%8E%B0%E5%9C%A8%E6%88%91%E4%BB%AC%E7%9A%84%E9%A1%B9%E7%9B%AE%E7%9B%AE%E5%BD%95%E5%A6%82%E4%B8%8B%EF%BC%9A%0A%60%60%60%0A%2B%20src%20%0A%20%20%20%20%2B%20main%20%0A%20%20%20%20%20%20%20%20%2B%20java%20%0A%20%20%20%20%20%20%20%20%2B%20resources%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%2B%20jdbc.properties%20%0A%20%20%20%20%20%20%20%20%2B%20bin%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%2B%20start.sh%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%2B%20stop.sh%20%0A%20%20%20%20%20%20%20%20%2B%20assembly%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%2B%20assembly.xml%0A%60%60%60%0A%0A%E6%9C%80%E7%BB%88%E6%83%B3%E8%A6%81%E7%9A%84%E7%9B%AE%E5%BD%95%EF%BC%9A%0A%60%60%60%0A%2B%20bin%20%0A%20%20%20%20start.sh%20%0A%20%20%20%20stop.sh%20%0A%2B%20conf%0A%20%20%20%20jdbc.properties%20%0A%2B%20lib(%E4%BE%9D%E8%B5%96jar%E5%8C%85%E7%9B%AE%E5%BD%95)%20%0A%20%20%20%20xxx.jar%0A%60%60%60%0A%0A%0A%23%23%20%E5%88%86%E9%A1%B5%0A%0A1.%20%E4%BE%9D%E8%B5%96%0A%60%60%60xml%0A%3Cdependency%3E%0A%20%20%20%20%3CgroupId%3Eorg.springframework.data%3C%2FgroupId%3E%0A%20%20%20%20%3CartifactId%3Espring-data-commons%3C%2FartifactId%3E%0A%20%20%20%20%3Cversion%3E2.1.8.RELEASE%3C%2Fversion%3E%0A%3C%2Fdependency%3E%0A%3Cdependency%3E%0A%20%20%20%20%3CgroupId%3Ecom.github.pagehelper%3C%2FgroupId%3E%0A%20%20%20%20%3CartifactId%3Epagehelper-spring-boot-starter%3C%2FartifactId%3E%0A%20%20%20%20%3Cversion%3E1.2.12%3C%2Fversion%3E%0A%3C%2Fdependency%3E%0A%60%60%60%0A2.%E5%88%86%E9%A1%B5%E5%B0%81%E8%A3%85%E5%B7%A5%E5%85%B7%E7%B1%BB%0A%60%60%60java%0Apublic%20class%20PageInfoAdapter%3CT%3E%20extends%20PageImpl%3CT%3E%20%7B%0Apublic%20PageInfoAdapter(Page%3CT%3E%20page)%20%7B%0Asuper(page.getResult()%2C%20PageRequest.of(page.getPageNum()%20-%201%2C%20page.getPageSize())%2C%20page.getTotal())%3B%0A%7D%0A%7D%0A%60%60%60%0A3.%20controller%0A%60%60%60java%0Apublic%20RWrapper%20listTaskPlan(Pageable%20pageable%2CTaskPlan%20taskPlan)%0A%7B%0Areturn%20new%20RWrapper(taskPlanService.listTaskPlan(pageable%2CtaskPlan))%3B%0A%7D%0A%60%60%60%0A4.%20servicepublic%20%0A%60%60%60java%0APage%3CMap%3CString%2C%20Object%3E%3E%20listTaskPlan(Pageable%20pageable%2C%20TaskPlan%20taskPlan)%20%0A%7B%0A%20%20%20%20com.github.pagehelper.Page%3CMap%3CString%2C%20Object%3E%3E%20pageInfo%20%3D%20%20PageHelper.startPage(pageable.getPageNumber()%2Cpageable.getPageSize())%0A.doSelectPage(()%20-%3E%20%20taskPlanQueryMapper.listTaskPlan(taskPlan))%3B%0A%20%20%20%20return%20new%20PageInfoAdapter(pageInfo)%3B%0A%7D%0A%0A%60%60%60%0A%0A%23%23%20mybatis%0A%0A1.%20mybatis%E9%80%86%E5%90%91%E5%B7%A5%E7%A8%8B%0AgeneratorConfig.xml%E6%96%87%E4%BB%B6%E9%9C%80%E8%A6%81%E5%8A%A0%E4%B8%8A%E4%B8%8D%E7%94%9F%E6%88%90%E6%B3%A8%E9%87%8A%20%0A%E8%87%AA%E5%AE%9A%E4%B9%89%E7%9A%84%E7%94%9F%E6%88%90%E6%96%87%E4%BB%B6%E4%BE%9D%E8%B5%96%0A%60%60%60xml%0A%3Cplugin%3E%0A%20%20%20%20%3CgroupId%3Eorg.mybatis.generator%3C%2FgroupId%3E%0A%20%20%20%20%3CartifactId%3Emybatis-generator-maven-plugin%3C%2FartifactId%3E%0A%20%20%20%20%3Cversion%3E1.3.5%3C%2Fversion%3E%0A%20%20%20%20%3Cconfiguration%3E%20%20%20%20%20%0A%20%20%3CconfigurationFile%3Esrc%2Fmain%2Fresources%2Fmybatis%2FgeneratorConfig.xml%0A%20%20%3C%2FconfigurationFile%3E%0A%20%20%20%20%3Cverbose%3Etrue%3C%2Fverbose%3E%0A%20%20%20%20%3Coverwrite%3Etrue%3C%2Foverwrite%3E%0A%20%20%20%20%3C%2Fconfiguration%3E%0A%3C%2Fplugin%3E%0A%0A%3Cdependency%3E%0A%20%20%20%20%3CgroupId%3Eorg.mybatis.generator%3C%2FgroupId%3E%0A%20%20%20%20%3CartifactId%3Emybatis-generator-core%3C%2FartifactId%3E%0A%20%20%20%20%3Cversion%3E1.3.5%3C%2Fversion%3E%0A%20%20%20%20%3Cscope%3Eprovided%3C%2Fscope%3E%0A%3C%2Fdependency%3E%0A%60%60%60%0A%0A%23%23%20response%2Frequest%0A1.%20%E7%BB%99%E5%89%8D%E7%AB%AF%E8%BF%94%E5%9B%9Ejson%E6%A0%BC%E5%BC%8F%E6%95%B0%E6%8D%AE%0A%60%60%60java%0AString%20json%20%3D%20JsonUtil.bean2Json(object)%3B%0A%0Aresponse.setCharacterEncoding(%22utf-8%22)%3B%0A%0Aresponse.setContentType(%22application%2Fjson%3B%20charset%3Dutf-8%22)%3B%0A%0APrintWriter%20writer%20%3D%20response.getWriter()%3B%0A%0Awriter.write(json)%3B%0A%0A%60%60%60%0A2.%20%E5%8F%96%E5%BE%97request%E8%AF%B7%E6%B1%82%E5%9C%B0%E5%9D%80%0A%60%60%60java%0AreferUri%20%3D%20request.getScheme()%20%2B%20%22%3A%2F%2F%22%20%2B%20request.getServerName()%20%0A%2B%20%22%3A%22%20%2B%20request.getServerPort()%20%2B%20request.getServletPath()%3B%0A%0Aif%20(request.getQueryString()%20!%3D%20null)%20%0A%7B%C2%A0%C2%A0%0A%20%20%20%20referUri%20%2B%3D%20%22%3F%22%20%2B%20request.getQueryString()%3B%0A%7D%0A%60%60%60&lt;/center&gt;&lt;/div&gt;
</content>
  </entry>
  <entry xml:base="http://linzhiteng.postach.io/feed.xml">
    <title type="text">linux</title>
    <id>https://linzhiteng.postach.io/post/linux</id>
    <updated>2019-12-27T02:45:59.598000Z</updated>
    <published>2019-08-13T08:22:34Z</published>
    <link href="https://linzhiteng.postach.io/post/linux" />
    <author>
      <name>linzhi teng</name>
    </author>
    <category term="linux" />
    <category term="bash" />
    <content type="html">&lt;div&gt;&lt;div style=&quot;font-size: 14px; margin: 0; padding: 0; width: 100%;&quot;&gt;&lt;div style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;linux
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;权限
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;命令
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;基本命令
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;find
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;系统信息
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;ps和grep
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;用户管理
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;链接
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;文件操作
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;打包
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;awk
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;sed
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;vim
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;正常模式
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;编辑模式
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;命令模式
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;shell
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;bash 命令
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;特殊命令
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;命令替换
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;变量替换
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;运算符
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;字符串
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;数组
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;case esac语句
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;for
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;function
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;重定向
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h1 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 41px; border-bottom: 3px double #999; color: #000; margin-top: 14px;&quot;&gt;linux&lt;/h1&gt;
&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;权限&lt;/h2&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;d rwx r-x r-x 3 root root&lt;/code&gt;&lt;br/&gt;
第 1 位为文件类型字段，后 9 位为文件权限字段&lt;/p&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;文件类型:&lt;/li&gt;
&lt;/ol&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;d：目录&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;-：文件&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;l：链接文件&lt;/li&gt;
&lt;/ul&gt;
&lt;ol start=&quot;2&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;权限字段&lt;br/&gt;
9 位的文件权限字段中，每 3 个为一组，共 3 组，每一组分别代表对&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;文件拥有者u&lt;/code&gt;、&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;所属群组g&lt;/code&gt;以及&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;其它人o&lt;/code&gt;的文件权限。&lt;/p&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;文件的数量&lt;/p&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;第一个root: 文件拥有者&lt;br/&gt;
第二个root:所属群组&lt;/p&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;rwx：代表可读4，可写2，可执行1&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;修改文件/目录的权限的命令：chmod&lt;br/&gt;
chmod u=rwx,g=rw,o=r aaa.txt&lt;br/&gt;
chmod 764 aaa.txt&lt;br/&gt;
chmod +x aaa.txt&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;改变文件所属用户 ：chown 用户名 文件名&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;命令&lt;/h2&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;基本命令&lt;/h3&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;ctrl-a 可以将光标移至行首&lt;br/&gt;
ctrl-e 可以将光标移至行尾&lt;br/&gt;
ctrl-k 可以删除光标至行尾的所有内容&lt;br/&gt;
ctrl-u 可以删除行内光标所在位置之前的内容&lt;br/&gt;
ctrl-w 删除你键入的最后一个单词&lt;br/&gt;
ctrl-l : 清屏&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;Tab：命令和文件名补全；&lt;br/&gt;
man:指令的基本用法与选项介绍。&lt;br/&gt;
-- help:指令的具体信息显示&lt;br/&gt;
pwd：显示当前所在位置&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;ls: 列出文件或者目录的信息 &lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;ls [-atl] file|dir&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;cd：切换目录&lt;br/&gt;
cd ..（或cd../）： 切换到上一层目录&lt;br/&gt;
cd /： 切换到系统根目录&lt;br/&gt;
cd ~： 切换到用户主目录&lt;br/&gt;
cd -： 切换到上一个操作所在目录&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;mkdir ：增加目录&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;mv [dir] [newdir]：修改目录/文件的名称，移动位置&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;cp [-r] ：复制文件/目录  -r 表示递归&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;rm [-rf] ：删除文件/目录&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;find&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;find ：查找目录下的文件及文件夹&lt;br/&gt;
&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;find .&lt;/code&gt;  ：列出当前目录及子目录下所有文件和文件夹&lt;br/&gt;
&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;find /home -name &quot;*.txt&quot;&lt;/code&gt; ：在/home目录下查找以.txt结尾的文件名&lt;br/&gt;
&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;find /home -iname &quot;*.txt&quot;&lt;/code&gt; ：同上，但忽略大小写:&lt;br/&gt;
&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;find . \( -name &quot;*.txt&quot; -o -name &quot;*.pdf&quot; \)&lt;/code&gt; 或&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;find . -name &quot;*.txt&quot; -o -name &quot;*.pdf&quot;&lt;/code&gt;  ： 当前目录及子目录下查找所有以.txt和.pdf结尾的文件&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;系统信息&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;ps和grep&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;ps -ef : 查看当前系统正在运行进程&lt;br/&gt;
gerp：搜索&lt;br/&gt;
ps -ef | grep xx：查看特定的进程&lt;br/&gt;
grep -v xx: 不包含&lt;br/&gt;
grep -w xx:只显示全字符符合的列&lt;br/&gt;
kill -9 [uid] : 杀死进程&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;查看当前系统的网卡信息：ifconfig&lt;br/&gt;
查看与某台机器的连接情况：ping&lt;br/&gt;
查看当前系统的端口使用：netstat -an&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;查看内存信息  cat /proc/meminfo&lt;br/&gt;
查看CPU信息  cat /proc/cpuinfo&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;用户管理&lt;/h3&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;用户添加 ：&lt;br/&gt;
useradd :&lt;br/&gt;
-d 目录 指定用户主目录&lt;br/&gt;
-g 用户组 指定用户所属的用户组。&lt;br/&gt;
useradd -d usr/tlz -g root tlz&lt;br/&gt;
口令管理：passwd&lt;br/&gt;
用户修改: usermod   用户删除: userdel -r&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;链接&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;Linux具有为一个文件起多个名字的功能，称为链接。被链接的文件可以存放在相同的目录下，但是必须有不同的文件名，而不用在硬盘上为同样的数据重复备份。另外，被链接的文件也可以有相同的文件名，但是存放在不同的目录下，这样只要对一个目录下的该文件进行修改，就可以完成对所有目录下同名链接文件的修改。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;ln -s /usr/mengqc/mub1 /usr/liu/abc&lt;/code&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;执行该命令后，/usr/mengqc/mub1代表的路径将存放在名为/usr/liu/abc的文件中。&lt;/p&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;文件操作&lt;/h3&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;touch filename : 新建文件&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;tail [-f] 查看文件的尾部内容&lt;br/&gt;
tail -f : 显示文件最新追加的内容 查看日志更新&lt;br/&gt;
tail -10 : 显示后10行&lt;br/&gt;
tail +20 : 显示20行至文件末尾&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;cat :&lt;br/&gt;
more [-cd] : 全屏方式显示文本  -c 先清屏 -d 显示百分比&lt;br/&gt;
回车：下一行&lt;br/&gt;
空格：下一屏&lt;br/&gt;
q : 退出&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;less : 分页显示文本&lt;br/&gt;
上下键翻页&lt;br/&gt;
q : 退出&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;打包&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;tar -zcvf 打包后的名.tar.gz 要打包的文件名 ：打包并压缩文件&lt;br/&gt;
z：调用gzip压缩命令进行压缩&lt;br/&gt;
c：打包文件&lt;br/&gt;
v：显示运行过程&lt;br/&gt;
f：指定文件名&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;tar [-xvf] 压缩文件&lt;br/&gt;
x : 解压&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;unzip ：解压zip包和war包&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;awk&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;awk '{print $2}' : 取出第二个字段输出&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;sed&lt;/h4&gt;
&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;vim&lt;/h2&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;正常模式&lt;/strong&gt;&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;复制一行：yy      y$(当前到行尾)&lt;br/&gt;
粘贴：p&lt;br/&gt;
删除：s&lt;br/&gt;
上一行末尾：k&lt;br/&gt;
下一行末尾：j&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;编辑模式&lt;/strong&gt;&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;正常模式进入编辑模式： i  o  a&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;命令模式&lt;/strong&gt;&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;进入命令模式： :&lt;br/&gt;
查找：/    查找后用 n 移动光标&lt;br/&gt;
查找：？  从末尾开始查找&lt;br/&gt;
替换：&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;s/x/y/g  把当前行的所有的x替换成y&lt;br/&gt;
%s/x/y/g 把所有的x替换成y&lt;br/&gt;
10,15s/1/2  把10-15行所有1替换成2&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;shell&lt;/h2&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;Shell 是一个程序，一般都是放在/bin或者/user/bin目录下，当前 Linux 系统可用的 Shell 都记录在&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;/etc/shells&lt;/code&gt;文件中。&lt;br/&gt;
&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;/etc/shells&lt;/code&gt;是一个纯文本文件，可以使用 cat 命令查看它。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;查看当前 Linux 的默认 Shell，那么可以输出 SHELL 环境变量：&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;echo $SHELL&lt;/code&gt;&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;对于普通用户，Base shell 默认的提示符是美元符号$；&lt;br/&gt;
对于超级用户（root 用户），Bash Shell 默认的提示符是井号#。该符号表示 Shell 等待输入命令。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;Shell 通过&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;PS1&lt;/code&gt;和&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;PS2&lt;/code&gt;两个环境变量来控制提示符格式：&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0;&quot;&gt;新建一个文件，扩展名为sh（sh代表shell），扩展名并不影响脚本执行&lt;br/&gt;
第一行    &lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;#!/bin/bash&lt;/code&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-bottom: 0;&quot;&gt;&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;#!/usr/bin/env bash&lt;/code&gt;是优先选择的，因为它提供了灵活性，特别是你想在不同的版本下运行这个脚本；&lt;br/&gt;
&quot;#!&quot; 是一个约定的标记，告诉系统脚本需要什么解释器来执行，使用哪一种Shell。&lt;br/&gt;
&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;chmod +x&lt;/code&gt; 使脚本可执行&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;bash 命令&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;-c string 如果有 -c 选项，那么命令将从 string 中读取。如果 string 后 面&lt;br/&gt;
         有参数 (argument)，它们将用于给位置参数 (positional parameter&lt;br/&gt;
         ，以 $0 起始) 赋值。&lt;/p&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;特殊命令&lt;/h3&gt;
&lt;table style=&quot;margin: 2px 0 14px; color: #333; width: auto; border-collapse: collapse; box-sizing: border-box;&quot;&gt;&lt;thead style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;变量&lt;/th&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;含义&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;$$&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;当前Shell进程ID。对于 Shell 脚本，就是这些脚本所在的进程ID。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;$?&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;上个命令的退出状态，或函数的返回值。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;$0&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;当前脚本的文件名&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;$n&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;传递给脚本或函数的参数。n 是一个数字，表示第几个参数。例如，第一个参数是$1，第二个参数是$2。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;$#&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;传递给脚本或函数的参数个数。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;$*&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;传递给脚本或函数的所有参数。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;$@&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;传递给脚本或函数的所有参数。被双引号(&quot; &quot;)包含时，与 $* 稍有不同&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;命令替换&lt;/strong&gt;&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;是指Shell可以先执行命令，将输出结果暂时保存，在适当的地方输出。&lt;/p&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;
在 bash shell 中，$( ) 与` ` (反引号) 都是用来做命令替换用(commandsubstitution)的。
`command`

$(command)
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;变量替换&lt;/strong&gt;&lt;/h3&gt;
&lt;table style=&quot;margin: 2px 0 14px; color: #333; width: auto; border-collapse: collapse; box-sizing: border-box;&quot;&gt;&lt;thead style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;形式&lt;/th&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;说明&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;${var}&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;变量本来的值&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;${var:-word}&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;如果变量 var 为空或已被删除(unset)，那么返回 word，但不改变 var 的值。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;${var:=word}&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;如果变量 var 为空或已被删除(unset)，那么返回 word，并将 var 的值设置为 word。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;${var:?message}&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;如果变量 var 为空或已被删除(unset)，那么将消息 message 送到标准错误输出，可以用来检测变量 var 是否可以被正常赋值。若此替换出现在Shell脚本中，那么脚本将停止运行。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;${var:+word}&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;如果变量 var 被定义，那么返回 word，但不改变 var 的值。&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;运算符&lt;/strong&gt;&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;Bash 支持很多运算符，包括算数运算符、关系运算符、布尔运算符、字符串运算符和文件测试运算符。&lt;br/&gt;
原生bash不支持简单的数学运算，但是可以通过其他命令来实现，例如 awk 和 expr，expr 最常用。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;条件表达式要放在方括号[]之间，并且要和括号有空格；&lt;br/&gt;
表达式和运算符之间也要有空格&lt;/strong&gt;&lt;/p&gt;
&lt;table style=&quot;margin: 2px 0 14px; color: #333; width: auto; border-collapse: collapse; box-sizing: border-box;&quot;&gt;&lt;thead style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;运算符&lt;/th&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;说明&lt;/th&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;举例&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;+&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;加法&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;expr $a + $b&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;*&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;乘法&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;expr $a \* $b&lt;/code&gt;  乘号前边必须加反斜杠才能实现乘法运算；&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;==&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;相等&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;[ $a == $b ] 条件表达式要放在方括号之间，并且要和括号有空格；表达式和运算符之间也要有空格&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;-eq&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;检测两个数是否相等，相等返回 true&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;[ $a -eq $b ]&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;-o&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;或运算，有一个表达式为 true 则返回 true。&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;[ $a -lt 20 -o $b -gt 100 ]&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;-a&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;与运算，两个表达式都为 true 才返回 true。&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;[ $a -lt 20 -a $b -gt 100 ]&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;-z&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;检测字符串长度是否为0，为0返回 true。&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;[ -z $a ]&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;-n&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;检测字符串长度是否为0，不为0返回 true。&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;[ -n $a ]&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;-d&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;检测文件是否是目录，如果是，则返回 true。&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;[ -d $file ]&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;-f&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;检测文件是否是普通文件（既不是目录，也不是设备文件），如果是，则返回 true。&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;[ -f $file ]&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;-s&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;检测文件是否为空（文件大小是否大于0），不为空返回 true。&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;[ -s $file ]&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;-e&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;检测文件（包括目录）是否存在，如果是，则返回 true。&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;[ -e $file ]&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;if&lt;/span&gt; [ $a -lt &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;5&lt;/span&gt; -o $b -gt &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;100&lt;/span&gt; ]
then
    echo &lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;$a -lt 100 -o $b -gt 100 : returns true&quot;&lt;/span&gt;
&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;else&lt;/span&gt;
    echo &lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;$a -lt 100 -o $b -gt 100 : returns false&quot;&lt;/span&gt;
fi
&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;
basename:
basename /usr/bin/sort          -&gt; &quot;sort&quot;

dirname:
dirname /usr/bin/          -&gt; &quot;/usr&quot;

-----------------------------------------------------------------

| 运算符：
command1 | command2
他的功能是把第一个命令command1 执行的结果 作为command2的 输入 传给command2
ls -s|sort -nr
该命令列出当前目录中的文档(含size)，并把输出送给sort命令作为输入，sort命令按数字递减的顺序把ls的输出排序。

---------------------------------------------------------------------
&amp;&amp; 运算符：
command1  &amp;&amp; command2
&amp;&amp;左边的命令（命令1）返回真(即返回0，成功被执行）后，&amp;&amp;右边的命令（命令2）才能够被执行


|| 运算符：
command1 || command2
||左边的命令（command1）未执行成功，那么就执行||右边的命令（command2）


() 运算符：
(command1;command2;command3....)               多个命令之间用;分隔
把几个命令合在一起执行


(()) 运算符：
只要括号中的运算符、表达式符合C语言运算规则，都可用在$((exp))中
双括号中的变量可以不使用$符号前缀。括号内支持多个表达式用逗号分开。只要括号中的表达式符合C语言运算规则，比如可以直接使用for((i=0;i&lt;5;i++))， 如果不使用双括号， 则为for i in `seq 0 4`或者for i in {0..4}。再如可以直接使用if (($i&lt;5))， 如果不使用双括号， 则为if [ $i -lt 5 ]。


[[]] 运算符：
[[ ]] 结构比[ ]结构更加通用
比如，&amp;&amp;、||、&lt;和&gt; 操作符能够正常存在于[[ ]]条件判断结构中
可以直接使用if [[ $a != 1 &amp;&amp; $a != 2 ]], 如果不适用双括号, 则为if [ $a -ne 1] &amp;&amp; [ $a != 2 ]或者if [ $a -ne 1 -a $a != 2 ]。
&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;
&gt;/dev/null &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;2&lt;/span&gt;&gt;&amp;&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1&lt;/span&gt;

&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1&lt;/span&gt;：&gt; 代表重定向到哪里，例如：echo &lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;123&quot;&lt;/span&gt; &gt; /home/&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;123.&lt;/span&gt;txt
&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;2&lt;/span&gt;：/dev/null 代表空设备文件
&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;3&lt;/span&gt;：&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;2&lt;/span&gt;&gt; 表示stderr标准错误
&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;4&lt;/span&gt;：&amp; 表示等同于的意思，&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;2&lt;/span&gt;&gt;&amp;&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1&lt;/span&gt;，表示&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;2&lt;/span&gt;的输出重定向等同于&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1&lt;/span&gt;
&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;5&lt;/span&gt;：&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1&lt;/span&gt; 表示stdout标准输出，系统默认值是&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1&lt;/span&gt;，所以&lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;&gt;/dev/null&quot;&lt;/span&gt;等同于 &lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;1&gt;/dev/null&quot;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;字符串&lt;/h3&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;# 获取字符串长度&lt;/span&gt;
string=&lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;abcd&quot;&lt;/span&gt;
echo ${&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;#string} #输出 4&lt;/span&gt;

&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;# 截取字符串&lt;/span&gt;
string=&lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;alibaba is a great company&quot;&lt;/span&gt;
echo ${string:&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1&lt;/span&gt;:&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;4&lt;/span&gt;} &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;#输出liba&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;数组&lt;/h3&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;
array_name=(value0 value1 value2 value3)

&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;# 使用@ 或 * 可以获取数组中的所有元素&lt;/span&gt;
${array_name[*]}
${array_name[@]}


&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;# 取得数组元素的个数&lt;/span&gt;
length=${&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;#array_name[@]}&lt;/span&gt;

&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;# 取得数组单个元素的长度&lt;/span&gt;
lengthn=${&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;#array_name[n]}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;case esac语句&lt;/h3&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;    case ${ACTION} &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;in&lt;/span&gt;
    war)
        deploy_war  &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;# 函数的调用&lt;/span&gt;
        ;;
    min)
        deploy_min
        ;;
    web)
        deploy_web
        ;;
    restart)
        stop_tomcat
        start_tomcat
        ;;
    *)
        usage
        ;;
    esac
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;for&lt;/h3&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;for loop in 1 2 3 4 5
do
    echo &quot;The value is: $loop&quot;
done
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;function&lt;/h3&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;function test() {
    local pids = &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;#命名变量&lt;/span&gt;
    
    sh startup.sh &gt;/dev/null &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;2&lt;/span&gt;&gt;&amp;&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1&lt;/span&gt;  &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;# 运行脚本&lt;/span&gt;
    
    log &lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;stop tomcat success.&quot;&lt;/span&gt;  &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;# 输出日志&lt;/span&gt;
}

test  &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;# 调用函数&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;重定向&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;一般情况下，每个 Unix/Linux 命令运行时都会打开三个文件：&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;标准输入文件(stdin)：stdin的文件描述符为0，Unix程序默认从stdin读取数据。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;标准输出文件(stdout)：stdout 的文件描述符为1，Unix程序默认向stdout输出数据。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;标准错误文件(stderr)：stderr的文件描述符为2，Unix程序会向stderr流中写入错误信息。&lt;/li&gt;
&lt;/ul&gt;
&lt;table style=&quot;margin: 2px 0 14px; color: #333; width: auto; border-collapse: collapse; box-sizing: border-box;&quot;&gt;&lt;thead style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;命令&lt;/th&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;说明&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;command &gt; file&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;将输出重定向到 file。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;command &lt; file&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;将输入重定向到 file。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;command &gt;&gt; file&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;将输出以追加的方式重定向到 file。&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;






&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;center style='display:none !important;visibility:collapse !important;height:0 !important;white-space:nowrap;width:100%;overflow:hidden'&gt;%5Btoc%5D%0A%23%20linux%20%0A%23%23%20%E6%9D%83%E9%99%90%0A%60d%20rwx%20r-x%20r-x%203%20root%20root%60%0A%E7%AC%AC%201%20%E4%BD%8D%E4%B8%BA%E6%96%87%E4%BB%B6%E7%B1%BB%E5%9E%8B%E5%AD%97%E6%AE%B5%EF%BC%8C%E5%90%8E%209%20%E4%BD%8D%E4%B8%BA%E6%96%87%E4%BB%B6%E6%9D%83%E9%99%90%E5%AD%97%E6%AE%B5%0A1.%20%E6%96%87%E4%BB%B6%E7%B1%BB%E5%9E%8B%3A%20%20%0A*%20d%EF%BC%9A%E7%9B%AE%E5%BD%95%20%20%0A*%20-%EF%BC%9A%E6%96%87%E4%BB%B6%20%20%20%20%0A*%20l%EF%BC%9A%E9%93%BE%E6%8E%A5%E6%96%87%E4%BB%B6%0A%0A2.%20%E6%9D%83%E9%99%90%E5%AD%97%E6%AE%B5%0A9%20%E4%BD%8D%E7%9A%84%E6%96%87%E4%BB%B6%E6%9D%83%E9%99%90%E5%AD%97%E6%AE%B5%E4%B8%AD%EF%BC%8C%E6%AF%8F%203%20%E4%B8%AA%E4%B8%BA%E4%B8%80%E7%BB%84%EF%BC%8C%E5%85%B1%203%20%E7%BB%84%EF%BC%8C%E6%AF%8F%E4%B8%80%E7%BB%84%E5%88%86%E5%88%AB%E4%BB%A3%E8%A1%A8%E5%AF%B9%60%E6%96%87%E4%BB%B6%E6%8B%A5%E6%9C%89%E8%80%85u%60%E3%80%81%60%E6%89%80%E5%B1%9E%E7%BE%A4%E7%BB%84g%60%E4%BB%A5%E5%8F%8A%60%E5%85%B6%E5%AE%83%E4%BA%BAo%60%E7%9A%84%E6%96%87%E4%BB%B6%E6%9D%83%E9%99%90%E3%80%82%0A%0A3.%20%E6%96%87%E4%BB%B6%E7%9A%84%E6%95%B0%E9%87%8F%0A%0A4.%20%E7%AC%AC%E4%B8%80%E4%B8%AAroot%3A%20%E6%96%87%E4%BB%B6%E6%8B%A5%E6%9C%89%E8%80%85%20%20%20%20%0A%E7%AC%AC%E4%BA%8C%E4%B8%AAroot%3A%E6%89%80%E5%B1%9E%E7%BE%A4%E7%BB%84%0A%0A5.%20rwx%EF%BC%9A%E4%BB%A3%E8%A1%A8%E5%8F%AF%E8%AF%BB4%EF%BC%8C%E5%8F%AF%E5%86%992%EF%BC%8C%E5%8F%AF%E6%89%A7%E8%A1%8C1%0A%0A%3E%E4%BF%AE%E6%94%B9%E6%96%87%E4%BB%B6%2F%E7%9B%AE%E5%BD%95%E7%9A%84%E6%9D%83%E9%99%90%E7%9A%84%E5%91%BD%E4%BB%A4%EF%BC%9Achmod%0A%3Echmod%20u%3Drwx%2Cg%3Drw%2Co%3Dr%20aaa.txt%0A%3Echmod%20764%20aaa.txt%0A%3Echmod%20%2Bx%20aaa.txt%0A%0A%3E%E6%94%B9%E5%8F%98%E6%96%87%E4%BB%B6%E6%89%80%E5%B1%9E%E7%94%A8%E6%88%B7%20%EF%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%BC%9A%E5%A4%8D%E5%88%B6%E6%96%87%E4%BB%B6%2F%E7%9B%AE%E5%BD%95%20%20-r%20%E8%A1%A8%E7%A4%BA%E9%80%92%E5%BD%92%0A%0A%3Erm%20%5B-rf%5D%20%EF%BC%9A%E5%88%A0%E9%99%A4%E6%96%87%E4%BB%B6%2F%E7%9B%AE%E5%BD%95%0A%0A%23%23%23%23%20find%0A%3Efind%20%EF%BC%9A%E6%9F%A5%E6%89%BE%E7%9B%AE%E5%BD%95%E4%B8%8B%E7%9A%84%E6%96%87%E4%BB%B6%E5%8F%8A%E6%96%87%E4%BB%B6%E5%A4%B9%0A%3E%60find%20.%60%20%20%EF%BC%9A%E5%88%97%E5%87%BA%E5%BD%93%E5%89%8D%E7%9B%AE%E5%BD%95%E5%8F%8A%E5%AD%90%E7%9B%AE%E5%BD%95%E4%B8%8B%E6%89%80%E6%9C%89%E6%96%87%E4%BB%B6%E5%92%8C%E6%96%87%E4%BB%B6%E5%A4%B9%0A%3E%60find%20%2Fhome%20-name%20%E2%80%9C*.txt%E2%80%9D%60%20%EF%BC%9A%E5%9C%A8%2Fhome%E7%9B%AE%E5%BD%95%E4%B8%8B%E6%9F%A5%E6%89%BE%E4%BB%A5.txt%E7%BB%93%E5%B0%BE%E7%9A%84%E6%96%87%E4%BB%B6%E5%90%8D%0A%3E%60find%20%2Fhome%20-iname%20%E2%80%9C*.txt%E2%80%9D%60%20%EF%BC%9A%E5%90%8C%E4%B8%8A%EF%BC%8C%E4%BD%86%E5%BF%BD%E7%95%A5%E5%A4%A7%E5%B0%8F%E5%86%99%3A%0A%3E%60find%20.%20%5C(%20-name%20%22*.txt%22%20-o%20-name%20%22*.pdf%22%20%5C)%60%20%E6%88%96%60%20find%20.%20-name%20%22*.txt%22%20-o%20-name%20%22*.pdf%22%60%20%20%EF%BC%9A%20%E5%BD%93%E5%89%8D%E7%9B%AE%E5%BD%95%E5%8F%8A%E5%AD%90%E7%9B%AE%E5%BD%95%E4%B8%8B%E6%9F%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B%E5%86%85%E5%AD%98%E4%BF%A1%E6%81%AF%20%20cat%20%2Fproc%2Fmeminfo%0A%3E%E6%9F%A5%E7%9C%8BCPU%E4%BF%A1%E6%81%AF%20%20cat%20%2Fproc%2Fcpuinfo%0A%0A%0A%0A%0A%23%23%23%20%E7%94%A8%E6%88%B7%E7%AE%A1%E7%90%86%0A*%20%E7%94%A8%E6%88%B7%E6%B7%BB%E5%8A%A0%20%EF%BC%9A%0Auseradd%20%3A%20%0A-d%20%E7%9B%AE%E5%BD%95%20%E6%8C%87%E5%AE%9A%E7%94%A8%E6%88%B7%E4%B8%BB%E7%9B%AE%E5%BD%95%0A-g%20%E7%94%A8%E6%88%B7%E7%BB%84%20%E6%8C%87%E5%AE%9A%E7%94%A8%E6%88%B7%E6%89%80%E5%B1%9E%E7%9A%84%E7%94%A8%E6%88%B7%E7%BB%84%E3%80%82%0Auseradd%20-d%20usr%2Ftlz%20-g%20root%20tlz%0A%E5%8F%A3%E4%BB%A4%E7%AE%A1%E7%90%86%EF%BC%9Apasswd%20%20%0A%E7%94%A8%E6%88%B7%E4%BF%AE%E6%94%B9%3A%20usermod%20%20%20%E7%94%A8%E6%88%B7%E5%88%A0%E9%99%A4%3A%20userdel%20-r%0A%0A%0A%23%23%23%20%E9%93%BE%E6%8E%A5%0A%0ALinux%E5%85%B7%E6%9C%89%E4%B8%BA%E4%B8%80%E4%B8%AA%E6%96%87%E4%BB%B6%E8%B5%B7%E5%A4%9A%E4%B8%AA%E5%90%8D%E5%AD%97%E7%9A%84%E5%8A%9F%E8%83%BD%EF%BC%8C%E7%A7%B0%E4%B8%BA%E9%93%BE%E6%8E%A5%E3%80%82%E8%A2%AB%E9%93%BE%E6%8E%A5%E7%9A%84%E6%96%87%E4%BB%B6%E5%8F%AF%E4%BB%A5%E5%AD%98%E6%94%BE%E5%9C%A8%E7%9B%B8%E5%90%8C%E7%9A%84%E7%9B%AE%E5%BD%95%E4%B8%8B%EF%BC%8C%E4%BD%86%E6%98%AF%E5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BE%84%E5%B0%86%E5%AD%98%E6%94%BE%E5%9C%A8%E5%90%8D%E4%B8%BA%2Fusr%2Fliu%2Fabc%E7%9A%84%E6%96%87%E4%BB%B6%E4%B8%AD%E3%80%82%0A%0A%23%23%23%20%E6%96%87%E4%BB%B6%E6%93%8D%E4%BD%9C%0A%3Etouch%20filename%20%3A%20%E6%96%B0%E5%BB%BA%E6%96%87%E4%BB%B6%0A%0A%3Etail%20%5B-f%5D%20%E6%9F%A5%E7%9C%8B%E6%96%87%E4%BB%B6%E7%9A%84%E5%B0%BE%E9%83%A8%E5%86%85%E5%AE%B9%0A%3Etail%20-f%20%3A%20%E6%98%BE%E7%A4%BA%E6%96%87%E4%BB%B6%E6%9C%80%E6%96%B0%E8%BF%BD%E5%8A%A0%E7%9A%84%E5%86%85%E5%AE%B9%20%E6%9F%A5%E7%9C%8B%E6%97%A5%E5%BF%97%E6%9B%B4%E6%96%B0%0A%3Etail%20-10%20%3A%20%E6%98%BE%E7%A4%BA%E5%90%8E10%E8%A1%8C%0A%3Etail%20%2B20%20%3A%20%E6%98%BE%E7%A4%BA20%E8%A1%8C%E8%87%B3%E6%96%87%E4%BB%B6%E6%9C%AB%E5%B0%BE%0A%0A%3Ecat%20%3A%0A%3Emore%20%5B-cd%5D%20%3A%20%E5%85%A8%E5%B1%8F%E6%96%B9%E5%BC%8F%E6%98%BE%E7%A4%BA%E6%96%87%E6%9C%AC%20%20-c%20%E5%85%88%E6%B8%85%E5%B1%8F%20-d%20%E6%98%BE%E7%A4%BA%E7%99%BE%E5%88%86%E6%AF%94%0A%3E%E5%9B%9E%E8%BD%A6%EF%BC%9A%E4%B8%8B%E4%B8%80%E8%A1%8C%0A%3E%E7%A9%BA%E6%A0%BC%EF%BC%9A%E4%B8%8B%E4%B8%80%E5%B1%8F%0A%3Eq%20%3A%20%E9%80%80%E5%87%BA%0A%0A%3Eless%20%3A%20%E5%88%86%E9%A1%B5%E6%98%BE%E7%A4%BA%E6%96%87%E6%9C%AC%20%0A%3E%E4%B8%8A%E4%B8%8B%E9%94%AE%E7%BF%BB%E9%A1%B5%0A%3Eq%20%3A%20%E9%80%80%E5%87%BA%0A%0A%23%23%23%23%20%E6%89%93%E5%8C%85%0A%3Etar%20-zcvf%20%E6%89%93%E5%8C%85%E5%90%8E%E7%9A%84%E5%90%8D.tar.gz%20%E8%A6%81%E6%89%93%E5%8C%85%E7%9A%84%E6%96%87%E4%BB%B6%E5%90%8D%20%EF%BC%9A%E6%89%93%E5%8C%85%E5%B9%B6%E5%8E%8B%E7%BC%A9%E6%96%87%E4%BB%B6%0A%3Ez%EF%BC%9A%E8%B0%83%E7%94%A8gzip%E5%8E%8B%E7%BC%A9%E5%91%BD%E4%BB%A4%E8%BF%9B%E8%A1%8C%E5%8E%8B%E7%BC%A9%0A%3Ec%EF%BC%9A%E6%89%93%E5%8C%85%E6%96%87%E4%BB%B6%0A%3Ev%EF%BC%9A%E6%98%BE%E7%A4%BA%E8%BF%90%E8%A1%8C%E8%BF%87%E7%A8%8B%0A%3Ef%EF%BC%9A%E6%8C%87%E5%AE%9A%E6%96%87%E4%BB%B6%E5%90%8D%0A%0A%3Etar%20%5B-xvf%5D%20%E5%8E%8B%E7%BC%A9%E6%96%87%E4%BB%B6%0A%3Ex%20%3A%20%E8%A7%A3%E5%8E%8B%0A%0A%3Eunzip%20%EF%BC%9A%E8%A7%A3%E5%8E%8Bzip%E5%8C%85%E5%92%8Cwar%E5%8C%85%0A%0A%23%23%23%23%20awk%0Aawk%20'%7Bprint%20%242%7D'%20%3A%20%E5%8F%96%E5%87%BA%E7%AC%AC%E4%BA%8C%E4%B8%AA%E5%AD%97%E6%AE%B5%E8%BE%93%E5%87%BA%0A%0A%23%23%23%23%20sed%0A%0A%23%23%20vim%0A%23%23%23%23%20**%E6%AD%A3%E5%B8%B8%E6%A8%A1%E5%BC%8F**%0A%E5%A4%8D%E5%88%B6%E4%B8%80%E8%A1%8C%EF%BC%9Ayy%20%20%20%20%20%20y%24(%E5%BD%93%E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B%BF%E6%8D%A2%E6%88%902%0A%0A%23%23%20shell%0A%0AShell%20%E6%98%AF%E4%B8%80%E4%B8%AA%E7%A8%8B%E5%BA%8F%EF%BC%8C%E4%B8%80%E8%88%AC%E9%83%BD%E6%98%AF%E6%94%BE%E5%9C%A8%2Fbin%E6%88%96%E8%80%85%2Fuser%2Fbin%E7%9B%AE%E5%BD%95%E4%B8%8B%EF%BC%8C%E5%BD%93%E5%89%8D%20Linux%20%E7%B3%BB%E7%BB%9F%E5%8F%AF%E7%94%A8%E7%9A%84%20Shell%20%E9%83%BD%E8%AE%B0%E5%BD%95%E5%9C%A8%60%2Fetc%2Fshells%60%E6%96%87%E4%BB%B6%E4%B8%AD%E3%80%82%0A%60%2Fetc%2Fshells%60%E6%98%AF%E4%B8%80%E4%B8%AA%E7%BA%AF%E6%96%87%E6%9C%AC%E6%96%87%E4%BB%B6%EF%BC%8C%E5%8F%AF%E4%BB%A5%E4%BD%BF%E7%94%A8%20cat%20%E5%91%BD%E4%BB%A4%E6%9F%A5%E7%9C%8B%E5%AE%83%E3%80%82%0A%0A%E6%9F%A5%E7%9C%8B%E5%BD%93%E5%89%8D%20Linux%20%E7%9A%84%E9%BB%98%E8%AE%A4%20Shell%EF%BC%8C%E9%82%A3%E4%B9%88%E5%8F%AF%E4%BB%A5%E8%BE%93%E5%87%BA%20SHELL%20%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%EF%BC%9A%60%20echo%20%24SHELL%60%0A%0A%3E%E5%AF%B9%E4%BA%8E%E6%99%AE%E9%80%9A%E7%94%A8%E6%88%B7%EF%BC%8CBase%20shell%20%E9%BB%98%E8%AE%A4%E7%9A%84%E6%8F%90%E7%A4%BA%E7%AC%A6%E6%98%AF%E7%BE%8E%E5%85%83%E7%AC%A6%E5%8F%B7%24%EF%BC%9B%0A%3E%E5%AF%B9%E4%BA%8E%E8%B6%85%E7%BA%A7%E7%94%A8%E6%88%B7%EF%BC%88root%20%E7%94%A8%E6%88%B7%EF%BC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8%84%9A%E6%9C%AC%EF%BC%9B%0A%3E%E2%80%9C%23!%E2%80%9D%20%E6%98%AF%E4%B8%80%E4%B8%AA%E7%BA%A6%E5%AE%9A%E7%9A%84%E6%A0%87%E8%AE%B0%EF%BC%8C%E5%91%8A%E8%AF%89%E7%B3%BB%E7%BB%9F%E8%84%9A%E6%9C%AC%E9%9C%80%E8%A6%81%E4%BB%80%E4%B9%88%E8%A7%A3%E9%87%8A%E5%99%A8%E6%9D%A5%E6%89%A7%E8%A1%8C%EF%BC%8C%E4%BD%BF%E7%94%A8%E5%93%AA%E4%B8%80%E7%A7%8DShell%E3%80%82%0A%3E%60chmod%20%2Bx%60%20%E4%BD%BF%E8%84%9A%E6%9C%AC%E5%8F%AF%E6%89%A7%E8%A1%8C%0A%0A%23%23%23%20bash%20%E5%91%BD%E4%BB%A4%0A%0A-c%20string%20%E5%A6%82%E6%9E%9C%E6%9C%89%20-c%20%E9%80%89%E9%A1%B9%EF%BC%8C%E9%82%A3%E4%B9%88%E5%91%BD%E4%BB%A4%E5%B0%86%E4%BB%8E%20string%20%E4%B8%AD%E8%AF%BB%E5%8F%96%E3%80%82%E5%A6%82%E6%9E%9C%20string%20%E5%90%8E%20%E9%9D%A2%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%E6%9C%89%E5%8F%82%E6%95%B0%20(argument)%EF%BC%8C%E5%AE%83%E4%BB%AC%E5%B0%86%E7%94%A8%E4%BA%8E%E7%BB%99%E4%BD%8D%E7%BD%AE%E5%8F%82%E6%95%B0%20(positional%20parameter%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%EF%BC%8C%E4%BB%A5%20%240%C2%A0%E8%B5%B7%E5%A7%8B)%20%E8%B5%8B%E5%80%BC%E3%80%82%0A%0A%0A%23%23%23%20%E7%89%B9%E6%AE%8A%E5%91%BD%E4%BB%A4%0A%0A%7C%20%E5%8F%98%E9%87%8F%20%7C%20%E5%90%AB%E4%B9%89%20%7C%0A%7C%20---%20%7C%20---%20%7C%0A%7C%24%24%20%7C%E5%BD%93%E5%89%8DShell%E8%BF%9B%E7%A8%8BID%E3%80%82%E5%AF%B9%E4%BA%8E%20Shell%20%E8%84%9A%E6%9C%AC%EF%BC%8C%E5%B0%B1%E6%98%AF%E8%BF%99%E4%BA%9B%E8%84%9A%E6%9C%AC%E6%89%80%E5%9C%A8%E7%9A%84%E8%BF%9B%E7%A8%8BID%E3%80%82%20%7C%0A%7C%20%24%3F%20%7C%20%E4%B8%8A%E4%B8%AA%E5%91%BD%E4%BB%A4%E7%9A%84%E9%80%80%E5%87%BA%E7%8A%B6%E6%80%81%EF%BC%8C%E6%88%96%E5%87%BD%E6%95%B0%E7%9A%84%E8%BF%94%E5%9B%9E%E5%80%BC%E3%80%82%20%7C%0A%7C%20%240%20%7C%20%E5%BD%93%E5%89%8D%E8%84%9A%E6%9C%AC%E7%9A%84%E6%96%87%E4%BB%B6%E5%90%8D%20%7C%0A%7C%20%24n%20%7C%20%E4%BC%A0%E9%80%92%E7%BB%99%E8%84%9A%E6%9C%AC%E6%88%96%E5%87%BD%E6%95%B0%E7%9A%84%E5%8F%82%E6%95%B0%E3%80%82n%20%E6%98%AF%E4%B8%80%E4%B8%AA%E6%95%B0%E5%AD%97%EF%BC%8C%E8%A1%A8%E7%A4%BA%E7%AC%AC%E5%87%A0%E4%B8%AA%E5%8F%82%E6%95%B0%E3%80%82%E4%BE%8B%E5%A6%82%EF%BC%8C%E7%AC%AC%E4%B8%80%E4%B8%AA%E5%8F%82%E6%95%B0%E6%98%AF%241%EF%BC%8C%E7%AC%AC%E4%BA%8C%E4%B8%AA%E5%8F%82%E6%95%B0%E6%98%AF%242%E3%80%82%20%7C%0A%7C%20%24%23%20%7C%20%E4%BC%A0%E9%80%92%E7%BB%99%E8%84%9A%E6%9C%AC%E6%88%96%E5%87%BD%E6%95%B0%E7%9A%84%E5%8F%82%E6%95%B0%E4%B8%AA%E6%95%B0%E3%80%82%20%7C%0A%7C%20%24*%20%7C%E4%BC%A0%E9%80%92%E7%BB%99%E8%84%9A%E6%9C%AC%E6%88%96%E5%87%BD%E6%95%B0%E7%9A%84%E6%89%80%E6%9C%89%E5%8F%82%E6%95%B0%E3%80%82%20%20%7C%0A%7C%20%24%40%20%7C%20%E4%BC%A0%E9%80%92%E7%BB%99%E8%84%9A%E6%9C%AC%E6%88%96%E5%87%BD%E6%95%B0%E7%9A%84%E6%89%80%E6%9C%89%E5%8F%82%E6%95%B0%E3%80%82%E8%A2%AB%E5%8F%8C%E5%BC%95%E5%8F%B7(%22%20%22)%E5%8C%85%E5%90%AB%E6%97%B6%EF%BC%8C%E4%B8%8E%20%24*%20%E7%A8%8D%E6%9C%89%E4%B8%8D%E5%90%8C%20%7C%0A%0A%23%23%23%20**%E5%91%BD%E4%BB%A4%E6%9B%BF%E6%8D%A2**%0A%E6%98%AF%E6%8C%87Shell%E5%8F%AF%E4%BB%A5%E5%85%88%E6%89%A7%E8%A1%8C%E5%91%BD%E4%BB%A4%EF%BC%8C%E5%B0%86%E8%BE%93%E5%87%BA%E7%BB%93%E6%9E%9C%E6%9A%82%E6%97%B6%E4%BF%9D%E5%AD%98%EF%BC%8C%E5%9C%A8%E9%80%82%E5%BD%93%E7%9A%84%E5%9C%B0%E6%96%B9%E8%BE%93%E5%87%BA%E3%80%82%0A%60%60%60%0A%0A%E5%9C%A8%20bash%20shell%20%E4%B8%AD%EF%BC%8C%24(%20)%20%E4%B8%8E%60%20%60%20(%E5%8F%8D%E5%BC%95%E5%8F%B7)%20%E9%83%BD%E6%98%AF%E7%94%A8%E6%9D%A5%E5%81%9A%E5%91%BD%E4%BB%A4%E6%9B%BF%E6%8D%A2%E7%94%A8(commandsubstitution)%E7%9A%84%E3%80%82%0A%60command%60%0A%0A%24(command)%0A%60%60%60%0A%0A%23%23%23%20**%E5%8F%98%E9%87%8F%E6%9B%BF%E6%8D%A2**%0A%0A%7C%E5%BD%A2%E5%BC%8F%7C%E8%AF%B4%E6%98%8E%7C%0A%7C---%7C---%7C%0A%24%7Bvar%7D%7C%E5%8F%98%E9%87%8F%E6%9C%AC%E6%9D%A5%E7%9A%84%E5%80%BC%0A%24%7Bvar%3A-word%7D%7C%E5%A6%82%E6%9E%9C%E5%8F%98%E9%87%8F%20var%20%E4%B8%BA%E7%A9%BA%E6%88%96%E5%B7%B2%E8%A2%AB%E5%88%A0%E9%99%A4(unset)%EF%BC%8C%E9%82%A3%E4%B9%88%E8%BF%94%E5%9B%9E%C2%A0word%EF%BC%8C%E4%BD%86%E4%B8%8D%E6%94%B9%E5%8F%98%C2%A0var%20%E7%9A%84%E5%80%BC%E3%80%82%0A%24%7Bvar%3A%3Dword%7D%7C%E5%A6%82%E6%9E%9C%E5%8F%98%E9%87%8F%20var%20%E4%B8%BA%E7%A9%BA%E6%88%96%E5%B7%B2%E8%A2%AB%E5%88%A0%E9%99%A4(unset)%EF%BC%8C%E9%82%A3%E4%B9%88%E8%BF%94%E5%9B%9E%20word%EF%BC%8C%E5%B9%B6%E5%B0%86%20var%20%E7%9A%84%E5%80%BC%E8%AE%BE%E7%BD%AE%E4%B8%BA%20word%E3%80%82%0A%24%7Bvar%3A%3Fmessage%7D%7C%E5%A6%82%E6%9E%9C%E5%8F%98%E9%87%8F%20var%20%E4%B8%BA%E7%A9%BA%E6%88%96%E5%B7%B2%E8%A2%AB%E5%88%A0%E9%99%A4(unset)%EF%BC%8C%E9%82%A3%E4%B9%88%E5%B0%86%E6%B6%88%E6%81%AF%20message%20%E9%80%81%E5%88%B0%E6%A0%87%E5%87%86%E9%94%99%E8%AF%AF%E8%BE%93%E5%87%BA%EF%BC%8C%E5%8F%AF%E4%BB%A5%E7%94%A8%E6%9D%A5%E6%A3%80%E6%B5%8B%E5%8F%98%E9%87%8F%20var%20%E6%98%AF%E5%90%A6%E5%8F%AF%E4%BB%A5%E8%A2%AB%E6%AD%A3%E5%B8%B8%E8%B5%8B%E5%80%BC%E3%80%82%E8%8B%A5%E6%AD%A4%E6%9B%BF%E6%8D%A2%E5%87%BA%E7%8E%B0%E5%9C%A8Shell%E8%84%9A%E6%9C%AC%E4%B8%AD%EF%BC%8C%E9%82%A3%E4%B9%88%E8%84%9A%E6%9C%AC%E5%B0%86%E5%81%9C%E6%AD%A2%E8%BF%90%E8%A1%8C%E3%80%82%0A%24%7Bvar%3A%2Bword%7D%7C%E5%A6%82%E6%9E%9C%E5%8F%98%E9%87%8F%20var%20%E8%A2%AB%E5%AE%9A%E4%B9%89%EF%BC%8C%E9%82%A3%E4%B9%88%E8%BF%94%E5%9B%9E%20word%EF%BC%8C%E4%BD%86%E4%B8%8D%E6%94%B9%E5%8F%98%20var%20%E7%9A%84%E5%80%BC%E3%80%82%0A%0A%23%23%23%20**%E8%BF%90%E7%AE%97%E7%AC%A6**%0A%0ABash%20%E6%94%AF%E6%8C%81%E5%BE%88%E5%A4%9A%E8%BF%90%E7%AE%97%E7%AC%A6%EF%BC%8C%E5%8C%85%E6%8B%AC%E7%AE%97%E6%95%B0%E8%BF%90%E7%AE%97%E7%AC%A6%E3%80%81%E5%85%B3%E7%B3%BB%E8%BF%90%E7%AE%97%E7%AC%A6%E3%80%81%E5%B8%83%E5%B0%94%E8%BF%90%E7%AE%97%E7%AC%A6%E3%80%81%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%BF%90%E7%AE%97%E7%AC%A6%E5%92%8C%E6%96%87%E4%BB%B6%E6%B5%8B%E8%AF%95%E8%BF%90%E7%AE%97%E7%AC%A6%E3%80%82%0A%E5%8E%9F%E7%94%9Fbash%E4%B8%8D%E6%94%AF%E6%8C%81%E7%AE%80%E5%8D%95%E7%9A%84%E6%95%B0%E5%AD%A6%E8%BF%90%E7%AE%97%EF%BC%8C%E4%BD%86%E6%98%AF%E5%8F%AF%E4%BB%A5%E9%80%9A%E8%BF%87%E5%85%B6%E4%BB%96%E5%91%BD%E4%BB%A4%E6%9D%A5%E5%AE%9E%E7%8E%B0%EF%BC%8C%E4%BE%8B%E5%A6%82%20awk%20%E5%92%8C%20expr%EF%BC%8Cexpr%20%E6%9C%80%E5%B8%B8%E7%94%A8%E3%80%82%0A%0A**%E6%9D%A1%E4%BB%B6%E8%A1%A8%E8%BE%BE%E5%BC%8F%E8%A6%81%E6%94%BE%E5%9C%A8%E6%96%B9%E6%8B%AC%E5%8F%B7%5B%5D%E4%B9%8B%E9%97%B4%EF%BC%8C%E5%B9%B6%E4%B8%94%E8%A6%81%E5%92%8C%E6%8B%AC%E5%8F%B7%E6%9C%89%E7%A9%BA%E6%A0%BC%EF%BC%9B%0A%E8%A1%A8%E8%BE%BE%E5%BC%8F%E5%92%8C%E8%BF%90%E7%AE%97%E7%AC%A6%E4%B9%8B%E9%97%B4%E4%B9%9F%E8%A6%81%E6%9C%89%E7%A9%BA%E6%A0%BC**%0A%0A%7C%20%E8%BF%90%E7%AE%97%E7%AC%A6%20%7C%20%E8%AF%B4%E6%98%8E%20%7C%20%E4%B8%BE%E4%BE%8B%20%7C%0A%7C%20---%20%7C%20---%20%7C%20---%20%7C%0A%7C%20%2B%20%7C%20%E5%8A%A0%E6%B3%95%20%7C%20%60expr%20%24a%20%2B%20%24b%60%20%20%7C%0A%7C%20*%20%7C%20%E4%B9%98%E6%B3%95%20%7C%20%60expr%20%24a%20%5C*%20%24b%60%C2%A0%20%E4%B9%98%E5%8F%B7%E5%89%8D%E8%BE%B9%E5%BF%85%E9%A1%BB%E5%8A%A0%E5%8F%8D%E6%96%9C%E6%9D%A0%E6%89%8D%E8%83%BD%E5%AE%9E%E7%8E%B0%E4%B9%98%E6%B3%95%E8%BF%90%E7%AE%97%EF%BC%9B%7C%0A%7C%20%3D%3D%20%7C%20%E7%9B%B8%E7%AD%89%20%7C%20%5B%20%24a%20%3D%3D%20%24b%20%5D%20%E6%9D%A1%E4%BB%B6%E8%A1%A8%E8%BE%BE%E5%BC%8F%E8%A6%81%E6%94%BE%E5%9C%A8%E6%96%B9%E6%8B%AC%E5%8F%B7%E4%B9%8B%E9%97%B4%EF%BC%8C%E5%B9%B6%E4%B8%94%E8%A6%81%E5%92%8C%E6%8B%AC%E5%8F%B7%E6%9C%89%E7%A9%BA%E6%A0%BC%EF%BC%9B%E8%A1%A8%E8%BE%BE%E5%BC%8F%E5%92%8C%E8%BF%90%E7%AE%97%E7%AC%A6%E4%B9%8B%E9%97%B4%E4%B9%9F%E8%A6%81%E6%9C%89%E7%A9%BA%E6%A0%BC%20%7C%0A%7C-eq%20%7C%20%E6%A3%80%E6%B5%8B%E4%B8%A4%E4%B8%AA%E6%95%B0%E6%98%AF%E5%90%A6%E7%9B%B8%E7%AD%89%EF%BC%8C%E7%9B%B8%E7%AD%89%E8%BF%94%E5%9B%9E%20true%20%7C%5B%20%24a%20-eq%20%24b%20%5D%7C%0A%7C%20-o%20%7C%20%E6%88%96%E8%BF%90%E7%AE%97%EF%BC%8C%E6%9C%89%E4%B8%80%E4%B8%AA%E8%A1%A8%E8%BE%BE%E5%BC%8F%E4%B8%BA%20true%20%E5%88%99%E8%BF%94%E5%9B%9E%20true%E3%80%82%20%7C%20%5B%20%24a%20-lt%2020%20-o%20%24b%20-gt%20100%20%5D%20%7C%0A%7C%20-a%20%7C%20%E4%B8%8E%E8%BF%90%E7%AE%97%EF%BC%8C%E4%B8%A4%E4%B8%AA%E8%A1%A8%E8%BE%BE%E5%BC%8F%E9%83%BD%E4%B8%BA%20true%20%E6%89%8D%E8%BF%94%E5%9B%9E%20true%E3%80%82%20%7C%20%5B%20%24a%20-lt%2020%20-a%20%24b%20-gt%20100%20%5D%20%7C%0A%7C%20-z%20%7C%20%E6%A3%80%E6%B5%8B%E5%AD%97%E7%AC%A6%E4%B8%B2%E9%95%BF%E5%BA%A6%E6%98%AF%E5%90%A6%E4%B8%BA0%EF%BC%8C%E4%B8%BA0%E8%BF%94%E5%9B%9E%20true%E3%80%82%20%7C%20%5B%20-z%20%24a%20%5D%C2%A0%20%7C%0A%7C%20-n%20%7C%20%E6%A3%80%E6%B5%8B%E5%AD%97%E7%AC%A6%E4%B8%B2%E9%95%BF%E5%BA%A6%E6%98%AF%E5%90%A6%E4%B8%BA0%EF%BC%8C%E4%B8%8D%E4%B8%BA0%E8%BF%94%E5%9B%9E%20true%E3%80%82%20%7C%20%5B%20-n%20%24a%20%5D%C2%A0%20%7C%0A%7C%20-d%20%7C%20%E6%A3%80%E6%B5%8B%E6%96%87%E4%BB%B6%E6%98%AF%E5%90%A6%E6%98%AF%E7%9B%AE%E5%BD%95%EF%BC%8C%E5%A6%82%E6%9E%9C%E6%98%AF%EF%BC%8C%E5%88%99%E8%BF%94%E5%9B%9E%20true%E3%80%82%20%7C%20%5B%20-d%20%24file%20%5D%20%7C%0A%7C%20-f%20%7C%20%E6%A3%80%E6%B5%8B%E6%96%87%E4%BB%B6%E6%98%AF%E5%90%A6%E6%98%AF%E6%99%AE%E9%80%9A%E6%96%87%E4%BB%B6%EF%BC%88%E6%97%A2%E4%B8%8D%E6%98%AF%E7%9B%AE%E5%BD%95%EF%BC%8C%E4%B9%9F%E4%B8%8D%E6%98%AF%E8%AE%BE%E5%A4%87%E6%96%87%E4%BB%B6%EF%BC%89%EF%BC%8C%E5%A6%82%E6%9E%9C%E6%98%AF%EF%BC%8C%E5%88%99%E8%BF%94%E5%9B%9E%20true%E3%80%82%20%7C%20%5B%20-f%20%24file%20%5D%C2%A0%20%7C%0A%7C%20-s%20%7C%20%E6%A3%80%E6%B5%8B%E6%96%87%E4%BB%B6%E6%98%AF%E5%90%A6%E4%B8%BA%E7%A9%BA%EF%BC%88%E6%96%87%E4%BB%B6%E5%A4%A7%E5%B0%8F%E6%98%AF%E5%90%A6%E5%A4%A7%E4%BA%8E0%EF%BC%89%EF%BC%8C%E4%B8%8D%E4%B8%BA%E7%A9%BA%E8%BF%94%E5%9B%9E%20true%E3%80%82%20%7C%20%5B%20-s%20%24file%20%5D%20%7C%0A%7C%20-e%20%7C%20%E6%A3%80%E6%B5%8B%E6%96%87%E4%BB%B6%EF%BC%88%E5%8C%85%E6%8B%AC%E7%9B%AE%E5%BD%95%EF%BC%89%E6%98%AF%E5%90%A6%E5%AD%98%E5%9C%A8%EF%BC%8C%E5%A6%82%E6%9E%9C%E6%98%AF%EF%BC%8C%E5%88%99%E8%BF%94%E5%9B%9E%20true%E3%80%82%20%7C%20%5B%20-e%20%24file%20%5D%20%7C%0A%0A%60%60%60python%0Aif%20%5B%20%24a%20-lt%205%20-o%20%24b%20-gt%20100%20%5D%0Athen%0A%20%20%20%20echo%20%22%24a%20-lt%20100%20-o%20%24b%20-gt%20100%20%3A%20returns%20true%22%0Aelse%0A%20%20%20%20echo%20%22%24a%20-lt%20100%20-o%20%24b%20-gt%20100%20%3A%20returns%20false%22%0Afi%0A%60%60%60%0A%0A%60%60%60python%0A%0Abasename%3A%0Abasename%20%2Fusr%2Fbin%2Fsort%20%20%20%20%20%20%20%20%20%20-%3E%20%22sort%22%0A%0Adirname%3A%0Adirname%20%2Fusr%2Fbin%2F%20%20%20%20%20%20%20%20%20%20-%3E%20%22%2Fusr%22%0A%0A-----------------------------------------------------------------%0A%0A%7C%20%E8%BF%90%E7%AE%97%E7%AC%A6%EF%BC%9A%0Acommand1%20%7C%20command2%0A%E4%BB%96%E7%9A%84%E5%8A%9F%E8%83%BD%E6%98%AF%E6%8A%8A%E7%AC%AC%E4%B8%80%E4%B8%AA%E5%91%BD%E4%BB%A4command1%20%E6%89%A7%E8%A1%8C%E7%9A%84%E7%BB%93%E6%9E%9C%20%E4%BD%9C%E4%B8%BAcommand2%E7%9A%84%20%E8%BE%93%E5%85%A5%20%E4%BC%A0%E7%BB%99command2%0Als%20-s%7Csort%20-nr%0A%E8%AF%A5%E5%91%BD%E4%BB%A4%E5%88%97%E5%87%BA%E5%BD%93%E5%89%8D%E7%9B%AE%E5%BD%95%E4%B8%AD%E7%9A%84%E6%96%87%E6%A1%A3(%E5%90%ABsize)%EF%BC%8C%E5%B9%B6%E6%8A%8A%E8%BE%93%E5%87%BA%E9%80%81%E7%BB%99sort%E5%91%BD%E4%BB%A4%E4%BD%9C%E4%B8%BA%E8%BE%93%E5%85%A5%EF%BC%8Csort%E5%91%BD%E4%BB%A4%E6%8C%89%E6%95%B0%E5%AD%97%E9%80%92%E5%87%8F%E7%9A%84%E9%A1%BA%E5%BA%8F%E6%8A%8Als%E7%9A%84%E8%BE%93%E5%87%BA%E6%8E%92%E5%BA%8F%E3%80%82%0A%0A---------------------------------------------------------------------%0A%26%26%20%E8%BF%90%E7%AE%97%E7%AC%A6%EF%BC%9A%0Acommand1%20%20%26%26%20command2%0A%26%26%E5%B7%A6%E8%BE%B9%E7%9A%84%E5%91%BD%E4%BB%A4%EF%BC%88%E5%91%BD%E4%BB%A41%EF%BC%89%E8%BF%94%E5%9B%9E%E7%9C%9F(%E5%8D%B3%E8%BF%94%E5%9B%9E0%EF%BC%8C%E6%88%90%E5%8A%9F%E8%A2%AB%E6%89%A7%E8%A1%8C%EF%BC%89%E5%90%8E%EF%BC%8C%26%26%E5%8F%B3%E8%BE%B9%E7%9A%84%E5%91%BD%E4%BB%A4%EF%BC%88%E5%91%BD%E4%BB%A42%EF%BC%89%E6%89%8D%E8%83%BD%E5%A4%9F%E8%A2%AB%E6%89%A7%E8%A1%8C%0A%0A%0A%7C%7C%20%E8%BF%90%E7%AE%97%E7%AC%A6%EF%BC%9A%0Acommand1%20%7C%7C%20command2%0A%7C%7C%E5%B7%A6%E8%BE%B9%E7%9A%84%E5%91%BD%E4%BB%A4%EF%BC%88command1%EF%BC%89%E6%9C%AA%E6%89%A7%E8%A1%8C%E6%88%90%E5%8A%9F%EF%BC%8C%E9%82%A3%E4%B9%88%E5%B0%B1%E6%89%A7%E8%A1%8C%7C%7C%E5%8F%B3%E8%BE%B9%E7%9A%84%E5%91%BD%E4%BB%A4%EF%BC%88command2%EF%BC%89%0A%0A%0A()%20%E8%BF%90%E7%AE%97%E7%AC%A6%EF%BC%9A%0A(command1%3Bcommand2%3Bcommand3....)%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%E5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%E4%BD%BF%E7%94%A8%E5%8F%8C%E6%8B%AC%E5%8F%B7%EF%BC%8C%20%E5%88%99%E4%B8%BAfor%20i%20in%20%60seq%200%204%60%E6%88%96%E8%80%85for%20i%20in%20%7B0..4%7D%E3%80%82%E5%86%8D%E5%A6%82%E5%8F%AF%E4%BB%A5%E7%9B%B4%E6%8E%A5%E4%BD%BF%E7%94%A8if%20((%24i%3C5))%EF%BC%8C%20%E5%A6%82%E6%9E%9C%E4%B8%8D%E4%BD%BF%E7%94%A8%E5%8F%8C%E6%8B%AC%E5%8F%B7%EF%BC%8C%20%E5%88%99%E4%B8%BAif%20%5B%20%24i%20-lt%205%20%5D%E3%80%82%0A%0A%0A%5B%5B%5D%5D%20%E8%BF%90%E7%AE%97%E7%AC%A6%EF%BC%9A%0A%5B%5B%20%5D%5D%20%E7%BB%93%E6%9E%84%E6%AF%94%5B%20%5D%E7%BB%93%E6%9E%84%E6%9B%B4%E5%8A%A0%E9%80%9A%E7%94%A8%0A%E6%AF%94%E5%A6%82%EF%BC%8C%26%26%E3%80%81%7C%7C%E3%80%81%3C%E5%92%8C%3E%20%E6%93%8D%E4%BD%9C%E7%AC%A6%E8%83%BD%E5%A4%9F%E6%AD%A3%E5%B8%B8%E5%AD%98%E5%9C%A8%E4%BA%8E%5B%5B%20%5D%5D%E6%9D%A1%E4%BB%B6%E5%88%A4%E6%96%AD%E7%BB%93%E6%9E%84%E4%B8%AD%0A%E5%8F%AF%E4%BB%A5%E7%9B%B4%E6%8E%A5%E4%BD%BF%E7%94%A8if%20%5B%5B%20%24a%20!%3D%201%20%26%26%20%24a%20!%3D%202%20%5D%5D%2C%20%E5%A6%82%E6%9E%9C%E4%B8%8D%E9%80%82%E7%94%A8%E5%8F%8C%E6%8B%AC%E5%8F%B7%2C%20%E5%88%99%E4%B8%BAif%20%5B%20%24a%20-ne%201%5D%20%26%26%20%5B%20%24a%20!%3D%202%20%5D%E6%88%96%E8%80%85if%20%5B%20%24a%20-ne%201%20-a%20%24a%20!%3D%202%20%5D%E3%80%82%0A%60%60%60%0A%0A%60%60%60python%0A%0A%3E%2Fdev%2Fnull%202%3E%261%0A%0A1%EF%BC%9A%3E%20%E4%BB%A3%E8%A1%A8%E9%87%8D%E5%AE%9A%E5%90%91%E5%88%B0%E5%93%AA%E9%87%8C%EF%BC%8C%E4%BE%8B%E5%A6%82%EF%BC%9Aecho%20%22123%22%20%3E%20%2Fhome%2F123.txt%0A2%EF%BC%9A%2Fdev%2Fnull%20%E4%BB%A3%E8%A1%A8%E7%A9%BA%E8%AE%BE%E5%A4%87%E6%96%87%E4%BB%B6%0A3%EF%BC%9A2%3E%20%E8%A1%A8%E7%A4%BAstderr%E6%A0%87%E5%87%86%E9%94%99%E8%AF%AF%0A4%EF%BC%9A%26%20%E8%A1%A8%E7%A4%BA%E7%AD%89%E5%90%8C%E4%BA%8E%E7%9A%84%E6%84%8F%E6%80%9D%EF%BC%8C2%3E%261%EF%BC%8C%E8%A1%A8%E7%A4%BA2%E7%9A%84%E8%BE%93%E5%87%BA%E9%87%8D%E5%AE%9A%E5%90%91%E7%AD%89%E5%90%8C%E4%BA%8E1%0A5%EF%BC%9A1%20%E8%A1%A8%E7%A4%BAstdout%E6%A0%87%E5%87%86%E8%BE%93%E5%87%BA%EF%BC%8C%E7%B3%BB%E7%BB%9F%E9%BB%98%E8%AE%A4%E5%80%BC%E6%98%AF1%EF%BC%8C%E6%89%80%E4%BB%A5%22%3E%2Fdev%2Fnull%22%E7%AD%89%E5%90%8C%E4%BA%8E%20%221%3E%2Fdev%2Fnull%22%0A%0A%0A%60%60%60%0A%0A%0A%0A%23%23%23%20%E5%AD%97%E7%AC%A6%E4%B8%B2%0A%60%60%60python%0A%23%20%E8%8E%B7%E5%8F%96%E5%AD%97%E7%AC%A6%E4%B8%B2%E9%95%BF%E5%BA%A6%0Astring%3D%22abcd%22%0Aecho%20%24%7B%23string%7D%20%23%E8%BE%93%E5%87%BA%204%0A%0A%23%20%E6%88%AA%E5%8F%96%E5%AD%97%E7%AC%A6%E4%B8%B2%0Astring%3D%22alibaba%20is%20a%20great%20company%22%0Aecho%20%24%7Bstring%3A1%3A4%7D%20%23%E8%BE%93%E5%87%BAliba%0A%0A%60%60%60%0A%0A%23%23%23%20%E6%95%B0%E7%BB%84%0A%60%60%60python%0A%0Aarray_name%3D(value0%20value1%20value2%20value3)%0A%0A%23%20%E4%BD%BF%E7%94%A8%40%20%E6%88%96%20*%20%E5%8F%AF%E4%BB%A5%E8%8E%B7%E5%8F%96%E6%95%B0%E7%BB%84%E4%B8%AD%E7%9A%84%E6%89%80%E6%9C%89%E5%85%83%E7%B4%A0%0A%24%7Barray_name%5B*%5D%7D%0A%24%7Barray_name%5B%40%5D%7D%0A%0A%0A%23%20%E5%8F%96%E5%BE%97%E6%95%B0%E7%BB%84%E5%85%83%E7%B4%A0%E7%9A%84%E4%B8%AA%E6%95%B0%0Alength%3D%24%7B%23array_name%5B%40%5D%7D%0A%0A%23%20%E5%8F%96%E5%BE%97%E6%95%B0%E7%BB%84%E5%8D%95%E4%B8%AA%E5%85%83%E7%B4%A0%E7%9A%84%E9%95%BF%E5%BA%A6%0Alengthn%3D%24%7B%23array_name%5Bn%5D%7D%0A%0A%60%60%60%0A%0A%0A%23%23%23%20case%20esac%E8%AF%AD%E5%8F%A5%0A%60%60%60python%0A%20%20%20%20case%20%24%7BACTION%7D%20in%0A%20%20%20%20war)%0A%20%20%20%20%20%20%20%20deploy_war%20%20%23%20%E5%87%BD%E6%95%B0%E7%9A%84%E8%B0%83%E7%94%A8%0A%20%20%20%20%20%20%20%20%3B%3B%0A%20%20%20%20min)%0A%20%20%20%20%20%20%20%20deploy_min%0A%20%20%20%20%20%20%20%20%3B%3B%0A%20%20%20%20web)%0A%20%20%20%20%20%20%20%20deploy_web%0A%20%20%20%20%20%20%20%20%3B%3B%0A%20%20%20%20restart)%0A%20%20%20%20%20%20%20%20stop_tomcat%0A%20%20%20%20%20%20%20%20start_tomcat%0A%20%20%20%20%20%20%20%20%3B%3B%0A%20%20%20%20*)%0A%20%20%20%20%20%20%20%20usage%0A%20%20%20%20%20%20%20%20%3B%3B%0A%20%20%20%20esac%0A%60%60%60%0A%0A%0A%23%23%23%20for%0A%60%60%60pyhon%0Afor%20loop%20in%201%202%203%204%205%0Ado%0A%20%20%20%20echo%20%22The%20value%20is%3A%20%24loop%22%0Adone%0A%60%60%60%0A%0A%23%23%23%20function%0A%60%60%60python%0Afunction%20test()%20%7B%0A%20%20%20%20local%20pids%20%3D%20%23%E5%91%BD%E5%90%8D%E5%8F%98%E9%87%8F%0A%20%20%20%20%0A%20%20%20%20sh%20startup.sh%20%3E%2Fdev%2Fnull%202%3E%261%20%20%23%20%E8%BF%90%E8%A1%8C%E8%84%9A%E6%9C%AC%0A%20%20%20%20%0A%20%20%20%20log%20%22stop%20tomcat%20success.%22%20%20%23%20%E8%BE%93%E5%87%BA%E6%97%A5%E5%BF%97%0A%7D%0A%0Atest%20%20%23%20%E8%B0%83%E7%94%A8%E5%87%BD%E6%95%B0%0A%0A%60%60%60%0A%0A%23%23%23%20%E9%87%8D%E5%AE%9A%E5%90%91%0A%0A%E4%B8%80%E8%88%AC%E6%83%85%E5%86%B5%E4%B8%8B%EF%BC%8C%E6%AF%8F%E4%B8%AA%20Unix%2FLinux%20%E5%91%BD%E4%BB%A4%E8%BF%90%E8%A1%8C%E6%97%B6%E9%83%BD%E4%BC%9A%E6%89%93%E5%BC%80%E4%B8%89%E4%B8%AA%E6%96%87%E4%BB%B6%EF%BC%9A%0A*%20%E6%A0%87%E5%87%86%E8%BE%93%E5%85%A5%E6%96%87%E4%BB%B6(stdin)%EF%BC%9Astdin%E7%9A%84%E6%96%87%E4%BB%B6%E6%8F%8F%E8%BF%B0%E7%AC%A6%E4%B8%BA0%EF%BC%8CUnix%E7%A8%8B%E5%BA%8F%E9%BB%98%E8%AE%A4%E4%BB%8Estdin%E8%AF%BB%E5%8F%96%E6%95%B0%E6%8D%AE%E3%80%82%0A*%20%E6%A0%87%E5%87%86%E8%BE%93%E5%87%BA%E6%96%87%E4%BB%B6(stdout)%EF%BC%9Astdout%20%E7%9A%84%E6%96%87%E4%BB%B6%E6%8F%8F%E8%BF%B0%E7%AC%A6%E4%B8%BA1%EF%BC%8CUnix%E7%A8%8B%E5%BA%8F%E9%BB%98%E8%AE%A4%E5%90%91stdout%E8%BE%93%E5%87%BA%E6%95%B0%E6%8D%AE%E3%80%82%0A*%20%E6%A0%87%E5%87%86%E9%94%99%E8%AF%AF%E6%96%87%E4%BB%B6(stderr)%EF%BC%9Astderr%E7%9A%84%E6%96%87%E4%BB%B6%E6%8F%8F%E8%BF%B0%E7%AC%A6%E4%B8%BA2%EF%BC%8CUnix%E7%A8%8B%E5%BA%8F%E4%BC%9A%E5%90%91stderr%E6%B5%81%E4%B8%AD%E5%86%99%E5%85%A5%E9%94%99%E8%AF%AF%E4%BF%A1%E6%81%AF%E3%80%82%0A%0A%7C%20%E5%91%BD%E4%BB%A4%20%7C%20%E8%AF%B4%E6%98%8E%20%7C%0A%7C%20---%20%7C%20---%20%7C%0A%7C%20command%20%3E%20file%20%7C%20%E5%B0%86%E8%BE%93%E5%87%BA%E9%87%8D%E5%AE%9A%E5%90%91%E5%88%B0%20file%E3%80%82%20%7C%0A%7C%20command%20%3C%20file%20%7C%20%E5%B0%86%E8%BE%93%E5%85%A5%E9%87%8D%E5%AE%9A%E5%90%91%E5%88%B0%20file%E3%80%82%7C%0A%7C%20command%20%3E%3E%20file%20%7C%20%E5%B0%86%E8%BE%93%E5%87%BA%E4%BB%A5%E8%BF%BD%E5%8A%A0%E7%9A%84%E6%96%B9%E5%BC%8F%E9%87%8D%E5%AE%9A%E5%90%91%E5%88%B0%20file%E3%80%82%7C%0A%0A%60%60%60python%0A%0A%0A%0A%0A%0A%0A%0A%60%60%60&lt;/center&gt;&lt;/div&gt;
</content>
  </entry>
  <entry xml:base="http://linzhiteng.postach.io/feed.xml">
    <title type="text">分支管理</title>
    <id>https://linzhiteng.postach.io/post/ben-di-xiang-mu-shang-chuan-dao-github</id>
    <updated>2019-10-11T08:51:19.133000Z</updated>
    <published>2019-04-02T09:37:20Z</published>
    <link href="https://linzhiteng.postach.io/post/ben-di-xiang-mu-shang-chuan-dao-github" />
    <author>
      <name>linzhi teng</name>
    </author>
    <category term="git" />
    <content type="html">&lt;div&gt;&lt;div style=&quot;font-size: 14px; margin: 0; padding: 0; width: 100%;&quot;&gt;&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;分支管理&lt;/h2&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;查看远程分支  &lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;git branch -a&lt;/code&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;查看本地分支 &lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;git branch&lt;/code&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;创建分支 &lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;git branch name&lt;/code&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;把分支推到远程库  &lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;git push orgin name&lt;/code&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;切换分支  &lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;git checkout name&lt;/code&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;删除本地分支  &lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;git branch -d name&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;本地项目上传到github&lt;/h2&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;在github上新建一个repository&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;
&lt;ol start=&quot;2&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;选择本地的一个目录进入，右键选择git bash here&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;
&lt;ol start=&quot;3&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;命令：&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;git clone 新建仓库的url
&lt;/code&gt;&lt;/pre&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;
&lt;ol start=&quot;4&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;完成3后，在目录下就会多一个仓库名的文件夹，将需要上传的项目的所有文件放到那个文件夹里&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;
&lt;ol start=&quot;5&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;cd 仓库的文件夹名&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;
&lt;ol start=&quot;6&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;输入命令&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;git add .
git commit -m &quot;提交的信息&quot;
git push -u origin master

&lt;/code&gt;&lt;/pre&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;
&lt;ol start=&quot;7&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;需要github输入用户名和密码&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;提交修改的代码到新建分支（原来的分支代码不变）&lt;/h2&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;git checkout -b newbrabch&lt;/p&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;git checkout oldbranch&lt;/p&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;git fetch origin&lt;/p&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;git reset --hard origin/oldbranch&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;暂时保存和恢复进度&lt;/h2&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;正在dev分支开发新功能，做到一半时有人过来反馈一个bug，让马上解决，但是新功能做到了一半你又不想提交，这时就可以使用git stash命令先把当前进度保存起来，然后切换到另一个分支去修改bug，修改完提交后，再切回dev分支，使用git stash pop来恢复之前的进度继续开发新功能。&lt;/p&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;git stash save 'msg'&lt;/p&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;git stash list&lt;/p&gt;
&lt;/div&gt;&lt;center style='display:none !important;visibility:collapse !important;height:0 !important;white-space:nowrap;width:100%;overflow:hidden'&gt;%23%23%20%E5%88%86%E6%94%AF%E7%AE%A1%E7%90%86%0A1.%20%E6%9F%A5%E7%9C%8B%E8%BF%9C%E7%A8%8B%E5%88%86%E6%94%AF%20%20%60git%20branch%20-a%60%0A2.%20%E6%9F%A5%E7%9C%8B%E6%9C%AC%E5%9C%B0%E5%88%86%E6%94%AF%20%60git%20branch%60%0A3.%20%E5%88%9B%E5%BB%BA%E5%88%86%E6%94%AF%20%60git%20branch%20name%60%0A4.%20%E6%8A%8A%E5%88%86%E6%94%AF%E6%8E%A8%E5%88%B0%E8%BF%9C%E7%A8%8B%E5%BA%93%20%20%60git%20push%20orgin%20name%60%0A5.%20%E5%88%87%E6%8D%A2%E5%88%86%E6%94%AF%20%20%60git%20checkout%20name%60%0A6.%20%E5%88%A0%E9%99%A4%E6%9C%AC%E5%9C%B0%E5%88%86%E6%94%AF%20%20%60git%20branch%20-d%20name%60%0A%0A%0A%0A%0A%23%23%20%E6%9C%AC%E5%9C%B0%E9%A1%B9%E7%9B%AE%E4%B8%8A%E4%BC%A0%E5%88%B0github%0A*%201.%20%E5%9C%A8github%E4%B8%8A%E6%96%B0%E5%BB%BA%E4%B8%80%E4%B8%AArepository%0A*%202.%20%E9%80%89%E6%8B%A9%E6%9C%AC%E5%9C%B0%E7%9A%84%E4%B8%80%E4%B8%AA%E7%9B%AE%E5%BD%95%E8%BF%9B%E5%85%A5%EF%BC%8C%E5%8F%B3%E9%94%AE%E9%80%89%E6%8B%A9git%20bash%20here%0A*%203.%20%E5%91%BD%E4%BB%A4%EF%BC%9A%0A%60%60%60%0Agit%20clone%20%E6%96%B0%E5%BB%BA%E4%BB%93%E5%BA%93%E7%9A%84url%0A%60%60%60%0A*%204.%20%E5%AE%8C%E6%88%903%E5%90%8E%EF%BC%8C%E5%9C%A8%E7%9B%AE%E5%BD%95%E4%B8%8B%E5%B0%B1%E4%BC%9A%E5%A4%9A%E4%B8%80%E4%B8%AA%E4%BB%93%E5%BA%93%E5%90%8D%E7%9A%84%E6%96%87%E4%BB%B6%E5%A4%B9%EF%BC%8C%E5%B0%86%E9%9C%80%E8%A6%81%E4%B8%8A%E4%BC%A0%E7%9A%84%E9%A1%B9%E7%9B%AE%E7%9A%84%E6%89%80%E6%9C%89%E6%96%87%E4%BB%B6%E6%94%BE%E5%88%B0%E9%82%A3%E4%B8%AA%E6%96%87%E4%BB%B6%E5%A4%B9%E9%87%8C%0A*%205.%20%60cd%20%E4%BB%93%E5%BA%93%E7%9A%84%E6%96%87%E4%BB%B6%E5%A4%B9%E5%90%8D%60%0A*%206.%20%E8%BE%93%E5%85%A5%E5%91%BD%E4%BB%A4%0A%60%60%60%0Agit%20add%20.%0Agit%20commit%20-m%20%22%E6%8F%90%E4%BA%A4%E7%9A%84%E4%BF%A1%E6%81%AF%22%0Agit%20push%20-u%20origin%20master%0A%0A%60%60%60%0A*%207.%20%E9%9C%80%E8%A6%81github%E8%BE%93%E5%85%A5%E7%94%A8%E6%88%B7%E5%90%8D%E5%92%8C%E5%AF%86%E7%A0%81%0A%0A%0A%0A%23%23%20%E6%8F%90%E4%BA%A4%E4%BF%AE%E6%94%B9%E7%9A%84%E4%BB%A3%E7%A0%81%E5%88%B0%E6%96%B0%E5%BB%BA%E5%88%86%E6%94%AF%EF%BC%88%E5%8E%9F%E6%9D%A5%E7%9A%84%E5%88%86%E6%94%AF%E4%BB%A3%E7%A0%81%E4%B8%8D%E5%8F%98%EF%BC%89%0A1.%20git%20checkout%20-b%20newbrabch%0A%0A2.%20git%20checkout%20oldbranch%0A%0A3.%20git%20fetch%20origin%0A%0A4.%20git%20reset%20--hard%20origin%2Foldbranch%0A%0A%23%23%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%8A%9F%E8%83%BD%E3%80%82%0A1.%20git%20stash%20save%20'msg'%0A%0A2.%20git%20stash%20list%20%20%E6%9F%A5%E7%9C%8B&lt;/center&gt;&lt;/div&gt;
</content>
  </entry>
  <entry xml:base="http://linzhiteng.postach.io/feed.xml">
    <title type="text">数据结构总结</title>
    <id>https://linzhiteng.postach.io/post/shu-ju-jie-gou-zong-jie</id>
    <updated>2019-04-01T07:48:42.142000Z</updated>
    <published>2019-04-01T07:41:39Z</published>
    <link href="https://linzhiteng.postach.io/post/shu-ju-jie-gou-zong-jie" />
    <author>
      <name>linzhi teng</name>
    </author>
    <category term="shu-ju-jie-gou" />
    <content type="html">&lt;div&gt;&lt;div style=&quot;font-size: 14px; margin: 0; padding: 0; width: 100%;&quot;&gt;&lt;div style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;数据结构
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;基本概念
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;分类
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;逻辑结构
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;存储结构
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;判断
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;数据的运算
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;数据结构详解
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.线性表
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.1 线性表的顺序存储（SeqList）
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.2 线性表的链式存储
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.2.1 单链表
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.2.2 双链表
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.3 改良顺序表与双链表(类似ArrayList和LinkedList)
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2. 栈(Stack)
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.1 顺序栈
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.2 链式栈
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.3 栈的应用
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.4 详细讲解
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3. 队列(Queue)
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1 顺序队列
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.2 链式队列（LinkedQueue）
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.3 优先队列(PriorityQueue)
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.4 详细讲解
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4. 集合(Set)
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.1 Hash
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.2 哈希表（散列表）
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.3 哈希表，哈希函数详细讲解
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;数据结构&lt;/h2&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;基本概念&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;相互之间存在一种或多种&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;特定关系&lt;/strong&gt;的数据&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;元素的集合&lt;/strong&gt;。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;按某种逻辑关系组织起来的一批数据（或称&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;带结构的数据元素的集合&lt;/strong&gt;）应用计算机语言并&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;按一定的存储表示方式&lt;/strong&gt;把它们存储在计算机的存储器中，&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;并在其上定义了一个运算&lt;/strong&gt;的集合。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;数据逻辑结构，数据存储结构，数据的运算称为数据结构&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;三要素&lt;/strong&gt;。&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;分类&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/9ea3fe73-d9c6-4a89-a247-c8fb97dfd11b/ec50783d-805f-4311-be2d-4809cf4cb261.jpg&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/9ea3fe73-d9c6-4a89-a247-c8fb97dfd11b/05772bf5-ca70-49b2-be6f-090acce5f8ed.jpg&quot; /&gt;&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;逻辑结构&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;数据元素间抽象化的相互关系&lt;/strong&gt;简称为逻辑结构。 与数据的存储无关，独立于计算机，它是从具体问题抽象出来的&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;数学模型&lt;/strong&gt;。&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;1.线性结构：有且只有一个开始结点和一个终端结点，并且所有结点都最多只有一个直接前驱和一个直接后继。&lt;br/&gt;
2.非线性存储：每个结点可以有不止一个直接前驱和直接后继。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;存储结构&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;存储结构是指数据结构在计算机中的表示（又称映像），也称物理结构。它包括数据元素的表示和关系的表示。数据的存储结构是&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;逻辑结构用计算机语言的实现&lt;/strong&gt;，它依赖于计算机语言。&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;顺序存储：把逻辑上相邻的元素存储在物理位置上也&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;相邻的存储单元&lt;/strong&gt;里，元素之间的关系由存储单元的邻接关系来体现。其优点是可以实现随机存取，每个元素占用最少的存储空间；缺点是只能使用相邻的一整块存储单元，因此可能产生较多的外部碎片。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;链接存储：不要求逻辑上相邻的元素在物理位置上也相邻，借助&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;指示元素存储地址的指针&lt;/strong&gt;表示元素之间的逻辑关系。其优点是不会出现碎片现象，充分利用所有存储单元；缺点是每个元素因存储指针而占用额外的存储空间，并且只能实现顺序存取。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;索引存储：在存储元素信息的同时，还&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;建立附加的索引表&lt;/strong&gt;。索引表中的每一项称为索引项，索引项的一般形式是：（关键字，地址）。其优点是检索速度快；缺点是增加了附加的索引表，会占用较多的存储空间。另外，在增加和删除数据时要修改索引表，因而会花费较多的时间。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;散列存储：根据元素的关键字直接计算出该元素的存储地址，又称为&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;Hash存储&lt;/strong&gt;。其优点是检索、增加和删除结点的操作都很快；缺点是如果散列函数不好可能出现元素存储单元的冲突，而解决冲突会增加时间和空间开销。&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;判断&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;当一个结构，如数组、链表、树、图，在逻辑结构中只有一种定义，而在物理结构中却有两种选择，那么这个结构就属于逻辑结构；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;相反，当此结构在原有基础上加上了某种限定，使得其在物理结构中只有一种定义，那么这个结构就属于物理（存储）结构；&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;数据的运算&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;施加在数据上的运算包括运算的&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;定义&lt;/strong&gt;和&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;实现&lt;/strong&gt;。&lt;br/&gt;
运算的&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;定义是针对逻辑结构&lt;/strong&gt;的，指出运算的功能；&lt;br/&gt;
运算的&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;实现是针对存储结构&lt;/strong&gt;的，指出运算的具体操作步骤。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;数据结构详解&lt;/h2&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.线性表&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;线性表是由n(n&gt;=0)个&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;类型相同&lt;/strong&gt;的数据元素a0,a1,…,an-1组成的&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;有限的序列&lt;/strong&gt;，在数学中记作(a0,a1,…,an-1)，其中ai的数据类型可以是基本数据类型(int,float等)、字符或类。n代表线性表的元素个数，也称其为长度(Length)。若n=0，则为空表；若n &gt; 0，则ai(0 &lt; i &lt; n-1)&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;有且仅有一个前驱&lt;/strong&gt;(Predecessor)元素ai-1和&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;一个后继&lt;/strong&gt;(Successor)元素ai+1，a0没有前驱元素，ai没有后继元素。&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;1.1 线性表的顺序存储（SeqList）&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;顺序存储结构底层是利用数组来实现的，而数组可以存储具有相同数据类型的元素集合，如int，float或者自定义类型等，当我们创建一个数组时，计算机操作系统会为该数组分配一块连续的内存块，这也就意味着数组中的每个存储单元的地址都是连续的，因此只要知道了数组的起始内存地址就可以通过简单的乘法和加法计算出数组中第n-1个存储单元的内存地址&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;线性表的顺序存储结构称之为&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;顺序表&lt;/strong&gt;(Sequential List),它使用&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;一维数组&lt;/strong&gt;依次存放从a0到an-1的数据元素(a0,a1,…,an-1)，将ai(0&lt;i&lt; n-1)存放在数组的第i个元素，使得ai与其前驱ai-1及后继ai+1的存储位置相邻，因此数据元素在内存的物理存储次序反映了线性表数据元素之间的逻辑次序。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;1.2 线性表的链式存储&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/9ea3fe73-d9c6-4a89-a247-c8fb97dfd11b/6231b16b-6077-49bc-9c44-794643f76a8e.png&quot; /&gt;&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;当创建顺序表时必须分配一块连续的内存存储空间，而当顺序表内部数组的容量不足时，则必须创建一个新的数组，然后把原数组的的元素复制到新的数组中，这将浪费大量的时间。而在插入或删除元素时，可能需要移动数组中的元素，这也将消耗一定的时间。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;鉴于这种种原因，于是&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;链表&lt;/strong&gt;就出场了，链表在初始化时仅需要分配一个元素的存储空间，并且插入和删除新的元素也相当便捷，同时链表在内存分配上可以是不连续的内存，也不需要做任何内存复制和重新分配的操作。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;线性链表的&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;存储结构&lt;/strong&gt;是用若干个&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;地址分散&lt;/strong&gt;的存储单元存放数据元素的，逻辑上相邻的数据元素在物理位置上不一定相邻，因此每个存储单元中都会有一个地址指向域，这个地址指向域指明其后继元素的位置。在链表中存储数据的单元称为&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;结点&lt;/strong&gt;(Node)，从图中可以看出一个结点至少包含了数据域和地址域，其中数据域用于存储数据，而地址域用于存储前驱或后继元素的地址。&lt;/li&gt;
&lt;/ul&gt;
&lt;h6 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 13px; color: #333;&quot;&gt;1.2.1 单链表&lt;/h6&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;单链表(SingleILinkedList)&lt;/strong&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;带头结点的单链表(HeadSingleILinkedList)&lt;/strong&gt;&lt;br/&gt;
头结点：一个没有值的结点&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;循环单链表(CircularHeadSILinkedList)&lt;/strong&gt;&lt;br/&gt;
链表中的最后一个结点的next域指向了头结点head，形成环形的结构&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;详细讲解：&lt;a href=&quot;https://blog.csdn.net/javazejian/article/details/52953190&quot; style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;顺序表与单链表详细讲解与实现&lt;/a&gt;&lt;/p&gt;
&lt;h6 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 13px; color: #333;&quot;&gt;1.2.2 双链表&lt;/h6&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;在单链表分析中，我们可以知道每个结点只有一个指向后继结点的next域，倘若此时已知当前结点p，需要查找其前驱结点，那么就必须从head头指针遍历至p的前驱结点，操作的效率很低，因此如果p有一个指向前驱结点的next域，那效率就高多了，对于这种一个&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;结点中分别包含了前驱结点域pre和后继结点域next&lt;/strong&gt;的链表，称之为双链表。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;双链表的主要优点是对于任意给的结点，都可以很轻易的获取其前驱结点或者后继结点，而主要缺点是每个结点需要添加额外的next域，因此需要更多的空间开销，同时结点的插入与删除操作也将更加耗时，因为需要更多的指针指向操作。&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;双链表(HeadDoubleILinkedList)&lt;/strong&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;循环双链表(LoopHeadDILinkedList)&lt;/strong&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;排序循环双链表(SortLoopHeadDIlinkedList)&lt;/strong&gt;&lt;br/&gt;
排序循环双链表指的是在插入元素时，不再根据index标志，而是根据值的大小寻找插入位置，但是有个插入值data必须是T或者T的父类而且实现了Comoarable接口。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;异或高效存储双链表(XORNode)&lt;/strong&gt;&lt;br/&gt;
双链表的实现中，都是需要一个指向后继结点的正向指针和一个指向前驱结点的反向指针，我们在构造一个结点类时需要一个数据域data、一个指向后继结点的指针next以及一个指向前驱结点的指针prev。但为了设计更高效节省存储空间，一种基于&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;指针差运算&lt;/strong&gt;存储高效的双向链表就诞生了。这种链表的每个结点仍然与单链表一样,仅使用一个指针域来设计双向链表。&lt;br/&gt;
结点中的ptrdiff字段存储了&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;后继结点与前驱结点的地址差&lt;/strong&gt;，指针的差通过异或运算来实现。&lt;br/&gt;
&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;pridiff=后继结点的地址⊕前驱结点的地址&lt;/strong&gt;&lt;br/&gt;
还未实现&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;详细讲解：&lt;a href=&quot;https://blog.csdn.net/javazejian/article/details/53047590&quot; style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;双链表详细讲解与实现&lt;/a&gt;&lt;/p&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;1.3 改良顺序表与双链表(类似ArrayList和LinkedList)&lt;/h5&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a href=&quot;https://blog.csdn.net/javazejian/article/details/53073995&quot; style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;改良顺序表与双链表类似ArrayList和LinkedList(Iterator迭代器与fast-fail机制)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2. 栈(Stack)&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/9ea3fe73-d9c6-4a89-a247-c8fb97dfd11b/b7e0edcd-6a92-4036-a8cf-e1730070ebbf.png&quot; /&gt;&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; color: #333; margin: 0;&quot;&gt;可以认为栈(Stack)是一种特殊的线性表，其插入和删除操作只允许在线性表的一端进行，一般而言，把允许操作的一端称为栈顶(Top)，不可操作的一端称为栈底(Bottom)，同时把插入元素的操作称为入栈(Push),删除元素的操作称为出栈(Pop)。若栈中没有任何元素，则称为空栈。&lt;/p&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; color: #333; margin: 0;&quot;&gt;栈(Stack)是一种有序特殊的线性表，只能在表的一端(称为栈顶，top，总是指向栈顶元素)执行插入和删除操作，最后插入的元素将第一个被删除，因此栈也称为后进先出(Last In First Out,LIFO)或先进后出(First In Last Out FILO)的线性表。&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;2.1 顺序栈&lt;/h5&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;顺序栈，顾名思义就是采用顺序表实现的的栈，顺序栈的内部&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;以顺序表为基础&lt;/strong&gt;，实现对元素的存取操作。当然我们还可以&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;采用内部数组&lt;/strong&gt;实现顺序栈。&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;顺序表实现(StackByArrayList)&lt;/strong&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;内部数组实现(SeqStack)&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;2.2 链式栈&lt;/h5&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;链式栈（Linked Stack），就是采用链式存储结构的栈，由于我们操作的是栈顶一端，因此这里采用单链表（不带头结点）作为基础即可。&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;单链表实现(LinkedStackBySingleLinkedList)&lt;/strong&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;结点实现(LinkedStack)&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;2.3 栈的应用&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;符号匹配（CheckExpression）&lt;/strong&gt;&lt;br/&gt;
在编写程序的过程中，我们经常会遇到诸如圆括号&quot;()&quot;与花括号&quot;{}&quot;，这些符号都必须是左右匹配的，这就是我们所说的符合匹配类型，当然符合不仅需要个数相等，而且需要先左后右的依次出现，否则就不符合匹配规则&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;中缀表达式转换为后缀表达式(CalculateExpression)&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;2.4 详细讲解&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;a href=&quot;https://blog.csdn.net/javazejian/article/details/53362993&quot; style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;栈的详细详解与实现&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3. 队列(Queue)&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;队列是一种特殊的线性表，其插入和删除的操作分别在表的两端进行，队列的特点就是先进先出(First In First Out)。我们把向队列中插入元素的过程称为入队(Enqueue)，删除元素的过程称为出队(Dequeue)并把允许入队的一端称为队尾，允许出的的一端称为队头，没有任何元素的队列则称为空队。&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;3.1 顺序队列&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;单队列&lt;br/&gt;
采用顺序表实现队列时，入队操作直接执行顺序表尾部插入操作，其时间复杂度为O(1)，出队操作直接执行顺序表头部删除操作，其时间复杂度为O(n)，主要用于移动元素，效率低，既然如此，我们就把出队的时间复杂度降为O(1)即可，为此在顺序表中添加一个头指向下标front和尾指向下标，出队和入队时只要改变front、rear的下标指向取值即可，此时无需移动元素，因此出队的时间复杂度也就变为O(1)。&lt;br/&gt;
通过给顺序表添加front和rear变量记录下标后使用得出队操作的时间复杂度降为O(1)，但是却出现了另外一个严重的问题，那就是空间浪费。&lt;br/&gt;
遗留下来的空间并没有被重新利用，反而是空着，出现队列已满的假现象，这种假现象我们称之为&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;假溢出&lt;/strong&gt;，之所以出现这样假溢出的现象是因为顺序表队列的存储单元没有重复利用机制，而解决该问题的最合适的方式就是将顺序队列设计为循环结构。&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol start=&quot;2&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;循环队列（SeqQueue）&lt;/strong&gt;&lt;br/&gt;
顺序循环队列就是将顺序队列设计为在逻辑结构上收尾相接的循环结构，这样我们就可以重复利用存储单元。&lt;br/&gt;
循环队列有以下计算关系&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;//其中front、rear的下标的取值范围是0~size-1，不会造成假溢出。
front=(front+1)%size;//队头下标
rear=(rear+1)%size;  //下一个入队元素的下标
&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;a. front为队头元素的下标，rear则指向下一个入队元素的下标&lt;br/&gt;
b. 当front=rear时，我们约定队列为空。&lt;br/&gt;
c. 出队操作改变front下标指向，入队操作改变rear下标指向，size代表队列容量。&lt;br/&gt;
d. 约定队列满的条件为front=(rear+1)%size,注意此时队列中仍有一个空的位置，此处留一个空位主要用于避免与队列空的条件front=rear相同。&lt;br/&gt;
e. 队列内部的数组可扩容，并按照原来队列的次序复制元素数组&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;3.2 链式队列（LinkedQueue）&lt;/h5&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;链式队列，将使用带头指针front和尾指针rear的单链表实现，front直接指向队头的第一个元素，rear指向队尾的最后一个元素。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;设计链式队列&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;a. 分别设置front和rear指向队头结点和队尾结点，使用单链表的头尾访问时间复杂度为O(1)&lt;br/&gt;
b. 设置初始化空队列，使用front=rear=null，并且约定条件front==null&amp;&amp;rear==null成立时，队列为空。&lt;br/&gt;
c. 当第一个元素入队或者最后一个元素出队时，同时更新front指针和rear指针的指向。&lt;br/&gt;
d. 入队操作时，使插入元素的结点在rear之后并更新rear指针指向新插入元素。&lt;br/&gt;
e. 出队操作时，若队列不为空获取队头结点元素，并删除队头结点元素，更新front指针的指向为front=front.next&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;3.3 优先队列(PriorityQueue)&lt;/h5&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;优先级队列也是一种特殊的数据结构，队列中的每个元素都有一个优先级，若每次出队的是具有最高优先级的元素，则称为降序优先级队列(总是先删除最大的元素)。若每次出队的是值最小的元素，则称为升序优先级队列(总是先删除最小的元素)，通常情况下我们所说的优先队列，一般是指降序优先级队列。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;使用之前分析过的MyLikedList作为基底，实现一个排序的SortLinkedList继承自MyLinkedList，这里需要注意的是排序链表中的T类型必须是实现了Comparable接口的类型，在SortLinkedList中主要重写添加的add方法，插入逻辑是，通过比较元素的大小加入，而非简单下标或尾部插入。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;接着以SortMyLinkedList为基底实现优先队列PriorityQueue&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;3.4 详细讲解&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;a href=&quot;https://blog.csdn.net/javazejian/article/details/53375004&quot; style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;队列的详细讲解与实现&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;4. 集合(Set)&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;集合，是由一堆无序的、相关联的，且不重复的内存结构【数学中称为元素】组成的组合；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;集合分类&lt;br/&gt;
&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;有序集合&lt;/strong&gt;：集合里的元素可以根据 key 或 index 访问 (&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;List、Map&lt;/strong&gt;)&lt;br/&gt;
&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;无序集合&lt;/strong&gt;：集合里的元素只能遍历。(&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;Set&lt;/strong&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.1 Hash&lt;/h5&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;Hash（哈希），又称&quot;散列&quot;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;在某种程度上，散列是与排序相反的一种操作，排序是将集合中的元素按照某种方式比如字典顺序排列在一起，而散列通过计算哈希值，打破元素之间原有的关系，使集合中的元素按照散列函数的分类进行排列。&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;为什么要有 Hash&lt;/strong&gt;&lt;br/&gt;
我们通常使用数组或者链表来存储元素，一旦存储的内容数量特别多，需要占用很大的空间，而且在&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;查找某个元素&lt;/strong&gt;是否存在的过程中，数组和链表都需要挨个循环比较，而通过 哈希 计算，可以大大&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;减少比较次数&lt;/strong&gt;。&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol start=&quot;2&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;哈希函数&lt;/strong&gt;&lt;br/&gt;
哈希的过程中需要使用哈希函数进行计算。哈希函数是一种映射关系，&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;根据数据的关键词 key&lt;/strong&gt; ，&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;通过一定的函数关系&lt;/strong&gt;，&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;计算出该元素存储位置的函数&lt;/strong&gt;。&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol start=&quot;3&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;几种常见的哈希函数（散列函数）构造方法&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;直接定址法 &lt;br/&gt;
H(key) = key 或 H(key) = a*key + b&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;除留余数法&lt;br/&gt;
H(key) = key % p, p &lt; m&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;数字分析法&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;平方取中法&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;折叠法（叠加法）&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;随机数法&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol start=&quot;4&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;哈希冲突的解决&lt;/strong&gt;&lt;br/&gt;
选用哈希函数计算哈希值时，可能不同的 key 会得到相同的结果，一个地址怎么存放多个数据呢？这就是&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;冲突&lt;/strong&gt;。&lt;/li&gt;
&lt;/ol&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;链接法（拉链法）&lt;/strong&gt;&lt;br/&gt;
&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;将所有关键字为同义词的结点链接在同一个单链表中&lt;/strong&gt;。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;若选定的散列表长度为 m,则可将散列表定义为一个由m个头指针组成的指针数组 T[0..m-1] 。
凡是散列地址为 i 的结点，均插入到以 T[i] 为头指针的单链表中。 T 中各分量的初值均应为空指针。T 中各分量的初值均应为空指针。
&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/9ea3fe73-d9c6-4a89-a247-c8fb97dfd11b/0badfc13-16ab-4024-86c4-61df0977939c.jpg&quot; /&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;开放定址法&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.2 哈希表（散列表）&lt;/h5&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;哈希表是实现关联数组（associative array）的一种数据结构，广泛应用于实现数据的快速查找。&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/9ea3fe73-d9c6-4a89-a247-c8fb97dfd11b/50f6e2fa-9321-41d1-973c-44fb938abde0.jpg&quot; /&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;用哈希函数计算关键字的哈希值（hash value）,通过哈希值这个索引就可以找到关键字的存储位置，即桶（bucket）。在哈希表上的插入、查找、删除等操作的时间复杂度是 O(1)。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;查找过程中，关键字的比较次数，取决于产生冲突的多少，产生的冲突少，查找效率就高，产生的冲突多，查找效率就低。因此，&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;影响产生冲突多少的因素，也就是影响查找效率的因素&lt;/strong&gt;。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0;&quot;&gt;影响产生冲突多少有以下三个因素：&lt;/p&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;哈希函数是否均匀；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;处理冲突的方法；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;哈希表的加载因子。&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;哈希表的加载因子和容量决定了在什么时候桶数（存储位置）不够，需要重新哈希。加载因子太大的话桶太多，遍历时效率变低；太小的话频繁 rehash，导致性能降低。所以加载因子的大小需要结合时间和空间效率考虑。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;例子：&lt;br/&gt;
桶不是在扩容时产生的，而是一个新元素在通过哈希计算后得到的一个新位置。 哈希函数合适的情况下，当然是使用哈希函数进行计算的元素越多桶就越多喽，举个极端的例子：HashMap 默认容量的情况下，如果加载因子为 0.1 ，只能放一个 16 * 0.1 = 1 个元素，哈希计算后一定就只有一个桶。那如果加载因子是 0.75，16 * 0.75 = 12 个元素，哈希计算后的桶基本上比 加载因子为 0.1 的多喽，你看是不是。 2. 桶多了单链表长度是短一些，但是这是不发生冲突的前提，如果哈希函数选择的不够合适，太多元素经过哈希计算可能会多次冲突，这样即使桶多了，也不能避免某个链表过长的情况。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.3 哈希表，哈希函数详细讲解&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;a href=&quot;https://blog.csdn.net/u011240877/article/details/52940469&quot; style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;哈希表，哈希函数详细讲解&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/div&gt;&lt;center style='display:none !important;visibility:collapse !important;height:0 !important;white-space:nowrap;width:100%;overflow:hidden'&gt;%5Btoc%5D%0A%23%23%20%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%0A%23%23%23%23%20%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5%0A%3E1.%20%E7%9B%B8%E4%BA%92%E4%B9%8B%E9%97%B4%E5%AD%98%E5%9C%A8%E4%B8%80%E7%A7%8D%E6%88%96%E5%A4%9A%E7%A7%8D**%E7%89%B9%E5%AE%9A%E5%85%B3%E7%B3%BB**%E7%9A%84%E6%95%B0%E6%8D%AE**%E5%85%83%E7%B4%A0%E7%9A%84%E9%9B%86%E5%90%88**%E3%80%82%0A%3E%202.%20%E6%8C%89%E6%9F%90%E7%A7%8D%E9%80%BB%E8%BE%91%E5%85%B3%E7%B3%BB%E7%BB%84%E7%BB%87%E8%B5%B7%E6%9D%A5%E7%9A%84%E4%B8%80%E6%89%B9%E6%95%B0%E6%8D%AE%EF%BC%88%E6%88%96%E7%A7%B0**%E5%B8%A6%E7%BB%93%E6%9E%84%E7%9A%84%E6%95%B0%E6%8D%AE%E5%85%83%E7%B4%A0%E7%9A%84%E9%9B%86%E5%90%88**%EF%BC%89%E5%BA%94%E7%94%A8%E8%AE%A1%E7%AE%97%E6%9C%BA%E8%AF%AD%E8%A8%80%E5%B9%B6**%E6%8C%89%E4%B8%80%E5%AE%9A%E7%9A%84%E5%AD%98%E5%82%A8%E8%A1%A8%E7%A4%BA%E6%96%B9%E5%BC%8F**%E6%8A%8A%E5%AE%83%E4%BB%AC%E5%AD%98%E5%82%A8%E5%9C%A8%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%9A%84%E5%AD%98%E5%82%A8%E5%99%A8%E4%B8%AD%EF%BC%8C**%E5%B9%B6%E5%9C%A8%E5%85%B6%E4%B8%8A%E5%AE%9A%E4%B9%89%E4%BA%86%E4%B8%80%E4%B8%AA%E8%BF%90%E7%AE%97**%E7%9A%84%E9%9B%86%E5%90%88%E3%80%82%0A%3E%203.%20%E6%95%B0%E6%8D%AE%E9%80%BB%E8%BE%91%E7%BB%93%E6%9E%84%EF%BC%8C%E6%95%B0%E6%8D%AE%E5%AD%98%E5%82%A8%E7%BB%93%E6%9E%84%EF%BC%8C%E6%95%B0%E6%8D%AE%E7%9A%84%E8%BF%90%E7%AE%97%E7%A7%B0%E4%B8%BA%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84**%E4%B8%89%E8%A6%81%E7%B4%A0**%E3%80%82%0A%0A%23%23%23%23%20%E5%88%86%E7%B1%BB%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/9ea3fe73-d9c6-4a89-a247-c8fb97dfd11b/ec50783d-805f-4311-be2d-4809cf4cb261.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F635%3A1)%0A%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/9ea3fe73-d9c6-4a89-a247-c8fb97dfd11b/05772bf5-ca70-49b2-be6f-090acce5f8ed.jpg.jpeg%5D(en-resource%3A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80%80%E3%80%80%E3%80%80%E3%80%80%E3%80%80%E3%80%80%E3%80%80%E3%80%80%0A*%20%E7%9B%B8%E5%8F%8D%EF%BC%8C%E5%BD%93%E6%AD%A4%E7%BB%93%E6%9E%84%E5%9C%A8%E5%8E%9F%E6%9C%89%E5%9F%BA%E7%A1%80%E4%B8%8A%E5%8A%A0%E4%B8%8A%E4%BA%86%E6%9F%90%E7%A7%8D%E9%99%90%E5%AE%9A%EF%BC%8C%E4%BD%BF%E5%BE%97%E5%85%B6%E5%9C%A8%E7%89%A9%E7%90%86%E7%BB%93%E6%9E%84%E4%B8%AD%E5%8F%AA%E6%9C%89%E4%B8%80%E7%A7%8D%E5%AE%9A%E4%B9%89%EF%BC%8C%E9%82%A3%E4%B9%88%E8%BF%99%E4%B8%AA%E7%BB%93%E6%9E%84%E5%B0%B1%E5%B1%9E%E4%BA%8E%E7%89%A9%E7%90%86%EF%BC%88%E5%AD%98%E5%82%A8%EF%BC%89%E7%BB%93%E6%9E%84%EF%BC%9B%0A%0A%23%23%23%23%20%E6%95%B0%E6%8D%AE%E7%9A%84%E8%BF%90%E7%AE%97%0A%3E%E6%96%BD%E5%8A%A0%E5%9C%A8%E6%95%B0%E6%8D%AE%E4%B8%8A%E7%9A%84%E8%BF%90%E7%AE%97%E5%8C%85%E6%8B%AC%E8%BF%90%E7%AE%97%E7%9A%84**%E5%AE%9A%E4%B9%89**%E5%92%8C**%E5%AE%9E%E7%8E%B0**%E3%80%82%0A%3E%E8%BF%90%E7%AE%97%E7%9A%84**%E5%AE%9A%E4%B9%89%E6%98%AF%E9%92%88%E5%AF%B9%E9%80%BB%E8%BE%91%E7%BB%93%E6%9E%84**%E7%9A%84%EF%BC%8C%E6%8C%87%E5%87%BA%E8%BF%90%E7%AE%97%E7%9A%84%E5%8A%9F%E8%83%BD%EF%BC%9B%0A%3E%E8%BF%90%E7%AE%97%E7%9A%84**%E5%AE%9E%E7%8E%B0%E6%98%AF%E9%92%88%E5%AF%B9%E5%AD%98%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E%200%EF%BC%8C%E5%88%99ai(0%20%3C%20i%20%3C%20n-1)**%E6%9C%89%E4%B8%94%E4%BB%85%E6%9C%89%E4%B8%80%E4%B8%AA%E5%89%8D%E9%A9%B1**(Predecessor)%E5%85%83%E7%B4%A0ai-1%E5%92%8C**%E4%B8%80%E4%B8%AA%E5%90%8E%E7%BB%A7**(Successor)%E5%85%83%E7%B4%A0ai%2B1%EF%BC%8Ca0%E6%B2%A1%E6%9C%89%E5%89%8D%E9%A9%B1%E5%85%83%E7%B4%A0%EF%BC%8Cai%E6%B2%A1%E6%9C%89%E5%90%8E%E7%BB%A7%E5%85%83%E7%B4%A0%E3%80%82%0A%0A%23%23%23%23%23%201.1%20%E7%BA%BF%E6%80%A7%E8%A1%A8%E7%9A%84%E9%A1%BA%E5%BA%8F%E5%AD%98%E5%82%A8%EF%BC%88SeqList%EF%BC%89%0A%3E%E9%A1%BA%E5%BA%8F%E5%AD%98%E5%82%A8%E7%BB%93%E6%9E%84%E5%BA%95%E5%B1%82%E6%98%AF%E5%88%A9%E7%94%A8%E6%95%B0%E7%BB%84%E6%9D%A5%E5%AE%9E%E7%8E%B0%E7%9A%84%EF%BC%8C%E8%80%8C%E6%95%B0%E7%BB%84%E5%8F%AF%E4%BB%A5%E5%AD%98%E5%82%A8%E5%85%B7%E6%9C%89%E7%9B%B8%E5%90%8C%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E7%9A%84%E5%85%83%E7%B4%A0%E9%9B%86%E5%90%88%EF%BC%8C%E5%A6%82int%EF%BC%8Cfloat%E6%88%96%E8%80%85%E8%87%AA%E5%AE%9A%E4%B9%89%E7%B1%BB%E5%9E%8B%E7%AD%89%EF%BC%8C%E5%BD%93%E6%88%91%E4%BB%AC%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E6%95%B0%E7%BB%84%E6%97%B6%EF%BC%8C%E8%AE%A1%E7%AE%97%E6%9C%BA%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%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D%AE%E5%85%83%E7%B4%A0(a0%2Ca1%2C%E2%80%A6%2Can-1)%EF%BC%8C%E5%B0%86ai(0%3Ci%3C%20n-1)%E5%AD%98%E6%94%BE%E5%9C%A8%E6%95%B0%E7%BB%84%E7%9A%84%E7%AC%ACi%E4%B8%AA%E5%85%83%E7%B4%A0%EF%BC%8C%E4%BD%BF%E5%BE%97ai%E4%B8%8E%E5%85%B6%E5%89%8D%E9%A9%B1ai-1%E5%8F%8A%E5%90%8E%E7%BB%A7ai%2B1%E7%9A%84%E5%AD%98%E5%82%A8%E4%BD%8D%E7%BD%AE%E7%9B%B8%E9%82%BB%EF%BC%8C%E5%9B%A0%E6%AD%A4%E6%95%B0%E6%8D%AE%E5%85%83%E7%B4%A0%E5%9C%A8%E5%86%85%E5%AD%98%E7%9A%84%E7%89%A9%E7%90%86%E5%AD%98%E5%82%A8%E6%AC%A1%E5%BA%8F%E5%8F%8D%E6%98%A0%E4%BA%86%E7%BA%BF%E6%80%A7%E8%A1%A8%E6%95%B0%E6%8D%AE%E5%85%83%E7%B4%A0%E4%B9%8B%E9%97%B4%E7%9A%84%E9%80%BB%E8%BE%91%E6%AC%A1%E5%BA%8F%E3%80%82%0A%0A%23%23%23%23%23%201.2%20%E7%BA%BF%E6%80%A7%E8%A1%A8%E7%9A%84%E9%93%BE%E5%BC%8F%E5%AD%98%E5%82%A8%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/9ea3fe73-d9c6-4a89-a247-c8fb97dfd11b/6231b16b-6077-49bc-9c44-794643f76a8e.png.png%5D(en-resource%3A%2F%2Fdatabase%2F636%3A1)%0A%0A*%20%E5%BD%93%E5%88%9B%E5%BB%BA%E9%A1%BA%E5%BA%8F%E8%A1%A8%E6%97%B6%E5%BF%85%E9%A1%BB%E5%88%86%E9%85%8D%E4%B8%80%E5%9D%97%E8%BF%9E%E7%BB%AD%E7%9A%84%E5%86%85%E5%AD%98%E5%AD%98%E5%82%A8%E7%A9%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%A4%E6%AF%8F%E4%B8%AA%E5%AD%98%E5%82%A8%E5%8D%95%E5%85%83%E4%B8%AD%E9%83%BD%E4%BC%9A%E6%9C%89%E4%B8%80%E4%B8%AA%E5%9C%B0%E5%9D%80%E6%8C%87%E5%90%91%E5%9F%9F%EF%BC%8C%E8%BF%99%E4%B8%AA%E5%9C%B0%E5%9D%80%E6%8C%87%E5%90%91%E5%9F%9F%E6%8C%87%E6%98%8E%E5%85%B6%E5%90%8E%E7%BB%A7%E5%85%83%E7%B4%A0%E7%9A%84%E4%BD%8D%E7%BD%AE%E3%80%82%E5%9C%A8%E9%93%BE%E8%A1%A8%E4%B8%AD%E5%AD%98%E5%82%A8%E6%95%B0%E6%8D%AE%E7%9A%84%E5%8D%95%E5%85%83%E7%A7%B0%E4%B8%BA**%E7%BB%93%E7%82%B9**(Node)%EF%BC%8C%E4%BB%8E%E5%9B%BE%E4%B8%AD%E5%8F%AF%E4%BB%A5%E7%9C%8B%E5%87%BA%E4%B8%80%E4%B8%AA%E7%BB%93%E7%82%B9%E8%87%B3%E5%B0%91%E5%8C%85%E5%90%AB%E4%BA%86%E6%95%B0%E6%8D%AE%E5%9F%9F%E5%92%8C%E5%9C%B0%E5%9D%80%E5%9F%9F%EF%BC%8C%E5%85%B6%E4%B8%AD%E6%95%B0%E6%8D%AE%E5%9F%9F%E7%94%A8%E4%BA%8E%E5%AD%98%E5%82%A8%E6%95%B0%E6%8D%AE%EF%BC%8C%E8%80%8C%E5%9C%B0%E5%9D%80%E5%9F%9F%E7%94%A8%E4%BA%8E%E5%AD%98%E5%82%A8%E5%89%8D%E9%A9%B1%E6%88%96%E5%90%8E%E7%BB%A7%E5%85%83%E7%B4%A0%E7%9A%84%E5%9C%B0%E5%9D%80%E3%80%82%0A%0A%23%23%23%23%23%23%201.2.1%20%E5%8D%95%E9%93%BE%E8%A1%A8%0A%3E%201.%20**%E5%8D%95%E9%93%BE%E8%A1%A8(SingleILinkedList)**%0A%3E%202.%20**%E5%B8%A6%E5%A4%B4%E7%BB%93%E7%82%B9%E7%9A%84%E5%8D%95%E9%93%BE%E8%A1%A8(HeadSingleILinkedList)**%0A%3E%E5%A4%B4%E7%BB%93%E7%82%B9%EF%BC%9A%E4%B8%80%E4%B8%AA%E6%B2%A1%E6%9C%89%E5%80%BC%E7%9A%84%E7%BB%93%E7%82%B9%0A%3E3.%20**%E5%BE%AA%E7%8E%AF%E5%8D%95%E9%93%BE%E8%A1%A8(CircularHeadSILinkedList)**%0A%3E%E9%93%BE%E8%A1%A8%E4%B8%AD%E7%9A%84%E6%9C%80%E5%90%8E%E4%B8%80%E4%B8%AA%E7%BB%93%E7%82%B9%E7%9A%84next%E5%9F%9F%E6%8C%87%E5%90%91%E4%BA%86%E5%A4%B4%E7%BB%93%E7%82%B9head%EF%BC%8C%E5%BD%A2%E6%88%90%E7%8E%AF%E5%BD%A2%E7%9A%84%E7%BB%93%E6%9E%84%0A%0A%E8%AF%A6%E7%BB%86%E8%AE%B2%E8%A7%A3%EF%BC%9A%5B%E9%A1%BA%E5%BA%8F%E8%A1%A8%E4%B8%8E%E5%8D%95%E9%93%BE%E8%A1%A8%E8%AF%A6%E7%BB%86%E8%AE%B2%E8%A7%A3%E4%B8%8E%E5%AE%9E%E7%8E%B0%5D(https%3A%2F%2Fblog.csdn.net%2Fjavazejian%2Farticle%2Fdetails%2F52953190)%0A%0A%23%23%23%23%23%23%201.2.2%20%E5%8F%8C%E9%93%BE%E8%A1%A8%0A*%20%E5%9C%A8%E5%8D%95%E9%93%BE%E8%A1%A8%E5%88%86%E6%9E%90%E4%B8%AD%EF%BC%8C%E6%88%91%E4%BB%AC%E5%8F%AF%E4%BB%A5%E7%9F%A5%E9%81%93%E6%AF%8F%E4%B8%AA%E7%BB%93%E7%82%B9%E5%8F%AA%E6%9C%89%E4%B8%80%E4%B8%AA%E6%8C%87%E5%90%91%E5%90%8E%E7%BB%A7%E7%BB%93%E7%82%B9%E7%9A%84next%E5%9F%9F%EF%BC%8C%E5%80%98%E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E7%9A%84%E7%BB%93%E7%82%B9%EF%BC%8C%E9%83%BD%E5%8F%AF%E4%BB%A5%E5%BE%88%E8%BD%BB%E6%98%93%E7%9A%84%E8%8E%B7%E5%8F%96%E5%85%B6%E5%89%8D%E9%A9%B1%E7%BB%93%E7%82%B9%E6%88%96%E8%80%85%E5%90%8E%E7%BB%A7%E7%BB%93%E7%82%B9%EF%BC%8C%E8%80%8C%E4%B8%BB%E8%A6%81%E7%BC%BA%E7%82%B9%E6%98%AF%E6%AF%8F%E4%B8%AA%E7%BB%93%E7%82%B9%E9%9C%80%E8%A6%81%E6%B7%BB%E5%8A%A0%E9%A2%9D%E5%A4%96%E7%9A%84next%E5%9F%9F%EF%BC%8C%E5%9B%A0%E6%AD%A4%E9%9C%80%E8%A6%81%E6%9B%B4%E5%A4%9A%E7%9A%84%E7%A9%BA%E9%97%B4%E5%BC%80%E9%94%80%EF%BC%8C%E5%90%8C%E6%97%B6%E7%BB%93%E7%82%B9%E7%9A%84%E6%8F%92%E5%85%A5%E4%B8%8E%E5%88%A0%E9%99%A4%E6%93%8D%E4%BD%9C%E4%B9%9F%E5%B0%86%E6%9B%B4%E5%8A%A0%E8%80%97%E6%97%B6%EF%BC%8C%E5%9B%A0%E4%B8%BA%E9%9C%80%E8%A6%81%E6%9B%B4%E5%A4%9A%E7%9A%84%E6%8C%87%E9%92%88%E6%8C%87%E5%90%91%E6%93%8D%E4%BD%9C%E3%80%82%0A%0A%3E1.%20**%E5%8F%8C%E9%93%BE%E8%A1%A8(HeadDoubleILinkedList)**%0A%3E2.%20**%E5%BE%AA%E7%8E%AF%E5%8F%8C%E9%93%BE%E8%A1%A8(LoopHeadDILinkedList)**%0A%3E3.%20**%E6%8E%92%E5%BA%8F%E5%BE%AA%E7%8E%AF%E5%8F%8C%E9%93%BE%E8%A1%A8(SortLoopHeadDIlinkedList)**%0A%3E%E6%8E%92%E5%BA%8F%E5%BE%AA%E7%8E%AF%E5%8F%8C%E9%93%BE%E8%A1%A8%E6%8C%87%E7%9A%84%E6%98%AF%E5%9C%A8%E6%8F%92%E5%85%A5%E5%85%83%E7%B4%A0%E6%97%B6%EF%BC%8C%E4%B8%8D%E5%86%8D%E6%A0%B9%E6%8D%AEindex%E6%A0%87%E5%BF%97%EF%BC%8C%E8%80%8C%E6%98%AF%E6%A0%B9%E6%8D%AE%E5%80%BC%E7%9A%84%E5%A4%A7%E5%B0%8F%E5%AF%BB%E6%89%BE%E6%8F%92%E5%85%A5%E4%BD%8D%E7%BD%AE%EF%BC%8C%E4%BD%86%E6%98%AF%E6%9C%89%E4%B8%AA%E6%8F%92%E5%85%A5%E5%80%BCdata%E5%BF%85%E9%A1%BB%E6%98%AFT%E6%88%96%E8%80%85T%E7%9A%84%E7%88%B6%E7%B1%BB%E8%80%8C%E4%B8%94%E5%AE%9E%E7%8E%B0%E4%BA%86Comoarable%E6%8E%A5%E5%8F%A3%E3%80%82%0A%3E4.%20**%E5%BC%82%E6%88%96%E9%AB%98%E6%95%88%E5%AD%98%E5%82%A8%E5%8F%8C%E9%93%BE%E8%A1%A8(XORNode)**%0A%3E%E5%8F%8C%E9%93%BE%E8%A1%A8%E7%9A%84%E5%AE%9E%E7%8E%B0%E4%B8%AD%EF%BC%8C%E9%83%BD%E6%98%AF%E9%9C%80%E8%A6%81%E4%B8%80%E4%B8%AA%E6%8C%87%E5%90%91%E5%90%8E%E7%BB%A7%E7%BB%93%E7%82%B9%E7%9A%84%E6%AD%A3%E5%90%91%E6%8C%87%E9%92%88%E5%92%8C%E4%B8%80%E4%B8%AA%E6%8C%87%E5%90%91%E5%89%8D%E9%A9%B1%E7%BB%93%E7%82%B9%E7%9A%84%E5%8F%8D%E5%90%91%E6%8C%87%E9%92%88%EF%BC%8C%E6%88%91%E4%BB%AC%E5%9C%A8%E6%9E%84%E9%80%A0%E4%B8%80%E4%B8%AA%E7%BB%93%E7%82%B9%E7%B1%BB%E6%97%B6%E9%9C%80%E8%A6%81%E4%B8%80%E4%B8%AA%E6%95%B0%E6%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BC%8C%E6%8C%87%E9%92%88%E7%9A%84%E5%B7%AE%E9%80%9A%E8%BF%87%E5%BC%82%E6%88%96%E8%BF%90%E7%AE%97%E6%9D%A5%E5%AE%9E%E7%8E%B0%E3%80%82%0A**pridiff%3D%E5%90%8E%E7%BB%A7%E7%BB%93%E7%82%B9%E7%9A%84%E5%9C%B0%E5%9D%80%E2%8A%95%E5%89%8D%E9%A9%B1%E7%BB%93%E7%82%B9%E7%9A%84%E5%9C%B0%E5%9D%80**%0A%E8%BF%98%E6%9C%AA%E5%AE%9E%E7%8E%B0%0A%0A%E8%AF%A6%E7%BB%86%E8%AE%B2%E8%A7%A3%EF%BC%9A%5B%E5%8F%8C%E9%93%BE%E8%A1%A8%E8%AF%A6%E7%BB%86%E8%AE%B2%E8%A7%A3%E4%B8%8E%E5%AE%9E%E7%8E%B0%5D(https%3A%2F%2Fblog.csdn.net%2Fjavazejian%2Farticle%2Fdetails%2F53047590)%0A%0A%23%23%23%23%23%201.3%20%E6%94%B9%E8%89%AF%E9%A1%BA%E5%BA%8F%E8%A1%A8%E4%B8%8E%E5%8F%8C%E9%93%BE%E8%A1%A8(%E7%B1%BB%E4%BC%BCArrayList%E5%92%8CLinkedList)%0A*%20%5B%E6%94%B9%E8%89%AF%E9%A1%BA%E5%BA%8F%E8%A1%A8%E4%B8%8E%E5%8F%8C%E9%93%BE%E8%A1%A8%E7%B1%BB%E4%BC%BCArrayList%E5%92%8CLinkedList%5C(Iterator%E8%BF%AD%E4%BB%A3%E5%99%A8%E4%B8%8Efast-fail%E6%9C%BA%E5%88%B6%5C)%5D(https%3A%2F%2Fblog.csdn.net%2Fjavazejian%2Farticle%2Fdetails%2F53073995)%0A%0A%23%23%23%23%202.%20%E6%A0%88(Stack)%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/9ea3fe73-d9c6-4a89-a247-c8fb97dfd11b/b7e0edcd-6a92-4036-a8cf-e1730070ebbf.png.png%5D(en-resource%3A%2F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E%B0%E5%AF%B9%E5%85%83%E7%B4%A0%E7%9A%84%E5%AD%98%E5%8F%96%E6%93%8D%E4%BD%9C%E3%80%82%E5%BD%93%E7%84%B6%E6%88%91%E4%BB%AC%E8%BF%98%E5%8F%AF%E4%BB%A5**%E9%87%87%E7%94%A8%E5%86%85%E9%83%A8%E6%95%B0%E7%BB%84**%E5%AE%9E%E7%8E%B0%E9%A1%BA%E5%BA%8F%E6%A0%88%E3%80%82%0A%3E1.%20**%E9%A1%BA%E5%BA%8F%E8%A1%A8%E5%AE%9E%E7%8E%B0(StackByArrayList)**%0A%3E2.%20**%E5%86%85%E9%83%A8%E6%95%B0%E7%BB%84%E5%AE%9E%E7%8E%B0(SeqStack)**%0A%0A%23%23%23%23%23%202.2%20%E9%93%BE%E5%BC%8F%E6%A0%88%0A*%20%E9%93%BE%E5%BC%8F%E6%A0%88%EF%BC%88Linked%20Stack%EF%BC%89%EF%BC%8C%E5%B0%B1%E6%98%AF%E9%87%87%E7%94%A8%E9%93%BE%E5%BC%8F%E5%AD%98%E5%82%A8%E7%BB%93%E6%9E%84%E7%9A%84%E6%A0%88%EF%BC%8C%E7%94%B1%E4%BA%8E%E6%88%91%E4%BB%AC%E6%93%8D%E4%BD%9C%E7%9A%84%E6%98%AF%E6%A0%88%E9%A1%B6%E4%B8%80%E7%AB%AF%EF%BC%8C%E5%9B%A0%E6%AD%A4%E8%BF%99%E9%87%8C%E9%87%87%E7%94%A8%E5%8D%95%E9%93%BE%E8%A1%A8%EF%BC%88%E4%B8%8D%E5%B8%A6%E5%A4%B4%E7%BB%93%E7%82%B9%EF%BC%89%E4%BD%9C%E4%B8%BA%E5%9F%BA%E7%A1%80%E5%8D%B3%E5%8F%AF%E3%80%82%0A%3E1.%20**%E5%8D%95%E9%93%BE%E8%A1%A8%E5%AE%9E%E7%8E%B0(LinkedStackBySingleLinkedList)**%0A%3E2.%20**%E7%BB%93%E7%82%B9%E5%AE%9E%E7%8E%B0(LinkedStack)**%0A%0A%23%23%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%90%8E%E7%BC%80%E8%A1%A8%E8%BE%BE%E5%BC%8F(CalculateExpression)**%0A%0A%23%23%23%23%23%202.4%20%E8%AF%A6%E7%BB%86%E8%AE%B2%E8%A7%A3%0A%3E%5B%E6%A0%88%E7%9A%84%E8%AF%A6%E7%BB%86%E8%AF%A6%E8%A7%A3%E4%B8%8E%E5%AE%9E%E7%8E%B0%5D(https%3A%2F%2Fblog.csdn.net%2Fjavazejian%2Farticle%2Fdetails%2F53362993)%0A%0A%23%23%23%23%203.%20%E9%98%9F%E5%88%97(Queue)%0A*%20%E9%98%9F%E5%88%97%E6%98%AF%E4%B8%80%E7%A7%8D%E7%89%B9%E6%AE%8A%E7%9A%84%E7%BA%BF%E6%80%A7%E8%A1%A8%EF%BC%8C%E5%85%B6%E6%8F%92%E5%85%A5%E5%92%8C%E5%88%A0%E9%99%A4%E7%9A%84%E6%93%8D%E4%BD%9C%E5%88%86%E5%88%AB%E5%9C%A8%E8%A1%A8%E7%9A%84%E4%B8%A4%E7%AB%AF%E8%BF%9B%E8%A1%8C%EF%BC%8C%E9%98%9F%E5%88%97%E7%9A%84%E7%89%B9%E7%82%B9%E5%B0%B1%E6%98%AF%E5%85%88%E8%BF%9B%E5%85%88%E5%87%BA(First%20In%20First%20Out)%E3%80%82%E6%88%91%E4%BB%AC%E6%8A%8A%E5%90%91%E9%98%9F%E5%88%97%E4%B8%AD%E6%8F%92%E5%85%A5%E5%85%83%E7%B4%A0%E7%9A%84%E8%BF%87%E7%A8%8B%E7%A7%B0%E4%B8%BA%E5%85%A5%E9%98%9F(Enqueue)%EF%BC%8C%E5%88%A0%E9%99%A4%E5%85%83%E7%B4%A0%E7%9A%84%E8%BF%87%E7%A8%8B%E7%A7%B0%E4%B8%BA%E5%87%BA%E9%98%9F(Dequeue)%E5%B9%B6%E6%8A%8A%E5%85%81%E8%AE%B8%E5%85%A5%E9%98%9F%E7%9A%84%E4%B8%80%E7%AB%AF%E7%A7%B0%E4%B8%BA%E9%98%9F%E5%B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E9%98%9F%E5%88%97%E8%AE%BE%E8%AE%A1%E4%B8%BA%E5%BE%AA%E7%8E%AF%E7%BB%93%E6%9E%84%E3%80%82%0A%0A%3E2.%20**%E5%BE%AA%E7%8E%AF%E9%98%9F%E5%88%97%EF%BC%88SeqQueue%EF%BC%89**%0A%3E%E9%A1%BA%E5%BA%8F%E5%BE%AA%E7%8E%AF%E9%98%9F%E5%88%97%E5%B0%B1%E6%98%AF%E5%B0%86%E9%A1%BA%E5%BA%8F%E9%98%9F%E5%88%97%E8%AE%BE%E8%AE%A1%E4%B8%BA%E5%9C%A8%E9%80%BB%E8%BE%91%E7%BB%93%E6%9E%84%E4%B8%8A%E6%94%B6%E5%B0%BE%E7%9B%B8%E6%8E%A5%E7%9A%84%E5%BE%AA%E7%8E%AF%E7%BB%93%E6%9E%84%EF%BC%8C%E8%BF%99%E6%A0%B7%E6%88%91%E4%BB%AC%E5%B0%B1%E5%8F%AF%E4%BB%A5%E9%87%8D%E5%A4%8D%E5%88%A9%E7%94%A8%E5%AD%98%E5%82%A8%E5%8D%95%E5%85%83%E3%80%82%0A%3E%E5%BE%AA%E7%8E%AF%E9%98%9F%E5%88%97%E6%9C%89%E4%BB%A5%E4%B8%8B%E8%AE%A1%E7%AE%97%E5%85%B3%E7%B3%BB%0A%60%60%60%0A%2F%2F%E5%85%B6%E4%B8%ADfront%E3%80%81rear%E7%9A%84%E4%B8%8B%E6%A0%87%E7%9A%84%E5%8F%96%E5%80%BC%E8%8C%83%E5%9B%B4%E6%98%AF0~size-1%EF%BC%8C%E4%B8%8D%E4%BC%9A%E9%80%A0%E6%88%90%E5%81%87%E6%BA%A2%E5%87%BA%E3%80%82%0Afront%3D(front%2B1)%25size%3B%2F%2F%E9%98%9F%E5%A4%B4%E4%B8%8B%E6%A0%87%0Arear%3D(rear%2B1)%25size%3B%20%20%2F%2F%E4%B8%8B%E4%B8%80%E4%B8%AA%E5%85%A5%E9%98%9F%E5%85%83%E7%B4%A0%E7%9A%84%E4%B8%8B%E6%A0%87%0A%60%60%60%0A%3Ea.%20front%E4%B8%BA%E9%98%9F%E5%A4%B4%E5%85%83%E7%B4%A0%E7%9A%84%E4%B8%8B%E6%A0%87%EF%BC%8Crear%E5%88%99%E6%8C%87%E5%90%91%E4%B8%8B%E4%B8%80%E4%B8%AA%E5%85%A5%E9%98%9F%E5%85%83%E7%B4%A0%E7%9A%84%E4%B8%8B%E6%A0%87%0Ab.%20%E5%BD%93front%3Drear%E6%97%B6%EF%BC%8C%E6%88%91%E4%BB%AC%E7%BA%A6%E5%AE%9A%E9%98%9F%E5%88%97%E4%B8%BA%E7%A9%BA%E3%80%82%0Ac.%20%E5%87%BA%E9%98%9F%E6%93%8D%E4%BD%9C%E6%94%B9%E5%8F%98front%E4%B8%8B%E6%A0%87%E6%8C%87%E5%90%91%EF%BC%8C%E5%85%A5%E9%98%9F%E6%93%8D%E4%BD%9C%E6%94%B9%E5%8F%98rear%E4%B8%8B%E6%A0%87%E6%8C%87%E5%90%91%EF%BC%8Csize%E4%BB%A3%E8%A1%A8%E9%98%9F%E5%88%97%E5%AE%B9%E9%87%8F%E3%80%82%0Ad.%20%E7%BA%A6%E5%AE%9A%E9%98%9F%E5%88%97%E6%BB%A1%E7%9A%84%E6%9D%A1%E4%BB%B6%E4%B8%BAfront%3D(rear%2B1)%25size%2C%E6%B3%A8%E6%84%8F%E6%AD%A4%E6%97%B6%E9%98%9F%E5%88%97%E4%B8%AD%E4%BB%8D%E6%9C%89%E4%B8%80%E4%B8%AA%E7%A9%BA%E7%9A%84%E4%BD%8D%E7%BD%AE%EF%BC%8C%E6%AD%A4%E5%A4%84%E7%95%99%E4%B8%80%E4%B8%AA%E7%A9%BA%E4%BD%8D%E4%B8%BB%E8%A6%81%E7%94%A8%E4%BA%8E%E9%81%BF%E5%85%8D%E4%B8%8E%E9%98%9F%E5%88%97%E7%A9%BA%E7%9A%84%E6%9D%A1%E4%BB%B6front%3Drear%E7%9B%B8%E5%90%8C%E3%80%82%0Ae.%20%E9%98%9F%E5%88%97%E5%86%85%E9%83%A8%E7%9A%84%E6%95%B0%E7%BB%84%E5%8F%AF%E6%89%A9%E5%AE%B9%EF%BC%8C%E5%B9%B6%E6%8C%89%E7%85%A7%E5%8E%9F%E6%9D%A5%E9%98%9F%E5%88%97%E7%9A%84%E6%AC%A1%E5%BA%8F%E5%A4%8D%E5%88%B6%E5%85%83%E7%B4%A0%E6%95%B0%E7%BB%84%C2%A0%0A%0A%23%23%23%23%23%203.2%20%E9%93%BE%E5%BC%8F%E9%98%9F%E5%88%97%EF%BC%88LinkedQueue%EF%BC%89%0A*%20%E9%93%BE%E5%BC%8F%E9%98%9F%E5%88%97%EF%BC%8C%E5%B0%86%E4%BD%BF%E7%94%A8%E5%B8%A6%E5%A4%B4%E6%8C%87%E9%92%88front%E5%92%8C%E5%B0%BE%E6%8C%87%E9%92%88rear%E7%9A%84%E5%8D%95%E9%93%BE%E8%A1%A8%E5%AE%9E%E7%8E%B0%EF%BC%8Cfront%E7%9B%B4%E6%8E%A5%E6%8C%87%E5%90%91%E9%98%9F%E5%A4%B4%E7%9A%84%E7%AC%AC%E4%B8%80%E4%B8%AA%E5%85%83%E7%B4%A0%EF%BC%8Crear%E6%8C%87%E5%90%91%E9%98%9F%E5%B0%BE%E7%9A%84%E6%9C%80%E5%90%8E%E4%B8%80%E4%B8%AA%E5%85%83%E7%B4%A0%E3%80%82%0A*%20%E8%AE%BE%E8%AE%A1%E9%93%BE%E5%BC%8F%E9%98%9F%E5%88%97%0A%3E%20a.%20%E5%88%86%E5%88%AB%E8%AE%BE%E7%BD%AEfront%E5%92%8Crear%E6%8C%87%E5%90%91%E9%98%9F%E5%A4%B4%E7%BB%93%E7%82%B9%E5%92%8C%E9%98%9F%E5%B0%BE%E7%BB%93%E7%82%B9%EF%BC%8C%E4%BD%BF%E7%94%A8%E5%8D%95%E9%93%BE%E8%A1%A8%E7%9A%84%E5%A4%B4%E5%B0%BE%E8%AE%BF%E9%97%AE%E6%97%B6%E9%97%B4%E5%A4%8D%E6%9D%82%E5%BA%A6%E4%B8%BAO(1)%0A%3E%20b.%20%E8%AE%BE%E7%BD%AE%E5%88%9D%E5%A7%8B%E5%8C%96%E7%A9%BA%E9%98%9F%E5%88%97%EF%BC%8C%E4%BD%BF%E7%94%A8front%3Drear%3Dnull%EF%BC%8C%E5%B9%B6%E4%B8%94%E7%BA%A6%E5%AE%9A%E6%9D%A1%E4%BB%B6front%3D%3Dnull%26%26rear%3D%3Dnull%E6%88%90%E7%AB%8B%E6%97%B6%EF%BC%8C%E9%98%9F%E5%88%97%E4%B8%BA%E7%A9%BA%E3%80%82%0A%3E%20c.%20%E5%BD%93%E7%AC%AC%E4%B8%80%E4%B8%AA%E5%85%83%E7%B4%A0%E5%85%A5%E9%98%9F%E6%88%96%E8%80%85%E6%9C%80%E5%90%8E%E4%B8%80%E4%B8%AA%E5%85%83%E7%B4%A0%E5%87%BA%E9%98%9F%E6%97%B6%EF%BC%8C%E5%90%8C%E6%97%B6%E6%9B%B4%E6%96%B0front%E6%8C%87%E9%92%88%E5%92%8Crear%E6%8C%87%E9%92%88%E7%9A%84%E6%8C%87%E5%90%91%E3%80%82%0A%3E%20d.%20%E5%85%A5%E9%98%9F%E6%93%8D%E4%BD%9C%E6%97%B6%EF%BC%8C%E4%BD%BF%E6%8F%92%E5%85%A5%E5%85%83%E7%B4%A0%E7%9A%84%E7%BB%93%E7%82%B9%E5%9C%A8rear%E4%B9%8B%E5%90%8E%E5%B9%B6%E6%9B%B4%E6%96%B0rear%E6%8C%87%E9%92%88%E6%8C%87%E5%90%91%E6%96%B0%E6%8F%92%E5%85%A5%E5%85%83%E7%B4%A0%E3%80%82%0A%3E%20e.%20%E5%87%BA%E9%98%9F%E6%93%8D%E4%BD%9C%E6%97%B6%EF%BC%8C%E8%8B%A5%E9%98%9F%E5%88%97%E4%B8%8D%E4%B8%BA%E7%A9%BA%E8%8E%B7%E5%8F%96%E9%98%9F%E5%A4%B4%E7%BB%93%E7%82%B9%E5%85%83%E7%B4%A0%EF%BC%8C%E5%B9%B6%E5%88%A0%E9%99%A4%E9%98%9F%E5%A4%B4%E7%BB%93%E7%82%B9%E5%85%83%E7%B4%A0%EF%BC%8C%E6%9B%B4%E6%96%B0front%E6%8C%87%E9%92%88%E7%9A%84%E6%8C%87%E5%90%91%E4%B8%BAfront%3Dfront.next%0A%0A%23%23%23%23%23%203.3%20%E4%BC%98%E5%85%88%E9%98%9F%E5%88%97(PriorityQueue)%0A*%20%E4%BC%98%E5%85%88%E7%BA%A7%E9%98%9F%E5%88%97%E4%B9%9F%E6%98%AF%E4%B8%80%E7%A7%8D%E7%89%B9%E6%AE%8A%E7%9A%84%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%EF%BC%8C%E9%98%9F%E5%88%97%E4%B8%AD%E7%9A%84%E6%AF%8F%E4%B8%AA%E5%85%83%E7%B4%A0%E9%83%BD%E6%9C%89%E4%B8%80%E4%B8%AA%E4%BC%98%E5%85%88%E7%BA%A7%EF%BC%8C%E8%8B%A5%E6%AF%8F%E6%AC%A1%E5%87%BA%E9%98%9F%E7%9A%84%E6%98%AF%E5%85%B7%E6%9C%89%E6%9C%80%E9%AB%98%E4%BC%98%E5%85%88%E7%BA%A7%E7%9A%84%E5%85%83%E7%B4%A0%EF%BC%8C%E5%88%99%E7%A7%B0%E4%B8%BA%E9%99%8D%E5%BA%8F%E4%BC%98%E5%85%88%E7%BA%A7%E9%98%9F%E5%88%97(%E6%80%BB%E6%98%AF%E5%85%88%E5%88%A0%E9%99%A4%E6%9C%80%E5%A4%A7%E7%9A%84%E5%85%83%E7%B4%A0)%E3%80%82%E8%8B%A5%E6%AF%8F%E6%AC%A1%E5%87%BA%E9%98%9F%E7%9A%84%E6%98%AF%E5%80%BC%E6%9C%80%E5%B0%8F%E7%9A%84%E5%85%83%E7%B4%A0%EF%BC%8C%E5%88%99%E7%A7%B0%E4%B8%BA%E5%8D%87%E5%BA%8F%E4%BC%98%E5%85%88%E7%BA%A7%E9%98%9F%E5%88%97(%E6%80%BB%E6%98%AF%E5%85%88%E5%88%A0%E9%99%A4%E6%9C%80%E5%B0%8F%E7%9A%84%E5%85%83%E7%B4%A0)%EF%BC%8C%E9%80%9A%E5%B8%B8%E6%83%85%E5%86%B5%E4%B8%8B%E6%88%91%E4%BB%AC%E6%89%80%E8%AF%B4%E7%9A%84%E4%BC%98%E5%85%88%E9%98%9F%E5%88%97%EF%BC%8C%E4%B8%80%E8%88%AC%E6%98%AF%E6%8C%87%E9%99%8D%E5%BA%8F%E4%BC%98%E5%85%88%E7%BA%A7%E9%98%9F%E5%88%97%E3%80%82%0A*%20%E4%BD%BF%E7%94%A8%E4%B9%8B%E5%89%8D%E5%88%86%E6%9E%90%E8%BF%87%E7%9A%84MyLikedList%E4%BD%9C%E4%B8%BA%E5%9F%BA%E5%BA%95%EF%BC%8C%E5%AE%9E%E7%8E%B0%E4%B8%80%E4%B8%AA%E6%8E%92%E5%BA%8F%E7%9A%84SortLinkedList%E7%BB%A7%E6%89%BF%E8%87%AAMyLinkedList%EF%BC%8C%E8%BF%99%E9%87%8C%E9%9C%80%E8%A6%81%E6%B3%A8%E6%84%8F%E7%9A%84%E6%98%AF%E6%8E%92%E5%BA%8F%E9%93%BE%E8%A1%A8%E4%B8%AD%E7%9A%84T%E7%B1%BB%E5%9E%8B%E5%BF%85%E9%A1%BB%E6%98%AF%E5%AE%9E%E7%8E%B0%E4%BA%86Comparable%E6%8E%A5%E5%8F%A3%E7%9A%84%E7%B1%BB%E5%9E%8B%EF%BC%8C%E5%9C%A8SortLinkedList%E4%B8%AD%E4%B8%BB%E8%A6%81%E9%87%8D%E5%86%99%E6%B7%BB%E5%8A%A0%E7%9A%84add%E6%96%B9%E6%B3%95%EF%BC%8C%E6%8F%92%E5%85%A5%E9%80%BB%E8%BE%91%E6%98%AF%EF%BC%8C%E9%80%9A%E8%BF%87%E6%AF%94%E8%BE%83%E5%85%83%E7%B4%A0%E7%9A%84%E5%A4%A7%E5%B0%8F%E5%8A%A0%E5%85%A5%EF%BC%8C%E8%80%8C%E9%9D%9E%E7%AE%80%E5%8D%95%E4%B8%8B%E6%A0%87%E6%88%96%E5%B0%BE%E9%83%A8%E6%8F%92%E5%85%A5%E3%80%82%0A*%20%E6%8E%A5%E7%9D%80%E4%BB%A5SortMyLinkedList%E4%B8%BA%E5%9F%BA%E5%BA%95%E5%AE%9E%E7%8E%B0%E4%BC%98%E5%85%88%E9%98%9F%E5%88%97PriorityQueue%0A%0A%23%23%23%23%23%203.4%20%E8%AF%A6%E7%BB%86%E8%AE%B2%E8%A7%A3%0A%3E%5B%E9%98%9F%E5%88%97%E7%9A%84%E8%AF%A6%E7%BB%86%E8%AE%B2%E8%A7%A3%E4%B8%8E%E5%AE%9E%E7%8E%B0%5D(https%3A%2F%2Fblog.csdn.net%2Fjavazejian%2Farticle%2Fdetails%2F53375004)%0A%0A%0A%23%23%23%23%204.%20%E9%9B%86%E5%90%88(Set)%0A*%20%E9%9B%86%E5%90%88%EF%BC%8C%E6%98%AF%E7%94%B1%E4%B8%80%E5%A0%86%E6%97%A0%E5%BA%8F%E7%9A%84%E3%80%81%E7%9B%B8%E5%85%B3%E8%81%94%E7%9A%84%EF%BC%8C%E4%B8%94%E4%B8%8D%E9%87%8D%E5%A4%8D%E7%9A%84%E5%86%85%E5%AD%98%E7%BB%93%E6%9E%84%E3%80%90%E6%95%B0%E5%AD%A6%E4%B8%AD%E7%A7%B0%E4%B8%BA%E5%85%83%E7%B4%A0%E3%80%91%E7%BB%84%E6%88%90%E7%9A%84%E7%BB%84%E5%90%88%EF%BC%9B%0A*%20%E9%9B%86%E5%90%88%E5%88%86%E7%B1%BB%0A**%E6%9C%89%E5%BA%8F%E9%9B%86%E5%90%88**%EF%BC%9A%E9%9B%86%E5%90%88%E9%87%8C%E7%9A%84%E5%85%83%E7%B4%A0%E5%8F%AF%E4%BB%A5%E6%A0%B9%E6%8D%AE%20key%20%E6%88%96%20index%20%E8%AE%BF%E9%97%AE%20(**List%E3%80%81Map**)%0A**%E6%97%A0%E5%BA%8F%E9%9B%86%E5%90%88**%EF%BC%9A%E9%9B%86%E5%90%88%E9%87%8C%E7%9A%84%E5%85%83%E7%B4%A0%E5%8F%AA%E8%83%BD%E9%81%8D%E5%8E%86%E3%80%82(**Set**)%0A%0A%23%23%23%23%23%204.1%20Hash%0A*%20Hash%EF%BC%88%E5%93%88%E5%B8%8C%EF%BC%89%EF%BC%8C%E5%8F%88%E7%A7%B0%E2%80%9C%E6%95%A3%E5%88%97%E2%80%9D%0A*%20%E5%9C%A8%E6%9F%90%E7%A7%8D%E7%A8%8B%E5%BA%A6%E4%B8%8A%EF%BC%8C%E6%95%A3%E5%88%97%E6%98%AF%E4%B8%8E%E6%8E%92%E5%BA%8F%E7%9B%B8%E5%8F%8D%E7%9A%84%E4%B8%80%E7%A7%8D%E6%93%8D%E4%BD%9C%EF%BC%8C%E6%8E%92%E5%BA%8F%E6%98%AF%E5%B0%86%E9%9B%86%E5%90%88%E4%B8%AD%E7%9A%84%E5%85%83%E7%B4%A0%E6%8C%89%E7%85%A7%E6%9F%90%E7%A7%8D%E6%96%B9%E5%BC%8F%E6%AF%94%E5%A6%82%E5%AD%97%E5%85%B8%E9%A1%BA%E5%BA%8F%E6%8E%92%E5%88%97%E5%9C%A8%E4%B8%80%E8%B5%B7%EF%BC%8C%E8%80%8C%E6%95%A3%E5%88%97%E9%80%9A%E8%BF%87%E8%AE%A1%E7%AE%97%E5%93%88%E5%B8%8C%E5%80%BC%EF%BC%8C%E6%89%93%E7%A0%B4%E5%85%83%E7%B4%A0%E4%B9%8B%E9%97%B4%E5%8E%9F%E6%9C%89%E7%9A%84%E5%85%B3%E7%B3%BB%EF%BC%8C%E4%BD%BF%E9%9B%86%E5%90%88%E4%B8%AD%E7%9A%84%E5%85%83%E7%B4%A0%E6%8C%89%E7%85%A7%E6%95%A3%E5%88%97%E5%87%BD%E6%95%B0%E7%9A%84%E5%88%86%E7%B1%BB%E8%BF%9B%E8%A1%8C%E6%8E%92%E5%88%97%E3%80%82%0A%0A%3E1.%20**%E4%B8%BA%E4%BB%80%E4%B9%88%E8%A6%81%E6%9C%89%20Hash**%0A%3E%20%E6%88%91%E4%BB%AC%E9%80%9A%E5%B8%B8%E4%BD%BF%E7%94%A8%E6%95%B0%E7%BB%84%E6%88%96%E8%80%85%E9%93%BE%E8%A1%A8%E6%9D%A5%E5%AD%98%E5%82%A8%E5%85%83%E7%B4%A0%EF%BC%8C%E4%B8%80%E6%97%A6%E5%AD%98%E5%82%A8%E7%9A%84%E5%86%85%E5%AE%B9%E6%95%B0%E9%87%8F%E7%89%B9%E5%88%AB%E5%A4%9A%EF%BC%8C%E9%9C%80%E8%A6%81%E5%8D%A0%E7%94%A8%E5%BE%88%E5%A4%A7%E7%9A%84%E7%A9%BA%E9%97%B4%EF%BC%8C%E8%80%8C%E4%B8%94%E5%9C%A8**%E6%9F%A5%E6%89%BE%E6%9F%90%E4%B8%AA%E5%85%83%E7%B4%A0**%E6%98%AF%E5%90%A6%E5%AD%98%E5%9C%A8%E7%9A%84%E8%BF%87%E7%A8%8B%E4%B8%AD%EF%BC%8C%E6%95%B0%E7%BB%84%E5%92%8C%E9%93%BE%E8%A1%A8%E9%83%BD%E9%9C%80%E8%A6%81%E6%8C%A8%E4%B8%AA%E5%BE%AA%E7%8E%AF%E6%AF%94%E8%BE%83%EF%BC%8C%E8%80%8C%E9%80%9A%E8%BF%87%20%E5%93%88%E5%B8%8C%20%E8%AE%A1%E7%AE%97%EF%BC%8C%E5%8F%AF%E4%BB%A5%E5%A4%A7%E5%A4%A7**%E5%87%8F%E5%B0%91%E6%AF%94%E8%BE%83%E6%AC%A1%E6%95%B0**%E3%80%82%0A%0A%3E2.%20**%E5%93%88%E5%B8%8C%E5%87%BD%E6%95%B0**%0A%3E%E5%93%88%E5%B8%8C%E7%9A%84%E8%BF%87%E7%A8%8B%E4%B8%AD%E9%9C%80%E8%A6%81%E4%BD%BF%E7%94%A8%E5%93%88%E5%B8%8C%E5%87%BD%E6%95%B0%E8%BF%9B%E8%A1%8C%E8%AE%A1%E7%AE%97%E3%80%82%E5%93%88%E5%B8%8C%E5%87%BD%E6%95%B0%E6%98%AF%E4%B8%80%E7%A7%8D%E6%98%A0%E5%B0%84%E5%85%B3%E7%B3%BB%EF%BC%8C**%E6%A0%B9%E6%8D%AE%E6%95%B0%E6%8D%AE%E7%9A%84%E5%85%B3%E9%94%AE%E8%AF%8D%20key**%20%EF%BC%8C**%E9%80%9A%E8%BF%87%E4%B8%80%E5%AE%9A%E7%9A%84%E5%87%BD%E6%95%B0%E5%85%B3%E7%B3%BB**%EF%BC%8C**%E8%AE%A1%E7%AE%97%E5%87%BA%E8%AF%A5%E5%85%83%E7%B4%A0%E5%AD%98%E5%82%A8%E4%BD%8D%E7%BD%AE%E7%9A%84%E5%87%BD%E6%95%B0**%E3%80%82%0A%0A%3E3.%20**%E5%87%A0%E7%A7%8D%E5%B8%B8%E8%A7%81%E7%9A%84%E5%93%88%E5%B8%8C%E5%87%BD%E6%95%B0%EF%BC%88%E6%95%A3%E5%88%97%E5%87%BD%E6%95%B0%EF%BC%89%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95**%0A%3E*%20%E7%9B%B4%E6%8E%A5%E5%AE%9A%E5%9D%80%E6%B3%95%C2%A0%0A%3E%20%20%20%20H(key)%20%3D%20key%20%E6%88%96%20H(key)%20%3D%20a*key%20%2B%20b%0A%3E*%20%E9%99%A4%E7%95%99%E4%BD%99%E6%95%B0%E6%B3%95%0A%3EH(key)%20%3D%20key%20%25%20p%2C%20p%20%3C%20m%0A%3E*%20%E6%95%B0%E5%AD%97%E5%88%86%E6%9E%90%E6%B3%95%0A%3E*%20%E5%B9%B3%E6%96%B9%E5%8F%96%E4%B8%AD%E6%B3%95%C2%A0%0A%3E*%20%E6%8A%98%E5%8F%A0%E6%B3%95%EF%BC%88%E5%8F%A0%E5%8A%A0%E6%B3%95%EF%BC%89%0A%3E*%20%E9%9A%8F%E6%9C%BA%E6%95%B0%E6%B3%95%0A%0A%3E4.%20**%E5%93%88%E5%B8%8C%E5%86%B2%E7%AA%81%E7%9A%84%E8%A7%A3%E5%86%B3**%0A%3E%E9%80%89%E7%94%A8%E5%93%88%E5%B8%8C%E5%87%BD%E6%95%B0%E8%AE%A1%E7%AE%97%E5%93%88%E5%B8%8C%E5%80%BC%E6%97%B6%EF%BC%8C%E5%8F%AF%E8%83%BD%E4%B8%8D%E5%90%8C%E7%9A%84%20key%20%E4%BC%9A%E5%BE%97%E5%88%B0%E7%9B%B8%E5%90%8C%E7%9A%84%E7%BB%93%E6%9E%9C%EF%BC%8C%E4%B8%80%E4%B8%AA%E5%9C%B0%E5%9D%80%E6%80%8E%E4%B9%88%E5%AD%98%E6%94%BE%E5%A4%9A%E4%B8%AA%E6%95%B0%E6%8D%AE%E5%91%A2%EF%BC%9F%E8%BF%99%E5%B0%B1%E6%98%AF**%E5%86%B2%E7%AA%81**%E3%80%82%0A%3E*%20**%E9%93%BE%E6%8E%A5%E6%B3%95%EF%BC%88%E6%8B%89%E9%93%BE%E6%B3%95%EF%BC%89**%0A%3E**%E5%B0%86%E6%89%80%E6%9C%89%E5%85%B3%E9%94%AE%E5%AD%97%E4%B8%BA%E5%90%8C%E4%B9%89%E8%AF%8D%E7%9A%84%E7%BB%93%E7%82%B9%E9%93%BE%E6%8E%A5%E5%9C%A8%E5%90%8C%E4%B8%80%E4%B8%AA%E5%8D%95%E9%93%BE%E8%A1%A8%E4%B8%AD**%E3%80%82%0A%60%60%60%0A%E8%8B%A5%E9%80%89%E5%AE%9A%E7%9A%84%E6%95%A3%E5%88%97%E8%A1%A8%E9%95%BF%E5%BA%A6%E4%B8%BA%20m%2C%E5%88%99%E5%8F%AF%E5%B0%86%E6%95%A3%E5%88%97%E8%A1%A8%E5%AE%9A%E4%B9%89%E4%B8%BA%E4%B8%80%E4%B8%AA%E7%94%B1m%E4%B8%AA%E5%A4%B4%E6%8C%87%E9%92%88%E7%BB%84%E6%88%90%E7%9A%84%E6%8C%87%E9%92%88%E6%95%B0%E7%BB%84%20T%5B0..m-1%5D%C2%A0%E3%80%82%0A%E5%87%A1%E6%98%AF%E6%95%A3%E5%88%97%E5%9C%B0%E5%9D%80%E4%B8%BA%20i%20%E7%9A%84%E7%BB%93%E7%82%B9%EF%BC%8C%E5%9D%87%E6%8F%92%E5%85%A5%E5%88%B0%E4%BB%A5%20T%5Bi%5D%20%E4%B8%BA%E5%A4%B4%E6%8C%87%E9%92%88%E7%9A%84%E5%8D%95%E9%93%BE%E8%A1%A8%E4%B8%AD%E3%80%82%C2%A0T%20%E4%B8%AD%E5%90%84%E5%88%86%E9%87%8F%E7%9A%84%E5%88%9D%E5%80%BC%E5%9D%87%E5%BA%94%E4%B8%BA%E7%A9%BA%E6%8C%87%E9%92%88%E3%80%82T%20%E4%B8%AD%E5%90%84%E5%88%86%E9%87%8F%E7%9A%84%E5%88%9D%E5%80%BC%E5%9D%87%E5%BA%94%E4%B8%BA%E7%A9%BA%E6%8C%87%E9%92%88%E3%80%82%0A%60%60%60%0A%3E!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/9ea3fe73-d9c6-4a89-a247-c8fb97dfd11b/0badfc13-16ab-4024-86c4-61df0977939c.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F638%3A1)%0A%0A%3E*%20**%E5%BC%80%E6%94%BE%E5%AE%9A%E5%9D%80%E6%B3%95**%0A%3E%0A%0A%23%23%23%23%23%204.2%20%E5%93%88%E5%B8%8C%E8%A1%A8%EF%BC%88%E6%95%A3%E5%88%97%E8%A1%A8%EF%BC%89%0A*%20%E5%93%88%E5%B8%8C%E8%A1%A8%E6%98%AF%E5%AE%9E%E7%8E%B0%E5%85%B3%E8%81%94%E6%95%B0%E7%BB%84%EF%BC%88associative%20array%EF%BC%89%E7%9A%84%E4%B8%80%E7%A7%8D%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%EF%BC%8C%E5%B9%BF%E6%B3%9B%E5%BA%94%E7%94%A8%E4%BA%8E%E5%AE%9E%E7%8E%B0%E6%95%B0%E6%8D%AE%E7%9A%84%E5%BF%AB%E9%80%9F%E6%9F%A5%E6%89%BE%E3%80%82%0A%3E!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/9ea3fe73-d9c6-4a89-a247-c8fb97dfd11b/50f6e2fa-9321-41d1-973c-44fb938abde0.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F639%3A1)%0A%0A%3E%E7%94%A8%E5%93%88%E5%B8%8C%E5%87%BD%E6%95%B0%E8%AE%A1%E7%AE%97%E5%85%B3%E9%94%AE%E5%AD%97%E7%9A%84%E5%93%88%E5%B8%8C%E5%80%BC%EF%BC%88hash%20value%EF%BC%89%2C%E9%80%9A%E8%BF%87%E5%93%88%E5%B8%8C%E5%80%BC%E8%BF%99%E4%B8%AA%E7%B4%A2%E5%BC%95%E5%B0%B1%E5%8F%AF%E4%BB%A5%E6%89%BE%E5%88%B0%E5%85%B3%E9%94%AE%E5%AD%97%E7%9A%84%E5%AD%98%E5%82%A8%E4%BD%8D%E7%BD%AE%EF%BC%8C%E5%8D%B3%E6%A1%B6%EF%BC%88bucket%EF%BC%89%E3%80%82%E5%9C%A8%E5%93%88%E5%B8%8C%E8%A1%A8%E4%B8%8A%E7%9A%84%E6%8F%92%E5%85%A5%E3%80%81%E6%9F%A5%E6%89%BE%E3%80%81%E5%88%A0%E9%99%A4%E7%AD%89%E6%93%8D%E4%BD%9C%E7%9A%84%E6%97%B6%E9%97%B4%E5%A4%8D%E6%9D%82%E5%BA%A6%E6%98%AF%20O(1)%E3%80%82%0A%0A%3E%E6%9F%A5%E6%89%BE%E8%BF%87%E7%A8%8B%E4%B8%AD%EF%BC%8C%E5%85%B3%E9%94%AE%E5%AD%97%E7%9A%84%E6%AF%94%E8%BE%83%E6%AC%A1%E6%95%B0%EF%BC%8C%E5%8F%96%E5%86%B3%E4%BA%8E%E4%BA%A7%E7%94%9F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BC%8C%E4%BD%A0%E7%9C%8B%E6%98%AF%E4%B8%8D%E6%98%AF%E3%80%82%202.%20%E6%A1%B6%E5%A4%9A%E4%BA%86%E5%8D%95%E9%93%BE%E8%A1%A8%E9%95%BF%E5%BA%A6%E6%98%AF%E7%9F%AD%E4%B8%80%E4%BA%9B%EF%BC%8C%E4%BD%86%E6%98%AF%E8%BF%99%E6%98%AF%E4%B8%8D%E5%8F%91%E7%94%9F%E5%86%B2%E7%AA%81%E7%9A%84%E5%89%8D%E6%8F%90%EF%BC%8C%E5%A6%82%E6%9E%9C%E5%93%88%E5%B8%8C%E5%87%BD%E6%95%B0%E9%80%89%E6%8B%A9%E7%9A%84%E4%B8%8D%E5%A4%9F%E5%90%88%E9%80%82%EF%BC%8C%E5%A4%AA%E5%A4%9A%E5%85%83%E7%B4%A0%E7%BB%8F%E8%BF%87%E5%93%88%E5%B8%8C%E8%AE%A1%E7%AE%97%E5%8F%AF%E8%83%BD%E4%BC%9A%E5%A4%9A%E6%AC%A1%E5%86%B2%E7%AA%81%EF%BC%8C%E8%BF%99%E6%A0%B7%E5%8D%B3%E4%BD%BF%E6%A1%B6%E5%A4%9A%E4%BA%86%EF%BC%8C%E4%B9%9F%E4%B8%8D%E8%83%BD%E9%81%BF%E5%85%8D%E6%9F%90%E4%B8%AA%E9%93%BE%E8%A1%A8%E8%BF%87%E9%95%BF%E7%9A%84%E6%83%85%E5%86%B5%E3%80%82%0A%0A%23%23%23%23%23%204.3%20%E5%93%88%E5%B8%8C%E8%A1%A8%EF%BC%8C%E5%93%88%E5%B8%8C%E5%87%BD%E6%95%B0%E8%AF%A6%E7%BB%86%E8%AE%B2%E8%A7%A3%0A%3E%5B%E5%93%88%E5%B8%8C%E8%A1%A8%EF%BC%8C%E5%93%88%E5%B8%8C%E5%87%BD%E6%95%B0%E8%AF%A6%E7%BB%86%E8%AE%B2%E8%A7%A3%5D(https%3A%2F%2Fblog.csdn.net%2Fu011240877%2Farticle%2Fdetails%2F52940469)%0A%0A&lt;/center&gt;&lt;/div&gt;
</content>
  </entry>
  <entry xml:base="http://linzhiteng.postach.io/feed.xml">
    <title type="text">一. 二叉树</title>
    <id>https://linzhiteng.postach.io/post/yi-er-cha-shu</id>
    <updated>2019-10-11T06:05:10.595000Z</updated>
    <published>2019-04-01T07:33:40Z</published>
    <link href="https://linzhiteng.postach.io/post/yi-er-cha-shu" />
    <author>
      <name>linzhi teng</name>
    </author>
    <category term="shu" />
    <content type="html">&lt;div&gt;&lt;div style=&quot;font-size: 14px; margin: 0; padding: 0; width: 100%;&quot;&gt;&lt;div style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;一. 二叉树
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1. 二叉树的基本概念
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.1 二叉树基本形态
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.2 二叉树类型
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.3 树的相关术语
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.4 二叉树性质
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.5 二叉树遍历
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2. 完全二叉树
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.1 完全二叉树定义
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.2 完全二叉树性质
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.3 完全二叉树特点
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.4 完全二叉树存储
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.5 完全二叉树判定
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3. 满二叉树
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1 满二叉树定义
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4. 堆
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.1 堆的概念
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.2 堆的实现
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;5. 二叉查找树(排序树)(Binary Search Tree，BST)
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;二叉树查找树的详细解析
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;6. 平衡二叉树(AVL树)
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;6.1 平衡二叉树定义
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;6.2  平衡二叉树性质
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;6.3 平衡二叉树的设计
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;6.3.1 左左单旋转(LL)情景①分析
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;6.3.2 右右单旋转(RR)情景④分析
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;6.3.3 左右双旋转(LR)情景②分析
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;6.3.4 右左双旋转(RL)情景③分析
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;平衡二叉树详细解析
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;一. 二叉树&lt;/h2&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;1. 二叉树的基本概念&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;二叉树是每个结点最多有两个子树的树结构。通常子树被称作&quot;左子树&quot;（left subtree）和&quot;右子树&quot;（right subtree）。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;一棵深度为k，且有2^k-1个节点的二叉树，称为&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;满二叉树&lt;/strong&gt;，这种树的特点是每一层上的节点数都是最大节点数。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.1 二叉树基本形态&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;二叉树是递归定义的，其结点有左右子树之分，逻辑上二叉树有五种基本形态：&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/086b7b73-72ad-486b-9654-2699e7fe43ba/1c70c41c-adb8-49c9-bbf2-d2e5b05a5943.gif&quot; /&gt;&lt;br/&gt;
(1)空二叉树——如图(a)；&lt;br/&gt;
(2)只有一个根结点的二叉树——如图(b)；&lt;br/&gt;
(3)只有左子树——如图(c)；&lt;br/&gt;
(4)只有右子树——如图(d)；&lt;br/&gt;
(5)完全二叉树——如图(e)。&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;注意：尽管二叉树与树有许多相似之处，但二叉树不是树的特殊情形。&lt;/strong&gt;&lt;br/&gt;
树和二叉树有两个主要差别：&lt;/p&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;树中结点的最大度数没有限制，而二叉树结点的最大度数为2；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;树的结点无左、右之分，而二叉树的结点有左、右之分。&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.2 二叉树类型&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;(1)&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;完全二叉树&lt;/strong&gt;——若设二叉树的高度为h，除第 h 层外，其它各层 (1～h-1) 的结点数都达到最大个数，第h层有叶子结点，并且叶子结点都是从左到右依次排布，这就是完全二叉树。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;(2)&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;满二叉树&lt;/strong&gt;——除了叶结点外每一个结点都有左右子叶且叶子结点都处在最底层的二叉树。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;(3)&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;平衡二叉树&lt;/strong&gt;——平衡二叉树又被称为AVL树（区别于AVL算法），它是一棵二叉排序树，且具有以下性质：它是一棵空树或它的左右两个子树的高度差的绝对值不超过1，并且左右两个子树都是一棵平衡二叉树。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.3 树的相关术语&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;结点的度：结点子树的个数&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;树的度： 树中最大的结点度。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;叶子结点：也叫终端结点，是度为 0 的结点；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;分枝结点：度不为0的结点；&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.4 二叉树性质&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;(1) 在非空二叉树中，第i层的结点总数不超过 &lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;2^(i-1)&lt;/code&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;(2) 深度为h的二叉树最多有 &lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;2^h - 1&lt;/code&gt; 个结点,最少有h个结点&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;(3) 对于任意一棵二叉树，如果其叶子结点数为N0，而度数为2的结点总数为N2，则N0=N2+1；&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;(4)给定N个节点，能构成h(N)种不同的二叉树。&lt;br/&gt;
h(N)为卡特兰数的第N项。&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;h(n)=C(2*n，n)/(n+1)&lt;/code&gt;&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.5 二叉树遍历&lt;/h4&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;先序遍历&lt;br/&gt;
首先访问根，再先序遍历左（右）子树，最后先序遍历右（左）子树&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;中序遍历&lt;br/&gt;
首先中序遍历左（右）子树，再访问根，最后中序遍历右（左）子树&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;后序遍历&lt;br/&gt;
首先后序遍历左（右）子树，再后序遍历右（左）子树，最后访问根&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;层次遍历&lt;br/&gt;
即按照层次访问，通常用队列来做。访问根，访问子女，再访问子女的子女（越往后的层次越低）（两个子女的级别相同）&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;2. 完全二叉树&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.1 完全二叉树定义&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/086b7b73-72ad-486b-9654-2699e7fe43ba/7437c917-d763-406e-b861-7d7ecb3df416.jpg&quot; /&gt;&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; color: #333; margin: 0;&quot;&gt;若设二叉树的深度为h，除第 h 层外，其它各层 (1～h-1) 的结点数都达到最大个数，&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;第 h 层所有的结点都连续集中在最左边&lt;/strong&gt;，这就是完全二叉树。&lt;/p&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; color: #333; margin: 0;&quot;&gt;完全二叉树是由满二叉树而引出来的。对于深度为K的，有n个结点的二叉树，当且仅当其每一个结点都与深度为K的满二叉树中编号从1至n的结点一一对应时称之为完全二叉树。&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;(1)所有的叶结点都出现在第k层或k-l层（层次最大的两层）&lt;br/&gt;
(2)对任一结点，如果其右子树的最大层次为L，则其左子树的最大层次为L或L+l。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.2 完全二叉树性质&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;假设n0是度为0的结点总数（即叶子结点数），n1是度为1的结点总数， n2是度为2的结点总数，  n是结点总数 则 ：&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;n0=n/2，其中n为奇数时（n1=0）向上取整；n为偶数时（n1=1）。可根据完全二叉树的结点总数计算出叶子结点数。&lt;/strong&gt;&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.3 完全二叉树特点&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;完全二叉树的特点是：&lt;br/&gt;
(1）只允许最后一层有空缺结点且空缺在右边，即叶子结点只能在层次最大的两层上出现；&lt;br/&gt;
(2）对任一结点，如果其右子树的深度为j，则其左子树的深度必为j或j+1。 即度为1的点只有1个或0个&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.4 完全二叉树存储&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;出于简便起见,完全二叉树通常采用数组而不是链表存储&lt;br/&gt;
其存储结构如下:&lt;br/&gt;
var tree:array[1..n]of longint;{n:integer;n&gt;=1}&lt;br/&gt;
对于tree[i]，有如下特点：&lt;br/&gt;
（1）若i为奇数且i&gt;1，那么tree的左兄弟为tree[i-1]；&lt;br/&gt;
（2）若i为偶数且i&lt;n，那么tree的右兄弟为tree[i+1]；&lt;br/&gt;
（3）若i&gt;1，tree的父亲节点为tree[i/2]；&lt;br/&gt;
（4）若2* i&lt;=n，那么tree的左孩子为tree[2* i];若2* i+1&lt;=n,那么tree的右孩子为tree[2* i+1]；&lt;br/&gt;
（5）若i&gt;n/2,那么tree[i]为叶子结点（对应于（3））；&lt;br/&gt;
（6）若i&lt;(n-1)/2.那么tree[i]必有两个孩子（对应于（4））。&lt;br/&gt;
（7）满二叉树一定是完全二叉树，完全二叉树不一定是满二叉树。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.5 完全二叉树判定&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;判断一棵树是否是完全二叉树的思路&lt;br/&gt;
1&gt;如果树为空，则直接返回错&lt;br/&gt;
2&gt;如果树不为空：层序遍历二叉树&lt;br/&gt;
　　      2.1&gt;如果一个结点左右孩子都不为空，则pop该节点，将其左右孩子入队列；&lt;br/&gt;
　　      2.1&gt;如果遇到一个结点，左孩子为空，右孩子不为空，则该树一定不是完全二叉树；&lt;br/&gt;
　　      2.2&gt;如果遇到一个结点，左孩子不为空，右孩子为空；或者左右孩子都为空；则该节点之后的队列中的结点都为叶子节点；该树才是完全二叉树，否则就不是完全二叉树；&lt;/p&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;3. 满二叉树&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.1 满二叉树定义&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; color: #333; margin: 0;&quot;&gt;对于国内的满二叉树&lt;/p&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;一个层数为k 的满二叉树总结点数为：2^k - 1,因此满二叉的结点树一定是奇数个。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;第i层上的结点数为：2^i -1 ;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;一个层数为k的满二叉树的叶子结点个数（也就是最后一层）:2^(k-1) ;&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/086b7b73-72ad-486b-9654-2699e7fe43ba/522744ac-f207-45ed-8769-9011975e0548.jpg&quot; /&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; color: #333; margin: 0;&quot;&gt;对于国外的满二叉树&lt;br/&gt;
满二叉树的任意节点，要么度为0，要么度为2.换个说法即要么为叶子结点，要么同时具有左右孩子。&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/086b7b73-72ad-486b-9654-2699e7fe43ba/1a74830d-9007-4b42-963f-542830804f82.jpg&quot; /&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;4. 堆&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;4.1 堆的概念&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;堆是具有以下性质的完全二叉树：&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;每个结点的值都大于或等于其左右孩子结点的值，称为大顶堆；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;或者每个结点的值都小于或等于其左右孩子结点的值，称为小顶堆&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/086b7b73-72ad-486b-9654-2699e7fe43ba/1c044107-37d5-402a-81d1-57d391368221.jpg&quot; /&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;在一个堆有序的二叉树中，父节点的位置是K/2,它的两个子节点的位置是2k,2k+1。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;4.2 堆的实现&lt;/h4&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;
&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//最大堆&lt;/span&gt;
&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;MaxPQ&lt;/span&gt; &lt;/span&gt;{
    &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;private&lt;/span&gt; List&lt;Integer&gt; arr;      &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//定义一个数组&lt;/span&gt;
    &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;private&lt;/span&gt;  &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; N;                   &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//定义队列中的元素个数&lt;/span&gt;

    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;MaxPQ&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{
        arr = &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; ArrayList();
        arr.add(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1&lt;/span&gt;);
        N = &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0&lt;/span&gt;;
    }

    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;boolean&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;isEmpty&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{                   &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//方法，返回队列是否为空&lt;/span&gt;
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt; N == &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0&lt;/span&gt;;                                              
    }

    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;size&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{                                 &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//方法，返回队列中元素的个数&lt;/span&gt;
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt; N;
    }

    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;inSert&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; number)&lt;/span&gt; &lt;/span&gt;{       &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//添加方法，添加元素到结合末尾，并且使用上浮方法到指定的位置&lt;/span&gt;
        arr.add(number);
        swim(++N);
    }

    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;deleteMax&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{                &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//删除方法，删除最大元素并把最小的元素放到第一个，然后使用下浮方法&lt;/span&gt;
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; max = arr.get(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1&lt;/span&gt;);
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; min  = arr.get(N);
        arr.set(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1&lt;/span&gt;, min);
        arr.remove(N--);
        sink(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1&lt;/span&gt;);
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt; max;
    }
    &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//上浮&lt;/span&gt;
    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;swim&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; N)&lt;/span&gt; &lt;/span&gt;{
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;while&lt;/span&gt;(N &gt; &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1&lt;/span&gt; &amp;&amp; (arr.get(N/&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;2&lt;/span&gt;) &lt; arr.get(N))){
            &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; max = arr.get(N);
            &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; min = arr.get(N/&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;2&lt;/span&gt;);
            arr.set(N,min );
            arr.set(N/&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;2&lt;/span&gt;, max);
            N = N/&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;2&lt;/span&gt;;
        }
    }
    &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//下沉&lt;/span&gt;
    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;sink&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; number)&lt;/span&gt; &lt;/span&gt;{
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;while&lt;/span&gt;(number*&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;2&lt;/span&gt; &lt;= N) {
            &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; index = number*&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;2&lt;/span&gt;;
            &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;if&lt;/span&gt;(index &lt; N &amp;&amp; (arr.get(index) &lt; arr.get(index + &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1&lt;/span&gt;))) {
                index++;
            }
            &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;if&lt;/span&gt;(!(arr.get(number) &lt; arr.get(index))) {
                &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;break&lt;/span&gt;;
            }
            &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; max = arr.get(index);
            &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; min = arr.get(number);
            arr.set(number, max);
            arr.set(index, min);
            number = index;
        }

    }

    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;@Override&lt;/span&gt;
    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; String &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;toString&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;MaxPQ [arr=&quot;&lt;/span&gt; + arr + &lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;, N=&quot;&lt;/span&gt; + N + &lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;]&quot;&lt;/span&gt;;
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;5. 二叉查找树(排序树)(Binary Search Tree，BST)&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;二叉排序树或者是一棵空树，或者是具有下列性质的二叉树：&lt;/p&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;（1）若左子树不空，则左子树上所有结点的值均小于它的根节点点的值；
（2）若右子树不空，则右子树上所有结点的值均大于或等于它的根结点的值；
（3）左、右子树也分别为二叉排序树；
（4）没有键值相等的节点。
&lt;/code&gt;&lt;/pre&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;例子：&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;a href=&quot;https://www.nowcoder.com/questionTerminal/dfdfc7f18a234a768aabd4021eda3652&quot; style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;二叉查找树例题&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;&lt;a href=&quot;https://blog.csdn.net/javazejian/article/details/53727333&quot; style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;二叉树查找树的详细解析&lt;/a&gt;&lt;/h4&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;6. 平衡二叉树(AVL树)&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;6.1 平衡二叉树定义&lt;/h4&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;对于一般的二叉搜索树（Binary Search Tree），其期望高度（即为一棵平衡树时）为logN，其各操作的时间复杂度（O(logN)）同时也由此而决定。但是，在某些极端的情况下（如在插入的序列是有序的时），二叉搜索树将退化成近似链或链，此时，其操作的时间复杂度将退化成线性的，即O(n)。&lt;/p&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;为了解决这个问题，要加上一个称为平衡的附加结构条件即：任何结点的深度不得过深&lt;br/&gt;
（子树高度相差不超过1），就是平衡二叉树（Balanced Binary Tree），它是G.M. Adelson-Velsky 和 E.M. Landis在1962年在论文中发表的，因此又叫AVL树。&lt;/p&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;AVL树只是实现平衡二叉树的一种方法，它还有很多的其他实现方法如红黑树、替罪羊树、Treap、伸展树等&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;6.2  平衡二叉树性质&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;它是一棵空树或它的左右两个子树的高度差的绝对值不超过1，并且左右两个子树都是一棵平衡二叉树。这个差值也称为平衡因子（其取值可以是1，0，-1，平衡因子是某个结点左右子树层数的差值)&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;6.3 平衡二叉树的设计&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; color: #333; margin: 0;&quot;&gt;理解了平衡二叉树的概念后，我们在思考一下，那些操作可能引起平衡发生变化呢？&lt;br/&gt;
显然只有那些引起结点数量变化的操作才可能导致平衡被改变，也就是删除和插入操作了。&lt;/p&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; color: #333; margin: 0;&quot;&gt;实际上也总是可以通过对树进行简单的修复来让其重新恢复到平衡，而这样的简单操作我们就称之为旋转，当然旋转也有单旋转和双旋转之分。&lt;/p&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; color: #333; margin: 0;&quot;&gt;无论是插入还是删除，只有那些从插入点或者删除点到根结点的路径上的结点的平衡才有可能被改变，因为只有这些结点的子树才可能发生变化，所以最终也只需针对这些点进行平衡修复操作即可。&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;如何通过旋转来修复一棵失衡的二叉树，这里假设结点X是失衡点，它必须重新恢复平衡，由于任意结点的孩子结点最多有两个，而且导致失衡的必要条件是X结点的两棵子树高度差为2(大于1)，因此一般只有以下4种情况可能导致X点失去平衡：&lt;br/&gt;
① 在结点X的左孩子结点的左子树中插入元素&lt;br/&gt;
② 在结点X的左孩子结点的右子树中插入元素&lt;br/&gt;
③ 在结点X的右孩子结点的左子树中插入元素&lt;br/&gt;
④ 在结点X的右孩子结点的右子树中插入元素&lt;br/&gt;
以上4种情况，其中第①情况和第④情况是对称的，可以通过&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;单旋转&lt;/strong&gt;来解决，而第②种情况和第③情况是对称的，需要&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;双旋转&lt;/strong&gt;来解决。&lt;/p&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;6.3.1 左左单旋转(LL)情景①分析&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;在结点X的左孩子结点的左子树中插入元素&lt;/strong&gt;&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/086b7b73-72ad-486b-9654-2699e7fe43ba/d2e031c8-b2d7-4c6c-831e-5f01ab9f36d1.png&quot; /&gt;&lt;/p&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;6.3.2 右右单旋转(RR)情景④分析&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;在结点X的右孩子结点的右子树中插入元素&lt;/strong&gt;&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/086b7b73-72ad-486b-9654-2699e7fe43ba/eed0f6b0-4c4d-4646-ba62-0785a76c1124.png&quot; /&gt;&lt;/p&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;6.3.3 左右双旋转(LR)情景②分析&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;在结点X的左孩子结点的右子树中插入元素&lt;/strong&gt;&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/086b7b73-72ad-486b-9654-2699e7fe43ba/8cfb1cbe-83b2-4928-909a-7d2c9150c450.png&quot; /&gt;&lt;/p&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;6.3.4 右左双旋转(RL)情景③分析&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;在结点X的右孩子结点的左子树中插入元素&lt;/strong&gt;&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/086b7b73-72ad-486b-9654-2699e7fe43ba/08e0a995-f61c-45fc-9600-fa69c2857932.png&quot; /&gt;&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;&lt;a href=&quot;https://blog.csdn.net/javazejian/article/details/53892797&quot; style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;平衡二叉树详细解析&lt;/a&gt;&lt;/h4&gt;
&lt;/div&gt;&lt;center style='display:none !important;visibility:collapse !important;height:0 !important;white-space:nowrap;width:100%;overflow:hidden'&gt;%5Btoc%5D%0A%23%23%20%E4%B8%80.%20%E4%BA%8C%E5%8F%89%E6%A0%91%0A%23%23%23%201.%20%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5%0A%0A%E4%BA%8C%E5%8F%89%E6%A0%91%E6%98%AF%E6%AF%8F%E4%B8%AA%E7%BB%93%E7%82%B9%E6%9C%80%E5%A4%9A%E6%9C%89%E4%B8%A4%E4%B8%AA%E5%AD%90%E6%A0%91%E7%9A%84%E6%A0%91%E7%BB%93%E6%9E%84%E3%80%82%E9%80%9A%E5%B8%B8%E5%AD%90%E6%A0%91%E8%A2%AB%E7%A7%B0%E4%BD%9C%E2%80%9C%E5%B7%A6%E5%AD%90%E6%A0%91%E2%80%9D%EF%BC%88left%20subtree%EF%BC%89%E5%92%8C%E2%80%9C%E5%8F%B3%E5%AD%90%E6%A0%91%E2%80%9D%EF%BC%88right%20subtree%EF%BC%89%E3%80%82%0A%0A%E4%B8%80%E6%A3%B5%E6%B7%B1%E5%BA%A6%E4%B8%BAk%EF%BC%8C%E4%B8%94%E6%9C%892%5Ek-1%E4%B8%AA%E8%8A%82%E7%82%B9%E7%9A%84%E4%BA%8C%E5%8F%89%E6%A0%91%EF%BC%8C%E7%A7%B0%E4%B8%BA**%E6%BB%A1%E4%BA%8C%E5%8F%89%E6%A0%91**%EF%BC%8C%E8%BF%99%E7%A7%8D%E6%A0%91%E7%9A%84%E7%89%B9%E7%82%B9%E6%98%AF%E6%AF%8F%E4%B8%80%E5%B1%82%E4%B8%8A%E7%9A%84%E8%8A%82%E7%82%B9%E6%95%B0%E9%83%BD%E6%98%AF%E6%9C%80%E5%A4%A7%E8%8A%82%E7%82%B9%E6%95%B0%E3%80%82%0A%23%23%23%23%201.1%20%E4%BA%8C%E5%8F%89%E6%A0%91%E5%9F%BA%E6%9C%AC%E5%BD%A2%E6%80%81%0A%20%E4%BA%8C%E5%8F%89%E6%A0%91%E6%98%AF%E9%80%92%E5%BD%92%E5%AE%9A%E4%B9%89%E7%9A%84%EF%BC%8C%E5%85%B6%E7%BB%93%E7%82%B9%E6%9C%89%E5%B7%A6%E5%8F%B3%E5%AD%90%E6%A0%91%E4%B9%8B%E5%88%86%EF%BC%8C%E9%80%BB%E8%BE%91%E4%B8%8A%E4%BA%8C%E5%8F%89%E6%A0%91%E6%9C%89%E4%BA%94%E7%A7%8D%E5%9F%BA%E6%9C%AC%E5%BD%A2%E6%80%81%EF%BC%9A%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/086b7b73-72ad-486b-9654-2699e7fe43ba/1c70c41c-adb8-49c9-bbf2-d2e5b05a5943.gif.gif%5D(en-resource%3A%2F%2Fdatabase%2F843%3A1)%0A(1)%E7%A9%BA%E4%BA%8C%E5%8F%89%E6%A0%91%E2%80%94%E2%80%94%E5%A6%82%E5%9B%BE(a)%EF%BC%9B%0A(2)%E5%8F%AA%E6%9C%89%E4%B8%80%E4%B8%AA%E6%A0%B9%E7%BB%93%E7%82%B9%E7%9A%84%E4%BA%8C%E5%8F%89%E6%A0%91%E2%80%94%E2%80%94%E5%A6%82%E5%9B%BE(b)%EF%BC%9B%0A(3)%E5%8F%AA%E6%9C%89%E5%B7%A6%E5%AD%90%E6%A0%91%E2%80%94%E2%80%94%E5%A6%82%E5%9B%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5%90%8E%E5%BA%8F%E9%81%8D%E5%8E%86%E5%B7%A6%EF%BC%88%E5%8F%B3%EF%BC%89%E5%AD%90%E6%A0%91%EF%BC%8C%E5%86%8D%E5%90%8E%E5%BA%8F%E9%81%8D%E5%8E%86%E5%8F%B3%EF%BC%88%E5%B7%A6%EF%BC%89%E5%AD%90%E6%A0%91%EF%BC%8C%E6%9C%80%E5%90%8E%E8%AE%BF%E9%97%AE%E6%A0%B9%0A4.%20%E5%B1%82%E6%AC%A1%E9%81%8D%E5%8E%86%0A%E5%8D%B3%E6%8C%89%E7%85%A7%E5%B1%82%E6%AC%A1%E8%AE%BF%E9%97%AE%EF%BC%8C%E9%80%9A%E5%B8%B8%E7%94%A8%E9%98%9F%E5%88%97%E6%9D%A5%E5%81%9A%E3%80%82%E8%AE%BF%E9%97%AE%E6%A0%B9%EF%BC%8C%E8%AE%BF%E9%97%AE%E5%AD%90%E5%A5%B3%EF%BC%8C%E5%86%8D%E8%AE%BF%E9%97%AE%E5%AD%90%E5%A5%B3%E7%9A%84%E5%AD%90%E5%A5%B3%EF%BC%88%E8%B6%8A%E5%BE%80%E5%90%8E%E7%9A%84%E5%B1%82%E6%AC%A1%E8%B6%8A%E4%BD%8E%EF%BC%89%EF%BC%88%E4%B8%A4%E4%B8%AA%E5%AD%90%E5%A5%B3%E7%9A%84%E7%BA%A7%E5%88%AB%E7%9B%B8%E5%90%8C%EF%BC%89%0A%0A%23%23%23%202.%20%E5%AE%8C%E5%85%A8%E4%BA%8C%E5%8F%89%E6%A0%91%0A%23%23%23%23%202.1%20%E5%AE%8C%E5%85%A8%E4%BA%8C%E5%8F%89%E6%A0%91%E5%AE%9A%E4%B9%89%0A%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/086b7b73-72ad-486b-9654-2699e7fe43ba/7437c917-d763-406e-b861-7d7ecb3df416.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F846%3A1)%0A%0A*%20%E8%8B%A5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B0%E4%B8%BA%EF%BC%9A2%5Ek%20-%201%2C%E5%9B%A0%E6%AD%A4%E6%BB%A1%E4%BA%8C%E5%8F%89%E7%9A%84%E7%BB%93%E7%82%B9%E6%A0%91%E4%B8%80%E5%AE%9A%E6%98%AF%E5%A5%87%E6%95%B0%E4%B8%AA%E3%80%82%0A%20%20%20%202.%20%20%E7%AC%ACi%E5%B1%82%E4%B8%8A%E7%9A%84%E7%BB%93%E7%82%B9%E6%95%B0%E4%B8%BA%EF%BC%9A2%5Ei%20-1%20%3B%0A%20%20%20%203.%20%20%E4%B8%80%E4%B8%AA%E5%B1%82%E6%95%B0%E4%B8%BAk%E7%9A%84%E6%BB%A1%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E5%8F%B6%E5%AD%90%E7%BB%93%E7%82%B9%E4%B8%AA%E6%95%B0%EF%BC%88%E4%B9%9F%E5%B0%B1%E6%98%AF%E6%9C%80%E5%90%8E%E4%B8%80%E5%B1%82%EF%BC%89%3A2%5E(k-1)%20%3B%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/086b7b73-72ad-486b-9654-2699e7fe43ba/522744ac-f207-45ed-8769-9011975e0548.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F840%3A1)%0A%0A*%20%E5%AF%B9%E4%BA%8E%E5%9B%BD%E5%A4%96%E7%9A%84%E6%BB%A1%E4%BA%8C%E5%8F%89%E6%A0%91%0A%E6%BB%A1%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E4%BB%BB%E6%84%8F%E8%8A%82%E7%82%B9%EF%BC%8C%E8%A6%81%E4%B9%88%E5%BA%A6%E4%B8%BA0%EF%BC%8C%E8%A6%81%E4%B9%88%E5%BA%A6%E4%B8%BA2.%E6%8D%A2%E4%B8%AA%E8%AF%B4%E6%B3%95%E5%8D%B3%E8%A6%81%E4%B9%88%E4%B8%BA%E5%8F%B6%E5%AD%90%E7%BB%93%E7%82%B9%EF%BC%8C%E8%A6%81%E4%B9%88%E5%90%8C%E6%97%B6%E5%85%B7%E6%9C%89%E5%B7%A6%E5%8F%B3%E5%AD%A9%E5%AD%90%E3%80%82%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/086b7b73-72ad-486b-9654-2699e7fe43ba/1a74830d-9007-4b42-963f-542830804f82.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F838%3A1)%0A%0A%23%23%23%204.%20%E5%A0%86%0A%23%23%23%23%204.1%20%E5%A0%86%E7%9A%84%E6%A6%82%E5%BF%B5%0A%0A%E5%A0%86%E6%98%AF%E5%85%B7%E6%9C%89%E4%BB%A5%E4%B8%8B%E6%80%A7%E8%B4%A8%E7%9A%84%E5%AE%8C%E5%85%A8%E4%BA%8C%E5%8F%89%E6%A0%91%EF%BC%9A%0A*%20%E6%AF%8F%E4%B8%AA%E7%BB%93%E7%82%B9%E7%9A%84%E5%80%BC%E9%83%BD%E5%A4%A7%E4%BA%8E%E6%88%96%E7%AD%89%E4%BA%8E%E5%85%B6%E5%B7%A6%E5%8F%B3%E5%AD%A9%E5%AD%90%E7%BB%93%E7%82%B9%E7%9A%84%E5%80%BC%EF%BC%8C%E7%A7%B0%E4%B8%BA%E5%A4%A7%E9%A1%B6%E5%A0%86%EF%BC%9B%0A*%20%E6%88%96%E8%80%85%E6%AF%8F%E4%B8%AA%E7%BB%93%E7%82%B9%E7%9A%84%E5%80%BC%E9%83%BD%E5%B0%8F%E4%BA%8E%E6%88%96%E7%AD%89%E4%BA%8E%E5%85%B6%E5%B7%A6%E5%8F%B3%E5%AD%A9%E5%AD%90%E7%BB%93%E7%82%B9%E7%9A%84%E5%80%BC%EF%BC%8C%E7%A7%B0%E4%B8%BA%E5%B0%8F%E9%A1%B6%E5%A0%86%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/086b7b73-72ad-486b-9654-2699e7fe43ba/1c044107-37d5-402a-81d1-57d391368221.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F844%3A1)%0A%0A%E5%9C%A8%E4%B8%80%E4%B8%AA%E5%A0%86%E6%9C%89%E5%BA%8F%E7%9A%84%E4%BA%8C%E5%8F%89%E6%A0%91%E4%B8%AD%EF%BC%8C%E7%88%B6%E8%8A%82%E7%82%B9%E7%9A%84%E4%BD%8D%E7%BD%AE%E6%98%AFK%2F2%2C%E5%AE%83%E7%9A%84%E4%B8%A4%E4%B8%AA%E5%AD%90%E8%8A%82%E7%82%B9%E7%9A%84%E4%BD%8D%E7%BD%AE%E6%98%AF2k%2C2k%2B1%E3%80%82%0A%0A%23%23%23%23%204.2%20%E5%A0%86%E7%9A%84%E5%AE%9E%E7%8E%B0%0A%60%60%60java%0A%0A%2F%2F%E6%9C%80%E5%A4%A7%E5%A0%86%0Apublic%20class%20MaxPQ%20%7B%0A%20%20%20%20private%20List%3CInteger%3E%20arr%3B%20%20%20%20%20%20%2F%2F%E5%AE%9A%E4%B9%89%E4%B8%80%E4%B8%AA%E6%95%B0%E7%BB%84%0A%20%20%20%20private%20%20int%20N%3B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%E5%AE%9A%E4%B9%89%E9%98%9F%E5%88%97%E4%B8%AD%E7%9A%84%E5%85%83%E7%B4%A0%E4%B8%AA%E6%95%B0%0A%0A%20%20%20%20public%20MaxPQ()%20%7B%0A%20%20%20%20%20%20%20%20arr%20%3D%20new%20ArrayList()%3B%0A%20%20%20%20%20%20%20%20arr.add(1)%3B%0A%20%20%20%20%20%20%20%20N%20%3D%200%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20public%20boolean%20isEmpty()%20%7B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%E6%96%B9%E6%B3%95%EF%BC%8C%E8%BF%94%E5%9B%9E%E9%98%9F%E5%88%97%E6%98%AF%E5%90%A6%E4%B8%BA%E7%A9%BA%0A%20%20%20%20%20%20%20%20return%20N%20%3D%3D%200%3B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%7D%0A%0A%20%20%20%20public%20int%20size()%20%7B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%E6%96%B9%E6%B3%95%EF%BC%8C%E8%BF%94%E5%9B%9E%E9%98%9F%E5%88%97%E4%B8%AD%E5%85%83%E7%B4%A0%E7%9A%84%E4%B8%AA%E6%95%B0%0A%20%20%20%20%20%20%20%20return%20N%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20public%20void%20inSert(int%20number)%20%7B%20%20%20%20%20%20%20%2F%2F%E6%B7%BB%E5%8A%A0%E6%96%B9%E6%B3%95%EF%BC%8C%E6%B7%BB%E5%8A%A0%E5%85%83%E7%B4%A0%E5%88%B0%E7%BB%93%E5%90%88%E6%9C%AB%E5%B0%BE%EF%BC%8C%E5%B9%B6%E4%B8%94%E4%BD%BF%E7%94%A8%E4%B8%8A%E6%B5%AE%E6%96%B9%E6%B3%95%E5%88%B0%E6%8C%87%E5%AE%9A%E7%9A%84%E4%BD%8D%E7%BD%AE%0A%20%20%20%20%20%20%20%20arr.add(number)%3B%0A%20%20%20%20%20%20%20%20swim(%2B%2BN)%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20public%20int%20deleteMax()%20%7B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%E5%88%A0%E9%99%A4%E6%96%B9%E6%B3%95%EF%BC%8C%E5%88%A0%E9%99%A4%E6%9C%80%E5%A4%A7%E5%85%83%E7%B4%A0%E5%B9%B6%E6%8A%8A%E6%9C%80%E5%B0%8F%E7%9A%84%E5%85%83%E7%B4%A0%E6%94%BE%E5%88%B0%E7%AC%AC%E4%B8%80%E4%B8%AA%EF%BC%8C%E7%84%B6%E5%90%8E%E4%BD%BF%E7%94%A8%E4%B8%8B%E6%B5%AE%E6%96%B9%E6%B3%95%0A%20%20%20%20%20%20%20%20int%20max%20%3D%20arr.get(1)%3B%0A%20%20%20%20%20%20%20%20int%20min%20%20%3D%20arr.get(N)%3B%0A%20%20%20%20%20%20%20%20arr.set(1%2C%20min)%3B%0A%20%20%20%20%20%20%20%20arr.remove(N--)%3B%0A%20%20%20%20%20%20%20%20sink(1)%3B%0A%20%20%20%20%20%20%20%20return%20max%3B%0A%20%20%20%20%7D%0A%20%20%20%20%2F%2F%E4%B8%8A%E6%B5%AE%0A%20%20%20%20public%20void%20swim(int%20N)%20%7B%0A%20%20%20%20%20%20%20%20while(N%20%3E%201%20%26%26%20(arr.get(N%2F2)%20%3C%20arr.get(N)))%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20int%20max%20%3D%20arr.get(N)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20int%20min%20%3D%20arr.get(N%2F2)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20arr.set(N%2Cmin%20)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20arr.set(N%2F2%2C%20max)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20N%20%3D%20N%2F2%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%20%20%2F%2F%E4%B8%8B%E6%B2%89%0A%20%20%20%20public%20void%20sink(int%20number)%20%7B%0A%20%20%20%20%20%20%20%20while(number*2%20%3C%3D%20N)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20int%20index%20%3D%20number*2%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20if(index%20%3C%20N%20%26%26%20(arr.get(index)%20%3C%20arr.get(index%20%2B%201)))%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20index%2B%2B%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20if(!(arr.get(number)%20%3C%20arr.get(index)))%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20break%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20int%20max%20%3D%20arr.get(index)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20int%20min%20%3D%20arr.get(number)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20arr.set(number%2C%20max)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20arr.set(index%2C%20min)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20number%20%3D%20index%3B%0A%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%7D%0A%0A%20%20%20%20%40Override%0A%20%20%20%20public%20String%20toString()%20%7B%0A%20%20%20%20%20%20%20%20return%20%22MaxPQ%20%5Barr%3D%22%20%2B%20arr%20%2B%20%22%2C%20N%3D%22%20%2B%20N%20%2B%20%22%5D%22%3B%0A%20%20%20%20%7D%0A%7D%0A%60%60%60%0A%0A%0A%0A%0A%23%23%23%205.%20%E4%BA%8C%E5%8F%89%E6%9F%A5%E6%89%BE%E6%A0%91(%E6%8E%92%E5%BA%8F%E6%A0%91)(Binary%20Search%20Tree%EF%BC%8CBST)%0A%0A%E4%BA%8C%E5%8F%89%E6%8E%92%E5%BA%8F%E6%A0%91%E6%88%96%E8%80%85%E6%98%AF%E4%B8%80%E6%A3%B5%E7%A9%BA%E6%A0%91%EF%BC%8C%E6%88%96%E8%80%85%E6%98%AF%E5%85%B7%E6%9C%89%E4%B8%8B%E5%88%97%E6%80%A7%E8%B4%A8%E7%9A%84%E4%BA%8C%E5%8F%89%E6%A0%91%EF%BC%9A%0A%0A%60%60%60%0A%EF%BC%881%EF%BC%89%E8%8B%A5%E5%B7%A6%E5%AD%90%E6%A0%91%E4%B8%8D%E7%A9%BA%EF%BC%8C%E5%88%99%E5%B7%A6%E5%AD%90%E6%A0%91%E4%B8%8A%E6%89%80%E6%9C%89%E7%BB%93%E7%82%B9%E7%9A%84%E5%80%BC%E5%9D%87%E5%B0%8F%E4%BA%8E%E5%AE%83%E7%9A%84%E6%A0%B9%E8%8A%82%E7%82%B9%E7%82%B9%E7%9A%84%E5%80%BC%EF%BC%9B%0A%EF%BC%882%EF%BC%89%E8%8B%A5%E5%8F%B3%E5%AD%90%E6%A0%91%E4%B8%8D%E7%A9%BA%EF%BC%8C%E5%88%99%E5%8F%B3%E5%AD%90%E6%A0%91%E4%B8%8A%E6%89%80%E6%9C%89%E7%BB%93%E7%82%B9%E7%9A%84%E5%80%BC%E5%9D%87%E5%A4%A7%E4%BA%8E%E6%88%96%E7%AD%89%E4%BA%8E%E5%AE%83%E7%9A%84%E6%A0%B9%E7%BB%93%E7%82%B9%E7%9A%84%E5%80%BC%EF%BC%9B%0A%EF%BC%883%EF%BC%89%E5%B7%A6%E3%80%81%E5%8F%B3%E5%AD%90%E6%A0%91%E4%B9%9F%E5%88%86%E5%88%AB%E4%B8%BA%E4%BA%8C%E5%8F%89%E6%8E%92%E5%BA%8F%E6%A0%91%EF%BC%9B%0A%EF%BC%884%EF%BC%89%E6%B2%A1%E6%9C%89%E9%94%AE%E5%80%BC%E7%9B%B8%E7%AD%89%E7%9A%84%E8%8A%82%E7%82%B9%E3%80%82%0A%60%60%60%0A%E4%BE%8B%E5%AD%90%EF%BC%9A%0A%3E%20%5B%E4%BA%8C%E5%8F%89%E6%9F%A5%E6%89%BE%E6%A0%91%E4%BE%8B%E9%A2%98%5D(https%3A%2F%2Fwww.nowcoder.com%2FquestionTerminal%2Fdfdfc7f18a234a768aabd4021eda3652)%0A%0A%23%23%23%23%20%5B%E4%BA%8C%E5%8F%89%E6%A0%91%E6%9F%A5%E6%89%BE%E6%A0%91%E7%9A%84%E8%AF%A6%E7%BB%86%E8%A7%A3%E6%9E%90%5D(https%3A%2F%2Fblog.csdn.net%2Fjavazejian%2Farticle%2Fdetails%2F53727333)%0A%0A%23%23%23%206.%20%E5%B9%B3%E8%A1%A1%E4%BA%8C%E5%8F%89%E6%A0%91(AVL%E6%A0%91)%0A%23%23%23%23%206.1%20%E5%B9%B3%E8%A1%A1%E4%BA%8C%E5%8F%89%E6%A0%91%E5%AE%9A%E4%B9%89%0A1.%20%E5%AF%B9%E4%BA%8E%E4%B8%80%E8%88%AC%E7%9A%84%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%EF%BC%88Binary%20Search%20Tree%EF%BC%89%EF%BC%8C%E5%85%B6%E6%9C%9F%E6%9C%9B%E9%AB%98%E5%BA%A6%EF%BC%88%E5%8D%B3%E4%B8%BA%E4%B8%80%E6%A3%B5%E5%B9%B3%E8%A1%A1%E6%A0%91%E6%97%B6%EF%BC%89%E4%B8%BAlogN%EF%BC%8C%E5%85%B6%E5%90%84%E6%93%8D%E4%BD%9C%E7%9A%84%E6%97%B6%E9%97%B4%E5%A4%8D%E6%9D%82%E5%BA%A6%EF%BC%88O(logN)%EF%BC%89%E5%90%8C%E6%97%B6%E4%B9%9F%E7%94%B1%E6%AD%A4%E8%80%8C%E5%86%B3%E5%AE%9A%E3%80%82%E4%BD%86%E6%98%AF%EF%BC%8C%E5%9C%A8%E6%9F%90%E4%BA%9B%E6%9E%81%E7%AB%AF%E7%9A%84%E6%83%85%E5%86%B5%E4%B8%8B%EF%BC%88%E5%A6%82%E5%9C%A8%E6%8F%92%E5%85%A5%E7%9A%84%E5%BA%8F%E5%88%97%E6%98%AF%E6%9C%89%E5%BA%8F%E7%9A%84%E6%97%B6%EF%BC%89%EF%BC%8C%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%E5%B0%86%E9%80%80%E5%8C%96%E6%88%90%E8%BF%91%E4%BC%BC%E9%93%BE%E6%88%96%E9%93%BE%EF%BC%8C%E6%AD%A4%E6%97%B6%EF%BC%8C%E5%85%B6%E6%93%8D%E4%BD%9C%E7%9A%84%E6%97%B6%E9%97%B4%E5%A4%8D%E6%9D%82%E5%BA%A6%E5%B0%86%E9%80%80%E5%8C%96%E6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93%E7%82%B9X%E7%9A%84%E5%B7%A6%E5%AD%A9%E5%AD%90%E7%BB%93%E7%82%B9%E7%9A%84%E5%B7%A6%E5%AD%90%E6%A0%91%E4%B8%AD%E6%8F%92%E5%85%A5%E5%85%83%E7%B4%A0**%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/086b7b73-72ad-486b-9654-2699e7fe43ba/d2e031c8-b2d7-4c6c-831e-5f01ab9f36d1.png.png%5D(en-resource%3A%2F%2Fdatabase%2F842%3A1)%0A%0A%23%23%23%23%23%206.3.2%20%E5%8F%B3%E5%8F%B3%E5%8D%95%E6%97%8B%E8%BD%AC(RR)%E6%83%85%E6%99%AF%E2%91%A3%E5%88%86%E6%9E%90%0A**%E5%9C%A8%E7%BB%93%E7%82%B9X%E7%9A%84%E5%8F%B3%E5%AD%A9%E5%AD%90%E7%BB%93%E7%82%B9%E7%9A%84%E5%8F%B3%E5%AD%90%E6%A0%91%E4%B8%AD%E6%8F%92%E5%85%A5%E5%85%83%E7%B4%A0**%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/086b7b73-72ad-486b-9654-2699e7fe43ba/eed0f6b0-4c4d-4646-ba62-0785a76c1124.png.png%5D(en-resource%3A%2F%2Fdatabase%2F845%3A1)%0A%0A%23%23%23%23%23%206.3.3%20%E5%B7%A6%E5%8F%B3%E5%8F%8C%E6%97%8B%E8%BD%AC(LR)%E6%83%85%E6%99%AF%E2%91%A1%E5%88%86%E6%9E%90%0A**%E5%9C%A8%E7%BB%93%E7%82%B9X%E7%9A%84%E5%B7%A6%E5%AD%A9%E5%AD%90%E7%BB%93%E7%82%B9%E7%9A%84%E5%8F%B3%E5%AD%90%E6%A0%91%E4%B8%AD%E6%8F%92%E5%85%A5%E5%85%83%E7%B4%A0**%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/086b7b73-72ad-486b-9654-2699e7fe43ba/8cfb1cbe-83b2-4928-909a-7d2c9150c450.png.png%5D(en-resource%3A%2F%2Fdatabase%2F839%3A1)%0A%0A%23%23%23%23%23%206.3.4%20%E5%8F%B3%E5%B7%A6%E5%8F%8C%E6%97%8B%E8%BD%AC(RL)%E6%83%85%E6%99%AF%E2%91%A2%E5%88%86%E6%9E%90%0A**%E5%9C%A8%E7%BB%93%E7%82%B9X%E7%9A%84%E5%8F%B3%E5%AD%A9%E5%AD%90%E7%BB%93%E7%82%B9%E7%9A%84%E5%B7%A6%E5%AD%90%E6%A0%91%E4%B8%AD%E6%8F%92%E5%85%A5%E5%85%83%E7%B4%A0**%20%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/086b7b73-72ad-486b-9654-2699e7fe43ba/08e0a995-f61c-45fc-9600-fa69c2857932.png.png%5D(en-resource%3A%2F%2Fdatabase%2F841%3A1)%0A%0A%0A%0A%0A%0A%23%23%23%23%20%5B%E5%B9%B3%E8%A1%A1%E4%BA%8C%E5%8F%89%E6%A0%91%E8%AF%A6%E7%BB%86%E8%A7%A3%E6%9E%90%5D(https%3A%2F%2Fblog.csdn.net%2Fjavazejian%2Farticle%2Fdetails%2F53892797)&lt;/center&gt;&lt;/div&gt;
</content>
  </entry>
  <entry xml:base="http://linzhiteng.postach.io/feed.xml">
    <title type="text">二 . 红黑树</title>
    <id>https://linzhiteng.postach.io/post/er-hong-hei-shu</id>
    <updated>2019-06-09T13:26:35.553000Z</updated>
    <published>2019-03-16T03:24:32Z</published>
    <link href="https://linzhiteng.postach.io/post/er-hong-hei-shu" />
    <author>
      <name>linzhi teng</name>
    </author>
    <category term="shu" />
    <content type="html">&lt;div&gt;&lt;div style=&quot;font-size: 14px; margin: 0; padding: 0; width: 100%;&quot;&gt;&lt;div style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;二 . 红黑树
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1. 红黑树简介
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2. 红黑树的修正
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.1 左旋
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.2 右旋
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3. 红黑树节点的添加
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1  红黑树插入后节点的调整思想:
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1.1 插入操作-case 1(叔叔节点也为红色)
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1.2 插入操作-case 2
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1.3 插入操作-case 3
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4. 红黑树节点的删除
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.1 红黑树删除之节点调整
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.1.1 删除操作-case 1
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.1.2 删除操作-case 2
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.1.3 删除操作-case 3
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.1.4 删除操作-case 4
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;二 . 红黑树&lt;/h2&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;1. 红黑树简介&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;红黑树是每个节点都带有颜色属性的二叉查找树，颜色或红色或黑色。在二叉查找树强制一般要求以外，对于任何有效的红黑树我们增加了如下的额外要求:&lt;/p&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;节点是红色或黑色。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;根节点是黑色。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;每个叶子节点都是黑色的空节点（NIL节点）。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;每个红色节点的两个子节点都是黑色。(从每个叶子到根的所有路径上不能有两个连续的红色节点)&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;从任一节点到其每个叶子的所有路径都包含相同数目的黑色节点。&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/0a80e276-0cf2-49d0-8159-374844062547/4a780926-1eb4-4c95-b24a-1244b8169ad0.jpg&quot; /&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;2. 红黑树的修正&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;变色、左旋、右旋是红黑树在二叉树上的扩展操作，同时也是基于这三个操作才能遵守红黑树的五个特性。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.1 左旋&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/0a80e276-0cf2-49d0-8159-374844062547/c6e0acce-f1d6-4613-a2a5-00adcb161b70.jpg&quot; /&gt;&lt;/p&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;    &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;/*
     * 左旋做了三件事：

     * 1. 将y的左子节点赋给x的右子节点,并将x赋给y左子节点的父节点(y左子节点非空时)

     * 2. 将x的父节点p(非空时)赋给y的父节点，同时更新p的子节点为y(左或右)

     * 3. 将y的左子节点设为x，将x的父节点设为y

     */&lt;/span&gt;
    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;leftRotate&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(RBNode&lt;T&gt; x)&lt;/span&gt; &lt;/span&gt;{
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;if&lt;/span&gt; (x == &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;null&lt;/span&gt;) &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt;;
        &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//1. 将y的左子节点赋给x的右子节点,并将x赋给y左子节点的父节点(y左子节点非空时)&lt;/span&gt;
        RBNode&lt;T&gt; y = x.right;
        x.right = y.left;
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;if&lt;/span&gt; (y.left != &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;null&lt;/span&gt;) {
            y.left.parent = x;
        }
        &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//2. 将x的父节点p(非空时)赋给y的父节点，同时更新p的子节点为y(左或右)&lt;/span&gt;
        y.parent = x.parent;
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;if&lt;/span&gt; (x.parent == &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;null&lt;/span&gt;) {
            &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;this&lt;/span&gt;.mRoot = y;
        } &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;else&lt;/span&gt; {
            &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;if&lt;/span&gt; (x == x.parent.left) {
                x.parent.left = y;
            } &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;else&lt;/span&gt; {
                x.parent.right = y;
            }
        }
        &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//3. 将y的左子节点设为x，将x的父节点设为y&lt;/span&gt;
        y.left = x;
        x.parent = y;
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.2 右旋&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/0a80e276-0cf2-49d0-8159-374844062547/2dc577d2-7699-4e2f-a493-f428437c21c2.jpg&quot; /&gt;&lt;/p&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;/*      右旋做了三件事：
     * 1. 将x的右子节点赋给y的左子节点,并将y赋给x右子节点的父节点(x右子节点非空时)
     * 2. 将y的父节点p(非空时)赋给x的父节点，同时更新p的子节点为x(左或右)
     * 3. 将x的右子节点设为y，将y的父节点设为x
     */&lt;/span&gt;
   &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;rightRotate&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(RBNode&lt;T&gt; y)&lt;/span&gt; &lt;/span&gt;{
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;if&lt;/span&gt; (y == &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;null&lt;/span&gt;) &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt;;
        &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//1. 将x的右子节点赋给y的左子节点,并将y赋给x右子节点的父节点(x右子节点非空时)&lt;/span&gt;
        RBNode&lt;T&gt; x = y.left;
        y.left = x.right;
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;if&lt;/span&gt; (x.right != &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;null&lt;/span&gt;) {
            x.right.parent = y;
        }
        &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//2. 将y的父节点p(非空时)赋给x的父节点，同时更新p的子节点为x(左或右)&lt;/span&gt;
        x.parent = y.parent;
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;if&lt;/span&gt; (y.parent == &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;null&lt;/span&gt;) {
            &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;this&lt;/span&gt;.mRoot = x;
        } &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;else&lt;/span&gt; {
            &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;if&lt;/span&gt; (y == y.parent.left) {
                y.parent.left = x;
            } &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;else&lt;/span&gt; {
                y.parent.right = x;
            }
        }
        &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//3. 将x的右子节点设为y，将y的父节点设为x&lt;/span&gt;
        x.right = y;
        y.parent = x;
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;3. 红黑树节点的添加&lt;/h3&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;红黑树的第 5 条特征规定，任一节点到它子树的每个叶子节点的路径中都包含同样数量的黑节点。也就是说当我们往红黑树中插入一个黑色节点时，会违背这条特征。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;同时第 4 条特征规定红色节点的左右孩子一定都是黑色节点，当我们给一个红色节点下插入一个红色节点时，会违背这条特征。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;因此我们需要在插入黑色节点后进行结构调整，保证红黑树始终满足这 5 条特征。&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.1  红黑树插入后节点的调整思想:&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;插入黑色节点的时候担心违背第5条，插入红色节点时担心违背第4条，所以我们将将&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;插入的节点改为红色，然后判断插入的节点的父亲是不是红色&lt;/strong&gt;，是的话进行修改调整（变色、左旋、右旋）。同时在调整的过程中我们需要遵守5条特性。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;新插入的节点是红色的，插入修复操作如果遇到父节点的颜色为黑则修复操作结束&lt;/strong&gt;。也就是说，&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;只有在父节点为红色节点的时候是需要插入修复操作的&lt;/strong&gt;。&lt;br/&gt;
插入修复操作分为以下的三种情况，而且新插入的节点的父节点都是红色的：&lt;/p&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;叔叔节点也为红色。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;叔叔节点为空，且祖父节点、父节点和新节点处于一条斜线上。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;叔叔节点为空，且祖父节点、父节点和新节点不处于一条斜线上。&lt;/li&gt;
&lt;/ol&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;3.1.1 插入操作-case 1(叔叔节点也为红色)&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/0a80e276-0cf2-49d0-8159-374844062547/7b9d03ec-b4c3-4c24-bd8a-3d2bdf1a9cdb.jpg&quot; /&gt;&lt;br/&gt;
&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;叔叔节点也为红色。&lt;/strong&gt;&lt;br/&gt;
case 1的操作是将 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;父节点和叔叔节点&lt;/strong&gt; 与 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;祖父节点&lt;/strong&gt; 的&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;颜色互换&lt;/strong&gt;，这样就符合了RBTRee的定义。即维持了高度的平衡，修复后颜色也符合RBTree定义的第三条和第四条。下图中，操作完成后A节点变成了新的节点。如果A节点的父节点不是黑色的话，则继续做修复操作。&lt;/p&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;3.1.2 插入操作-case 2&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/0a80e276-0cf2-49d0-8159-374844062547/f390ece2-3c7a-4d70-8ccf-fcc19c8316d5.jpg&quot; /&gt;&lt;br/&gt;
&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;叔叔节点为空，且祖父节点、父节点和新节点处于一条斜线上。&lt;/strong&gt;&lt;br/&gt;
case 2的操作是：&lt;/p&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;B和C都是左节点，将B节点进行右旋操作，并且和父节点A互换颜色。通过该修复操作RBTRee的高度和颜色都符合红黑树的定义。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;如果B和C节点都是右节点的话，只要将操作变成B节点左旋就可以了。&lt;/li&gt;
&lt;/ol&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;3.1.3 插入操作-case 3&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/0a80e276-0cf2-49d0-8159-374844062547/78acbcfe-b6cd-4641-8b45-cdb9ca82479e.jpg&quot; /&gt;&lt;br/&gt;
&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;叔叔节点为空，且祖父节点、父节点和新节点不处于一条斜线上。&lt;/strong&gt;&lt;br/&gt;
case 3的操作是：&lt;/p&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;C是右节点，将C节点进行左旋，这样就从case 3转换成case 2了，然后针对case 2进行操作处理就行了。case2操作C节点做了一个右旋操作和颜色互换来达到目的。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;如果C是左节点，将C节点进行右旋，转换成case2，再左旋就可以了。&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;4. 红黑树节点的删除&lt;/h3&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;如果删除节点的左孩子和右孩子不同时为null，那么只需要让其子树继承删除该节点的位置&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;如果删除的节点是叶子节点，我们直接进行调整；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;假如删除节点的左右孩子都不是null，需要后继节点替换被删除的节点和值和颜色，这样才不会引起红黑树平衡的破坏，只需要对 后继节点删除后进行调整，这样我们就回归处理情况 1 和 2 的状态；
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;后继节点为左子树最右边的子叶节点&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;后继节点为右子树最左边的叶子节点；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;如果需要删除的节点颜色为红色，那么红黑树的结构不被破坏，也就不需要进行调整。&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;如果我们判断删除节点的颜色为黑色，那么就进行调整；&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;4.1 红黑树删除之节点调整&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;调整思想：&lt;br/&gt;
为了保证删除节点的父节点左右两边黑色节点数一致，需要重点关注父节点没删除的那一边节点是不是黑色。&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;如果删除后父亲节点另一边比删除的一边黑色多，就要想办法搞到平衡。
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;1、把父亲节点另一边（即删除节点的兄弟树）其中一个节点弄成红色，也少了一个黑色。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;2、或者把另一边多的节点（染成黑色）转过来一个&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr style=&quot;line-height: 160%; box-sizing: content-box; border-top: 1px solid #eee; margin: 16px 0;&quot;/&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;删除修复操作是针对删除黑色节点才有的&lt;/strong&gt;，当黑色节点被删除后会让整个树不符合RBTree的定义的第四条。&lt;/li&gt;
&lt;/ul&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;当前节点是黑色的，且兄弟节点是红色的（那么父节点和兄弟节点的子节点肯定是黑色的）；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;当前节点是黑色的，且兄弟节点是黑色的，&lt;br/&gt;
1）、兄弟节点的两个子节点均为黑色的；&lt;br/&gt;
2）、兄弟节点的左子节点是红色，右子节点时黑色的；&lt;br/&gt;
3）、兄弟节点的右子节点是红色，左子节点任意颜色；&lt;/li&gt;
&lt;/ol&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.1.1 删除操作-case 1&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/0a80e276-0cf2-49d0-8159-374844062547/4e36b261-7fc0-4ffb-8cfe-396905023b75.jpg&quot; /&gt;&lt;br/&gt;
&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;待删除的节点的兄弟节点是红色的节点。&lt;/strong&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;将父节点涂红，将兄弟节点涂黑，然后将当前节点的父节点进行支点左旋。&lt;br/&gt;
case 1这样转换之后就会变成后面的case 2，case 3，或者case 4进行处理了。&lt;/p&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.1.2 删除操作-case 2&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/0a80e276-0cf2-49d0-8159-374844062547/7c3534c2-6ff8-43d7-a848-ee11bfbf9e6f.jpg&quot; /&gt;&lt;br/&gt;
&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;待删除的节点的兄弟节点是黑色的节点，且兄弟节点的子节点都是黑色的。&lt;/strong&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;将兄弟节点涂红，将当前节点指向其父节点，将其父节点指向当前节点的祖父节点，继续往树根递归判断以及调整；&lt;/p&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.1.3 删除操作-case 3&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/0a80e276-0cf2-49d0-8159-374844062547/7e8c6d89-fd19-4fc3-9e78-7de379c12f64.jpg&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;待调整的节点的兄弟节点是黑色的节点，且和兄弟节点在一条斜线上的子节点也是黑色，另一个子节点是红色。&lt;/strong&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;把当前节点的兄弟节点涂红，把兄弟节点的左子节点涂黑，然后以兄弟节点作为支点做右旋操作。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;case 3的删除操作是一个中间步骤，它的目的是将左边的红色节点借调过来，这样就可以转换成case 4&lt;/p&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.1.4 删除操作-case 4&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/0a80e276-0cf2-49d0-8159-374844062547/8a5d9c24-8890-4ee9-880b-9a60e4fb9216.jpg&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;待调整的节点的兄弟节点是黑色的节点，且和兄弟节点在一条斜线上的子节点是红色，另一个子节点任意&lt;/strong&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;把兄弟节点涂成父节点的颜色，再把父节点涂黑，把兄弟节点的右子节点涂黑，然后以当前节点的父节点为支点做左旋操作。&lt;/p&gt;
&lt;/div&gt;&lt;center style='display:none !important;visibility:collapse !important;height:0 !important;white-space:nowrap;width:100%;overflow:hidden'&gt;%5Btoc%5D%0A%23%23%20%E4%BA%8C%20.%20%E7%BA%A2%E9%BB%91%E6%A0%91%0A%23%23%23%201.%20%E7%BA%A2%E9%BB%91%E6%A0%91%E7%AE%80%E4%BB%8B%0A%E7%BA%A2%E9%BB%91%E6%A0%91%E6%98%AF%E6%AF%8F%E4%B8%AA%E8%8A%82%E7%82%B9%E9%83%BD%E5%B8%A6%E6%9C%89%E9%A2%9C%E8%89%B2%E5%B1%9E%E6%80%A7%E7%9A%84%E4%BA%8C%E5%8F%89%E6%9F%A5%E6%89%BE%E6%A0%91%EF%BC%8C%E9%A2%9C%E8%89%B2%E6%88%96%E7%BA%A2%E8%89%B2%E6%88%96%E9%BB%91%E8%89%B2%E3%80%82%E5%9C%A8%E4%BA%8C%E5%8F%89%E6%9F%A5%E6%89%BE%E6%A0%91%E5%BC%BA%E5%88%B6%E4%B8%80%E8%88%AC%E8%A6%81%E6%B1%82%E4%BB%A5%E5%A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%90%AB%E7%9B%B8%E5%90%8C%E6%95%B0%E7%9B%AE%E7%9A%84%E9%BB%91%E8%89%B2%E8%8A%82%E7%82%B9%E3%80%82%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/0a80e276-0cf2-49d0-8159-374844062547/4a780926-1eb4-4c95-b24a-1244b8169ad0.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F562%3A1)%0A%0A%23%23%23%202.%20%E7%BA%A2%E9%BB%91%E6%A0%91%E7%9A%84%E4%BF%AE%E6%AD%A3%0A%0A%E5%8F%98%E8%89%B2%E3%80%81%E5%B7%A6%E6%97%8B%E3%80%81%E5%8F%B3%E6%97%8B%E6%98%AF%E7%BA%A2%E9%BB%91%E6%A0%91%E5%9C%A8%E4%BA%8C%E5%8F%89%E6%A0%91%E4%B8%8A%E7%9A%84%E6%89%A9%E5%B1%95%E6%93%8D%E4%BD%9C%EF%BC%8C%E5%90%8C%E6%97%B6%E4%B9%9F%E6%98%AF%E5%9F%BA%E4%BA%8E%E8%BF%99%E4%B8%89%E4%B8%AA%E6%93%8D%E4%BD%9C%E6%89%8D%E8%83%BD%E9%81%B5%E5%AE%88%E7%BA%A2%E9%BB%91%E6%A0%91%E7%9A%84%E4%BA%94%E4%B8%AA%E7%89%B9%E6%80%A7%E3%80%82%0A%0A%23%23%23%23%202.1%20%E5%B7%A6%E6%97%8B%0A%20%20%20!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/0a80e276-0cf2-49d0-8159-374844062547/c6e0acce-f1d6-4613-a2a5-00adcb161b70.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F559%3A1)%0A%20%20%20%0A%60%60%60java%0A%C2%A0%C2%A0%C2%A0%20%2F*%0A%C2%A0%C2%A0%C2%A0%C2%A0%20*%20%E5%B7%A6%E6%97%8B%E5%81%9A%E4%BA%86%E4%B8%89%E4%BB%B6%E4%BA%8B%EF%BC%9A%0A%0A%C2%A0%C2%A0%C2%A0%C2%A0%20*%201.%20%E5%B0%86y%E7%9A%84%E5%B7%A6%E5%AD%90%E8%8A%82%E7%82%B9%E8%B5%8B%E7%BB%99x%E7%9A%84%E5%8F%B3%E5%AD%90%E8%8A%82%E7%82%B9%2C%E5%B9%B6%E5%B0%86x%E8%B5%8B%E7%BB%99y%E5%B7%A6%E5%AD%90%E8%8A%82%E7%82%B9%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9(y%E5%B7%A6%E5%AD%90%E8%8A%82%E7%82%B9%E9%9D%9E%E7%A9%BA%E6%97%B6)%0A%0A%C2%A0%C2%A0%C2%A0%C2%A0%20*%202.%20%E5%B0%86x%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9p(%E9%9D%9E%E7%A9%BA%E6%97%B6)%E8%B5%8B%E7%BB%99y%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9%EF%BC%8C%E5%90%8C%E6%97%B6%E6%9B%B4%E6%96%B0p%E7%9A%84%E5%AD%90%E8%8A%82%E7%82%B9%E4%B8%BAy(%E5%B7%A6%E6%88%96%E5%8F%B3)%0A%0A%C2%A0%C2%A0%C2%A0%C2%A0%20*%203.%20%E5%B0%86y%E7%9A%84%E5%B7%A6%E5%AD%90%E8%8A%82%E7%82%B9%E8%AE%BE%E4%B8%BAx%EF%BC%8C%E5%B0%86x%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9%E8%AE%BE%E4%B8%BAy%0A%0A%C2%A0%C2%A0%C2%A0%C2%A0%20*%2F%0A%C2%A0%C2%A0%C2%A0%20public%20void%20leftRotate(RBNode%3CT%3E%20x)%20%7B%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20if%20(x%20%3D%3D%20null)%20return%3B%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%2F%2F1.%20%E5%B0%86y%E7%9A%84%E5%B7%A6%E5%AD%90%E8%8A%82%E7%82%B9%E8%B5%8B%E7%BB%99x%E7%9A%84%E5%8F%B3%E5%AD%90%E8%8A%82%E7%82%B9%2C%E5%B9%B6%E5%B0%86x%E8%B5%8B%E7%BB%99y%E5%B7%A6%E5%AD%90%E8%8A%82%E7%82%B9%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9(y%E5%B7%A6%E5%AD%90%E8%8A%82%E7%82%B9%E9%9D%9E%E7%A9%BA%E6%97%B6)%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20RBNode%3CT%3E%20y%20%3D%20x.right%3B%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20x.right%20%3D%20y.left%3B%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20if%20(y.left%20!%3D%20null)%20%7B%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20y.left.parent%20%3D%20x%3B%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%7D%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%2F%2F2.%20%E5%B0%86x%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9p(%E9%9D%9E%E7%A9%BA%E6%97%B6)%E8%B5%8B%E7%BB%99y%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9%EF%BC%8C%E5%90%8C%E6%97%B6%E6%9B%B4%E6%96%B0p%E7%9A%84%E5%AD%90%E8%8A%82%E7%82%B9%E4%B8%BAy(%E5%B7%A6%E6%88%96%E5%8F%B3)%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20y.parent%20%3D%20x.parent%3B%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20if%20(x.parent%20%3D%3D%20null)%20%7B%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%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6%97%8B%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/0a80e276-0cf2-49d0-8159-374844062547/2dc577d2-7699-4e2f-a493-f428437c21c2.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F563%3A1)%0A%60%60%60java%0A%2F*%20%20%20%20%20%20%E5%8F%B3%E6%97%8B%E5%81%9A%E4%BA%86%E4%B8%89%E4%BB%B6%E4%BA%8B%EF%BC%9A%0A%C2%A0%C2%A0%C2%A0%C2%A0%20*%201.%20%E5%B0%86x%E7%9A%84%E5%8F%B3%E5%AD%90%E8%8A%82%E7%82%B9%E8%B5%8B%E7%BB%99y%E7%9A%84%E5%B7%A6%E5%AD%90%E8%8A%82%E7%82%B9%2C%E5%B9%B6%E5%B0%86y%E8%B5%8B%E7%BB%99x%E5%8F%B3%E5%AD%90%E8%8A%82%E7%82%B9%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9(x%E5%8F%B3%E5%AD%90%E8%8A%82%E7%82%B9%E9%9D%9E%E7%A9%BA%E6%97%B6)%0A%C2%A0%C2%A0%C2%A0%C2%A0%20*%202.%20%E5%B0%86y%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9p(%E9%9D%9E%E7%A9%BA%E6%97%B6)%E8%B5%8B%E7%BB%99x%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9%EF%BC%8C%E5%90%8C%E6%97%B6%E6%9B%B4%E6%96%B0p%E7%9A%84%E5%AD%90%E8%8A%82%E7%82%B9%E4%B8%BAx(%E5%B7%A6%E6%88%96%E5%8F%B3)%0A%C2%A0%C2%A0%C2%A0%C2%A0%20*%203.%20%E5%B0%86x%E7%9A%84%E5%8F%B3%E5%AD%90%E8%8A%82%E7%82%B9%E8%AE%BE%E4%B8%BAy%EF%BC%8C%E5%B0%86y%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9%E8%AE%BE%E4%B8%BAx%0A%C2%A0%C2%A0%C2%A0%C2%A0%20*%2F%0A%C2%A0%C2%A0%20public%20void%20rightRotate(RBNode%3CT%3E%20y)%20%7B%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20if%20(y%20%3D%3D%20null)%20return%3B%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%2F%2F1.%20%E5%B0%86x%E7%9A%84%E5%8F%B3%E5%AD%90%E8%8A%82%E7%82%B9%E8%B5%8B%E7%BB%99y%E7%9A%84%E5%B7%A6%E5%AD%90%E8%8A%82%E7%82%B9%2C%E5%B9%B6%E5%B0%86y%E8%B5%8B%E7%BB%99x%E5%8F%B3%E5%AD%90%E8%8A%82%E7%82%B9%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9(x%E5%8F%B3%E5%AD%90%E8%8A%82%E7%82%B9%E9%9D%9E%E7%A9%BA%E6%97%B6)%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20RBNode%3CT%3E%20x%20%3D%20y.left%3B%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20y.left%20%3D%20x.right%3B%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20if%20(x.right%20!%3D%20null)%20%7B%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20x.right.parent%20%3D%20y%3B%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%7D%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%2F%2F2.%20%E5%B0%86y%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9p(%E9%9D%9E%E7%A9%BA%E6%97%B6)%E8%B5%8B%E7%BB%99x%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9%EF%BC%8C%E5%90%8C%E6%97%B6%E6%9B%B4%E6%96%B0p%E7%9A%84%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%E8%89%B2%E8%8A%82%E7%82%B9%E7%9A%84%E6%97%B6%E5%80%99%E6%98%AF%E9%9C%80%E8%A6%81%E6%8F%92%E5%85%A5%E4%BF%AE%E5%A4%8D%E6%93%8D%E4%BD%9C%E7%9A%84**%E3%80%82%0A%E6%8F%92%E5%85%A5%E4%BF%AE%E5%A4%8D%E6%93%8D%E4%BD%9C%E5%88%86%E4%B8%BA%E4%BB%A5%E4%B8%8B%E7%9A%84%E4%B8%89%E7%A7%8D%E6%83%85%E5%86%B5%EF%BC%8C%E8%80%8C%E4%B8%94%E6%96%B0%E6%8F%92%E5%85%A5%E7%9A%84%E8%8A%82%E7%82%B9%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9%E9%83%BD%E6%98%AF%E7%BA%A2%E8%89%B2%E7%9A%84%EF%BC%9A%0A1.%20%E5%8F%94%E5%8F%94%E8%8A%82%E7%82%B9%E4%B9%9F%E4%B8%BA%E7%BA%A2%E8%89%B2%E3%80%82%0A2.%20%E5%8F%94%E5%8F%94%E8%8A%82%E7%82%B9%E4%B8%BA%E7%A9%BA%EF%BC%8C%E4%B8%94%E7%A5%96%E7%88%B6%E8%8A%82%E7%82%B9%E3%80%81%E7%88%B6%E8%8A%82%E7%82%B9%E5%92%8C%E6%96%B0%E8%8A%82%E7%82%B9%E5%A4%84%E4%BA%8E%E4%B8%80%E6%9D%A1%E6%96%9C%E7%BA%BF%E4%B8%8A%E3%80%82%0A3.%20%E5%8F%94%E5%8F%94%E8%8A%82%E7%82%B9%E4%B8%BA%E7%A9%BA%EF%BC%8C%E4%B8%94%E7%A5%96%E7%88%B6%E8%8A%82%E7%82%B9%E3%80%81%E7%88%B6%E8%8A%82%E7%82%B9%E5%92%8C%E6%96%B0%E8%8A%82%E7%82%B9%E4%B8%8D%E5%A4%84%E4%BA%8E%E4%B8%80%E6%9D%A1%E6%96%9C%E7%BA%BF%E4%B8%8A%E3%80%82%0A%0A%23%23%23%23%23%203.1.1%20%E6%8F%92%E5%85%A5%E6%93%8D%E4%BD%9C-case%201(%E5%8F%94%E5%8F%94%E8%8A%82%E7%82%B9%E4%B9%9F%E4%B8%BA%E7%BA%A2%E8%89%B2)%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/0a80e276-0cf2-49d0-8159-374844062547/7b9d03ec-b4c3-4c24-bd8a-3d2bdf1a9cdb.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F557%3A1)%0A**%E5%8F%94%E5%8F%94%E8%8A%82%E7%82%B9%E4%B9%9F%E4%B8%BA%E7%BA%A2%E8%89%B2%E3%80%82**%0Acase%201%E7%9A%84%E6%93%8D%E4%BD%9C%E6%98%AF%E5%B0%86%20**%E7%88%B6%E8%8A%82%E7%82%B9%E5%92%8C%E5%8F%94%E5%8F%94%E8%8A%82%E7%82%B9**%20%E4%B8%8E%20**%E7%A5%96%E7%88%B6%E8%8A%82%E7%82%B9**%20%E7%9A%84**%E9%A2%9C%E8%89%B2%E4%BA%92%E6%8D%A2**%EF%BC%8C%E8%BF%99%E6%A0%B7%E5%B0%B1%E7%AC%A6%E5%90%88%E4%BA%86RBTRee%E7%9A%84%E5%AE%9A%E4%B9%89%E3%80%82%E5%8D%B3%E7%BB%B4%E6%8C%81%E4%BA%86%E9%AB%98%E5%BA%A6%E7%9A%84%E5%B9%B3%E8%A1%A1%EF%BC%8C%E4%BF%AE%E5%A4%8D%E5%90%8E%E9%A2%9C%E8%89%B2%E4%B9%9F%E7%AC%A6%E5%90%88RBTree%E5%AE%9A%E4%B9%89%E7%9A%84%E7%AC%AC%E4%B8%89%E6%9D%A1%E5%92%8C%E7%AC%AC%E5%9B%9B%E6%9D%A1%E3%80%82%E4%B8%8B%E5%9B%BE%E4%B8%AD%EF%BC%8C%E6%93%8D%E4%BD%9C%E5%AE%8C%E6%88%90%E5%90%8EA%E8%8A%82%E7%82%B9%E5%8F%98%E6%88%90%E4%BA%86%E6%96%B0%E7%9A%84%E8%8A%82%E7%82%B9%E3%80%82%E5%A6%82%E6%9E%9CA%E8%8A%82%E7%82%B9%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9%E4%B8%8D%E6%98%AF%E9%BB%91%E8%89%B2%E7%9A%84%E8%AF%9D%EF%BC%8C%E5%88%99%E7%BB%A7%E7%BB%AD%E5%81%9A%E4%BF%AE%E5%A4%8D%E6%93%8D%E4%BD%9C%E3%80%82%0A%0A%23%23%23%23%23%203.1.2%20%E6%8F%92%E5%85%A5%E6%93%8D%E4%BD%9C-case%202%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/0a80e276-0cf2-49d0-8159-374844062547/f390ece2-3c7a-4d70-8ccf-fcc19c8316d5.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F558%3A1)%0A**%E5%8F%94%E5%8F%94%E8%8A%82%E7%82%B9%E4%B8%BA%E7%A9%BA%EF%BC%8C%E4%B8%94%E7%A5%96%E7%88%B6%E8%8A%82%E7%82%B9%E3%80%81%E7%88%B6%E8%8A%82%E7%82%B9%E5%92%8C%E6%96%B0%E8%8A%82%E7%82%B9%E5%A4%84%E4%BA%8E%E4%B8%80%E6%9D%A1%E6%96%9C%E7%BA%BF%E4%B8%8A%E3%80%82**%0Acase%202%E7%9A%84%E6%93%8D%E4%BD%9C%E6%98%AF%EF%BC%9A%0A1.%20B%E5%92%8CC%E9%83%BD%E6%98%AF%E5%B7%A6%E8%8A%82%E7%82%B9%EF%BC%8C%E5%B0%86B%E8%8A%82%E7%82%B9%E8%BF%9B%E8%A1%8C%E5%8F%B3%E6%97%8B%E6%93%8D%E4%BD%9C%EF%BC%8C%E5%B9%B6%E4%B8%94%E5%92%8C%E7%88%B6%E8%8A%82%E7%82%B9A%E4%BA%92%E6%8D%A2%E9%A2%9C%E8%89%B2%E3%80%82%E9%80%9A%E8%BF%87%E8%AF%A5%E4%BF%AE%E5%A4%8D%E6%93%8D%E4%BD%9CRBTRee%E7%9A%84%E9%AB%98%E5%BA%A6%E5%92%8C%E9%A2%9C%E8%89%B2%E9%83%BD%E7%AC%A6%E5%90%88%E7%BA%A2%E9%BB%91%E6%A0%91%E7%9A%84%E5%AE%9A%E4%B9%89%E3%80%82%0A2.%20%E5%A6%82%E6%9E%9CB%E5%92%8CC%E8%8A%82%E7%82%B9%E9%83%BD%E6%98%AF%E5%8F%B3%E8%8A%82%E7%82%B9%E7%9A%84%E8%AF%9D%EF%BC%8C%E5%8F%AA%E8%A6%81%E5%B0%86%E6%93%8D%E4%BD%9C%E5%8F%98%E6%88%90B%E8%8A%82%E7%82%B9%E5%B7%A6%E6%97%8B%E5%B0%B1%E5%8F%AF%E4%BB%A5%E4%BA%86%E3%80%82%0A%0A%23%23%23%23%23%203.1.3%20%E6%8F%92%E5%85%A5%E6%93%8D%E4%BD%9C-case%203%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/0a80e276-0cf2-49d0-8159-374844062547/78acbcfe-b6cd-4641-8b45-cdb9ca82479e.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F560%3A1)%0A**%E5%8F%94%E5%8F%94%E8%8A%82%E7%82%B9%E4%B8%BA%E7%A9%BA%EF%BC%8C%E4%B8%94%E7%A5%96%E7%88%B6%E8%8A%82%E7%82%B9%E3%80%81%E7%88%B6%E8%8A%82%E7%82%B9%E5%92%8C%E6%96%B0%E8%8A%82%E7%82%B9%E4%B8%8D%E5%A4%84%E4%BA%8E%E4%B8%80%E6%9D%A1%E6%96%9C%E7%BA%BF%E4%B8%8A%E3%80%82**%0Acase%203%E7%9A%84%E6%93%8D%E4%BD%9C%E6%98%AF%EF%BC%9A%0A1.%20C%E6%98%AF%E5%8F%B3%E8%8A%82%E7%82%B9%EF%BC%8C%E5%B0%86C%E8%8A%82%E7%82%B9%E8%BF%9B%E8%A1%8C%E5%B7%A6%E6%97%8B%EF%BC%8C%E8%BF%99%E6%A0%B7%E5%B0%B1%E4%BB%8Ecase%203%E8%BD%AC%E6%8D%A2%E6%88%90case%202%E4%BA%86%EF%BC%8C%E7%84%B6%E5%90%8E%E9%92%88%E5%AF%B9case%202%E8%BF%9B%E8%A1%8C%E6%93%8D%E4%BD%9C%E5%A4%84%E7%90%86%E5%B0%B1%E8%A1%8C%E4%BA%86%E3%80%82case2%E6%93%8D%E4%BD%9CC%E8%8A%82%E7%82%B9%E5%81%9A%E4%BA%86%E4%B8%80%E4%B8%AA%E5%8F%B3%E6%97%8B%E6%93%8D%E4%BD%9C%E5%92%8C%E9%A2%9C%E8%89%B2%E4%BA%92%E6%8D%A2%E6%9D%A5%E8%BE%BE%E5%88%B0%E7%9B%AE%E7%9A%84%E3%80%82%0A2.%20%E5%A6%82%E6%9E%9CC%E6%98%AF%E5%B7%A6%E8%8A%82%E7%82%B9%EF%BC%8C%E5%B0%86C%E8%8A%82%E7%82%B9%E8%BF%9B%E8%A1%8C%E5%8F%B3%E6%97%8B%EF%BC%8C%E8%BD%AC%E6%8D%A2%E6%88%90case2%EF%BC%8C%E5%86%8D%E5%B7%A6%E6%97%8B%E5%B0%B1%E5%8F%AF%E4%BB%A5%E4%BA%86%E3%80%82%0A%0A%23%23%23%204.%20%E7%BA%A2%E9%BB%91%E6%A0%91%E8%8A%82%E7%82%B9%E7%9A%84%E5%88%A0%E9%99%A4%0A%0A1.%20%E5%A6%82%E6%9E%9C%E5%88%A0%E9%99%A4%E8%8A%82%E7%82%B9%E7%9A%84%E5%B7%A6%E5%AD%A9%E5%AD%90%E5%92%8C%E5%8F%B3%E5%AD%A9%E5%AD%90%E4%B8%8D%E5%90%8C%E6%97%B6%E4%B8%BAnull%EF%BC%8C%E9%82%A3%E4%B9%88%E5%8F%AA%E9%9C%80%E8%A6%81%E8%AE%A9%E5%85%B6%E5%AD%90%E6%A0%91%E7%BB%A7%E6%89%BF%E5%88%A0%E9%99%A4%E8%AF%A5%E8%8A%82%E7%82%B9%E7%9A%84%E4%BD%8D%E7%BD%AE%0A2.%20%E5%A6%82%E6%9E%9C%E5%88%A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82%B9%E6%95%B0%E4%B8%80%E8%87%B4%EF%BC%8C%E9%9C%80%E8%A6%81%E9%87%8D%E7%82%B9%E5%85%B3%E6%B3%A8%E7%88%B6%E8%8A%82%E7%82%B9%E6%B2%A1%E5%88%A0%E9%99%A4%E7%9A%84%E9%82%A3%E4%B8%80%E8%BE%B9%E8%8A%82%E7%82%B9%E6%98%AF%E4%B8%8D%E6%98%AF%E9%BB%91%E8%89%B2%E3%80%82%0A*%20%E5%A6%82%E6%9E%9C%E5%88%A0%E9%99%A4%E5%90%8E%E7%88%B6%E4%BA%B2%E8%8A%82%E7%82%B9%E5%8F%A6%E4%B8%80%E8%BE%B9%E6%AF%94%E5%88%A0%E9%99%A4%E7%9A%84%E4%B8%80%E8%BE%B9%E9%BB%91%E8%89%B2%E5%A4%9A%EF%BC%8C%E5%B0%B1%E8%A6%81%E6%83%B3%E5%8A%9E%E6%B3%95%E6%90%9E%E5%88%B0%E5%B9%B3%E8%A1%A1%E3%80%82%0A%20%20%20%20*%201%E3%80%81%E6%8A%8A%E7%88%B6%E4%BA%B2%E8%8A%82%E7%82%B9%E5%8F%A6%E4%B8%80%E8%BE%B9%EF%BC%88%E5%8D%B3%E5%88%A0%E9%99%A4%E8%8A%82%E7%82%B9%E7%9A%84%E5%85%84%E5%BC%9F%E6%A0%91%EF%BC%89%E5%85%B6%E4%B8%AD%E4%B8%80%E4%B8%AA%E8%8A%82%E7%82%B9%E5%BC%84%E6%88%90%E7%BA%A2%E8%89%B2%EF%BC%8C%E4%B9%9F%E5%B0%91%E4%BA%86%E4%B8%80%E4%B8%AA%E9%BB%91%E8%89%B2%E3%80%82%20%0A%20%20%20%20*%202%E3%80%81%E6%88%96%E8%80%85%E6%8A%8A%E5%8F%A6%E4%B8%80%E8%BE%B9%E5%A4%9A%E7%9A%84%E8%8A%82%E7%82%B9%EF%BC%88%E6%9F%93%E6%88%90%E9%BB%91%E8%89%B2%EF%BC%89%E8%BD%AC%E8%BF%87%E6%9D%A5%E4%B8%80%E4%B8%AA%0A-%20-%20-%20%0A%0A*%20**%E5%88%A0%E9%99%A4%E4%BF%AE%E5%A4%8D%E6%93%8D%E4%BD%9C%E6%98%AF%E9%92%88%E5%AF%B9%E5%88%A0%E9%99%A4%E9%BB%91%E8%89%B2%E8%8A%82%E7%82%B9%E6%89%8D%E6%9C%89%E7%9A%84**%EF%BC%8C%E5%BD%93%E9%BB%91%E8%89%B2%E8%8A%82%E7%82%B9%E8%A2%AB%E5%88%A0%E9%99%A4%E5%90%8E%E4%BC%9A%E8%AE%A9%E6%95%B4%E4%B8%AA%E6%A0%91%E4%B8%8D%E7%AC%A6%E5%90%88RBTree%E7%9A%84%E5%AE%9A%E4%B9%89%E7%9A%84%E7%AC%AC%E5%9B%9B%E6%9D%A1%E3%80%82%0A%0A1.%20%E5%BD%93%E5%89%8D%E8%8A%82%E7%82%B9%E6%98%AF%E9%BB%91%E8%89%B2%E7%9A%84%EF%BC%8C%E4%B8%94%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E6%98%AF%E7%BA%A2%E8%89%B2%E7%9A%84%EF%BC%88%E9%82%A3%E4%B9%88%E7%88%B6%E8%8A%82%E7%82%B9%E5%92%8C%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E7%9A%84%E5%AD%90%E8%8A%82%E7%82%B9%E8%82%AF%E5%AE%9A%E6%98%AF%E9%BB%91%E8%89%B2%E7%9A%84%EF%BC%89%EF%BC%9B%0A2.%20%E5%BD%93%E5%89%8D%E8%8A%82%E7%82%B9%E6%98%AF%E9%BB%91%E8%89%B2%E7%9A%84%EF%BC%8C%E4%B8%94%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E6%98%AF%E9%BB%91%E8%89%B2%E7%9A%84%EF%BC%8C%0A%20%20%20%201%EF%BC%89%E3%80%81%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E7%9A%84%E4%B8%A4%E4%B8%AA%E5%AD%90%E8%8A%82%E7%82%B9%E5%9D%87%E4%B8%BA%E9%BB%91%E8%89%B2%E7%9A%84%EF%BC%9B%0A%20%20%20%202%EF%BC%89%E3%80%81%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E7%9A%84%E5%B7%A6%E5%AD%90%E8%8A%82%E7%82%B9%E6%98%AF%E7%BA%A2%E8%89%B2%EF%BC%8C%E5%8F%B3%E5%AD%90%E8%8A%82%E7%82%B9%E6%97%B6%E9%BB%91%E8%89%B2%E7%9A%84%EF%BC%9B%0A%20%20%20%203%EF%BC%89%E3%80%81%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E7%9A%84%E5%8F%B3%E5%AD%90%E8%8A%82%E7%82%B9%E6%98%AF%E7%BA%A2%E8%89%B2%EF%BC%8C%E5%B7%A6%E5%AD%90%E8%8A%82%E7%82%B9%E4%BB%BB%E6%84%8F%E9%A2%9C%E8%89%B2%EF%BC%9B%0A%0A%0A%23%23%23%23%23%204.1.1%20%E5%88%A0%E9%99%A4%E6%93%8D%E4%BD%9C-case%201%20%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/0a80e276-0cf2-49d0-8159-374844062547/4e36b261-7fc0-4ffb-8cfe-396905023b75.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F561%3A1)%0A**%E5%BE%85%E5%88%A0%E9%99%A4%E7%9A%84%E8%8A%82%E7%82%B9%E7%9A%84%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E6%98%AF%E7%BA%A2%E8%89%B2%E7%9A%84%E8%8A%82%E7%82%B9%E3%80%82**%0A%0A%E5%B0%86%E7%88%B6%E8%8A%82%E7%82%B9%E6%B6%82%E7%BA%A2%EF%BC%8C%E5%B0%86%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E6%B6%82%E9%BB%91%EF%BC%8C%E7%84%B6%E5%90%8E%E5%B0%86%E5%BD%93%E5%89%8D%E8%8A%82%E7%82%B9%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9%E8%BF%9B%E8%A1%8C%E6%94%AF%E7%82%B9%E5%B7%A6%E6%97%8B%E3%80%82%0Acase%201%E8%BF%99%E6%A0%B7%E8%BD%AC%E6%8D%A2%E4%B9%8B%E5%90%8E%E5%B0%B1%E4%BC%9A%E5%8F%98%E6%88%90%E5%90%8E%E9%9D%A2%E7%9A%84case%202%EF%BC%8Ccase%203%EF%BC%8C%E6%88%96%E8%80%85case%204%E8%BF%9B%E8%A1%8C%E5%A4%84%E7%90%86%E4%BA%86%E3%80%82%0A%0A%23%23%23%23%23%204.1.2%20%E5%88%A0%E9%99%A4%E6%93%8D%E4%BD%9C-case%202%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/0a80e276-0cf2-49d0-8159-374844062547/7c3534c2-6ff8-43d7-a848-ee11bfbf9e6f.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F565%3A1)%0A**%E5%BE%85%E5%88%A0%E9%99%A4%E7%9A%84%E8%8A%82%E7%82%B9%E7%9A%84%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E6%98%AF%E9%BB%91%E8%89%B2%E7%9A%84%E8%8A%82%E7%82%B9%EF%BC%8C%E4%B8%94%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E7%9A%84%E5%AD%90%E8%8A%82%E7%82%B9%E9%83%BD%E6%98%AF%E9%BB%91%E8%89%B2%E7%9A%84%E3%80%82**%0A%0A%E5%B0%86%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E6%B6%82%E7%BA%A2%EF%BC%8C%E5%B0%86%E5%BD%93%E5%89%8D%E8%8A%82%E7%82%B9%E6%8C%87%E5%90%91%E5%85%B6%E7%88%B6%E8%8A%82%E7%82%B9%EF%BC%8C%E5%B0%86%E5%85%B6%E7%88%B6%E8%8A%82%E7%82%B9%E6%8C%87%E5%90%91%E5%BD%93%E5%89%8D%E8%8A%82%E7%82%B9%E7%9A%84%E7%A5%96%E7%88%B6%E8%8A%82%E7%82%B9%EF%BC%8C%E7%BB%A7%E7%BB%AD%E5%BE%80%E6%A0%91%E6%A0%B9%E9%80%92%E5%BD%92%E5%88%A4%E6%96%AD%E4%BB%A5%E5%8F%8A%E8%B0%83%E6%95%B4%EF%BC%9B%0A%0A%23%23%23%23%23%204.1.3%20%E5%88%A0%E9%99%A4%E6%93%8D%E4%BD%9C-case%203%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/0a80e276-0cf2-49d0-8159-374844062547/7e8c6d89-fd19-4fc3-9e78-7de379c12f64.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F564%3A1)%0A%0A**%E5%BE%85%E8%B0%83%E6%95%B4%E7%9A%84%E8%8A%82%E7%82%B9%E7%9A%84%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E6%98%AF%E9%BB%91%E8%89%B2%E7%9A%84%E8%8A%82%E7%82%B9%EF%BC%8C%E4%B8%94%E5%92%8C%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E5%9C%A8%E4%B8%80%E6%9D%A1%E6%96%9C%E7%BA%BF%E4%B8%8A%E7%9A%84%E5%AD%90%E8%8A%82%E7%82%B9%E4%B9%9F%E6%98%AF%E9%BB%91%E8%89%B2%EF%BC%8C%E5%8F%A6%E4%B8%80%E4%B8%AA%E5%AD%90%E8%8A%82%E7%82%B9%E6%98%AF%E7%BA%A2%E8%89%B2%E3%80%82**%0A%0A%E6%8A%8A%E5%BD%93%E5%89%8D%E8%8A%82%E7%82%B9%E7%9A%84%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E6%B6%82%E7%BA%A2%EF%BC%8C%E6%8A%8A%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E7%9A%84%E5%B7%A6%E5%AD%90%E8%8A%82%E7%82%B9%E6%B6%82%E9%BB%91%EF%BC%8C%E7%84%B6%E5%90%8E%E4%BB%A5%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E4%BD%9C%E4%B8%BA%E6%94%AF%E7%82%B9%E5%81%9A%E5%8F%B3%E6%97%8B%E6%93%8D%E4%BD%9C%E3%80%82%0A%0Acase%203%E7%9A%84%E5%88%A0%E9%99%A4%E6%93%8D%E4%BD%9C%E6%98%AF%E4%B8%80%E4%B8%AA%E4%B8%AD%E9%97%B4%E6%AD%A5%E9%AA%A4%EF%BC%8C%E5%AE%83%E7%9A%84%E7%9B%AE%E7%9A%84%E6%98%AF%E5%B0%86%E5%B7%A6%E8%BE%B9%E7%9A%84%E7%BA%A2%E8%89%B2%E8%8A%82%E7%82%B9%E5%80%9F%E8%B0%83%E8%BF%87%E6%9D%A5%EF%BC%8C%E8%BF%99%E6%A0%B7%E5%B0%B1%E5%8F%AF%E4%BB%A5%E8%BD%AC%E6%8D%A2%E6%88%90case%204%0A%0A%23%23%23%23%23%204.1.4%20%E5%88%A0%E9%99%A4%E6%93%8D%E4%BD%9C-case%204%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/0a80e276-0cf2-49d0-8159-374844062547/8a5d9c24-8890-4ee9-880b-9a60e4fb9216.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F556%3A1)%0A%0A**%E5%BE%85%E8%B0%83%E6%95%B4%E7%9A%84%E8%8A%82%E7%82%B9%E7%9A%84%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E6%98%AF%E9%BB%91%E8%89%B2%E7%9A%84%E8%8A%82%E7%82%B9%EF%BC%8C%E4%B8%94%E5%92%8C%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E5%9C%A8%E4%B8%80%E6%9D%A1%E6%96%9C%E7%BA%BF%E4%B8%8A%E7%9A%84%E5%AD%90%E8%8A%82%E7%82%B9%E6%98%AF%E7%BA%A2%E8%89%B2%EF%BC%8C%E5%8F%A6%E4%B8%80%E4%B8%AA%E5%AD%90%E8%8A%82%E7%82%B9%E4%BB%BB%E6%84%8F**%0A%0A%E6%8A%8A%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E6%B6%82%E6%88%90%E7%88%B6%E8%8A%82%E7%82%B9%E7%9A%84%E9%A2%9C%E8%89%B2%EF%BC%8C%E5%86%8D%E6%8A%8A%E7%88%B6%E8%8A%82%E7%82%B9%E6%B6%82%E9%BB%91%EF%BC%8C%E6%8A%8A%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E7%9A%84%E5%8F%B3%E5%AD%90%E8%8A%82%E7%82%B9%E6%B6%82%E9%BB%91%EF%BC%8C%E7%84%B6%E5%90%8E%E4%BB%A5%E5%BD%93%E5%89%8D%E8%8A%82%E7%82%B9%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9%E4%B8%BA%E6%94%AF%E7%82%B9%E5%81%9A%E5%B7%A6%E6%97%8B%E6%93%8D%E4%BD%9C%E3%80%82%0A&lt;/center&gt;&lt;/div&gt;
</content>
  </entry>
  <entry xml:base="http://linzhiteng.postach.io/feed.xml">
    <title type="text">三 . B树、B+树、B*树</title>
    <id>https://linzhiteng.postach.io/post/san-bshu-b-shu-b-shu</id>
    <updated>2019-06-09T13:26:36.498000Z</updated>
    <published>2019-03-16T03:22:44Z</published>
    <link href="https://linzhiteng.postach.io/post/san-bshu-b-shu-b-shu" />
    <author>
      <name>linzhi teng</name>
    </author>
    <category term="shu" />
    <content type="html">&lt;div&gt;&lt;div style=&quot;font-size: 14px; margin: 0; padding: 0; width: 100%;&quot;&gt;&lt;div style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;三 . B树、B+树、B*树
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1 B树(B-树)
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1.1 B树简介
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1.2 B树特点
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1.3 B树的查找
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;查找操作的时间开销
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1.4 B树的插入
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1.5 B树的删除
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.2 B+树
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.2.1 B+树简介
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;B+树用途
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.2.2 B+树定义
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;B+树与B-树的不同
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.2.3 B+树的特性：
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.2.4 B+树 vs B树
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.3 B*树
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.3.1 B*树简介
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.3.2 B*树 vs B+树
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.4 小结：
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;三 . B树、B+树、B*树&lt;/h2&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;3.1 B树(B-树)&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.1.1 B树简介&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;B-树是一种多路搜索树（并不一定是二叉的）&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;1970年，R.Bayer和E.mccreight提出了一种适用于外查找的树，它是一种平衡的多叉树，称为B树（或B-树、B_树）。&lt;/li&gt;
&lt;/ul&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;B-Tree的接点结构B-tree中，每个&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;结点&lt;/strong&gt;包含：&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;本结点所含关键字的个数；&lt;br/&gt;
指向父结点的指针；&lt;br/&gt;
关键字；&lt;br/&gt;
指向子结点的指针数组；&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/1b373e0a-8510-40e0-b50f-b087843843a5/1d85ca58-cb9d-4fee-9251-5b1754b4475d.jpg&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;一棵m阶B树(balanced tree of order m)是一棵平衡的m路搜索树。它或者是空树，或者是满足下列性质的树：&lt;br/&gt;
1、根结点至少有两个子女；&lt;br/&gt;
2、每个非根节点所包含的关键字个数 j 满足：m/2 - 1 &lt;= j &lt;= m - 1；&lt;br/&gt;
3、除根结点以外的所有结点（不包括叶子结点）的度数正好是关键字总数加1，故内部子树个数 k 满足：m/2 &lt;= k &lt;= m ；&lt;br/&gt;
4、所有的叶子结点都位于同一层。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.1.2 B树特点&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;是一种多路搜索树（并不是二叉的）：&lt;/p&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;定义任意非叶子结点最多只有M个儿子；且M&gt;2；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;根结点的儿子数为[2, M]；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;除根结点以外的非叶子结点的儿子数为[M/2, M]；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;每个结点存放至少M/2-1（取上整）和至多M-1个关键字；（至少2个关键字）&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;非叶子结点的关键字个数=指向儿子的指针个数-1；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;非叶子结点的关键字：K[1], K[2], …, K[M-1]；且K[i] &lt; K[i+1]；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;非叶子结点的指针：P[1], P[2], …, P[M]；其中P[1]指向关键字小于K[1]的子树，P[M]指向关键字大于K[M-1]的子树，其它P[i]指向关键字属于(K[i-1], K[i])的子树；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;所有叶子结点位于同一层；&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.1.3 B树的查找&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/1b373e0a-8510-40e0-b50f-b087843843a5/635a7e19-ba45-40ef-808e-7ca458e25f2f.png&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;在B-树中查找给定关键字的方法类似于二叉排序树上的查找。不同的是在每个结点上确定向下查找的路径不一定是二路而是keynum+1路的。&lt;br/&gt;
对&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;结点内的存放有序关键字序列&lt;/strong&gt;的向量key[l..keynum] 用&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;顺序查找或折半查找方法查找&lt;/strong&gt;。&lt;/p&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;若在某结点内找到待查的关键字K，则返回该结点的地址及K在key[1..keynum]中的位置；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;否则，确定K在某个key[i]和key[i+1]之间结点后，从磁盘中读son[i]所指的结点继续查找。直到在某结点中查找成功；或直至找到叶结点且叶结点中的查找仍不成功时，查找过程失败。&lt;/li&gt;
&lt;/ol&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;查找操作的时间开销&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;B-树上的查找有两个基本步骤：&lt;/p&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;在B-树中查找结点，该查找涉及读盘DiskRead操作，属外查找；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;在结点内查找，该查找属内查找。&lt;/li&gt;
&lt;/ol&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;查找操作的时间为：&lt;/p&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;外查找的读盘次数不超过树高h，故其时间是O(h)；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;内查找中，每个结点内的关键字数目keynum&lt;m(m是B-树的阶数)，故其时间为O(nh)。&lt;/li&gt;
&lt;/ol&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;注意：&lt;/p&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;实际上外查找时间可能远远大于内查找时间。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;B-树作为数据库文件时，打开文件之后就必须将根结点读人内存，而直至文件关闭之前，此根一直驻留在内存中，故查找时可以不计读入根结点的时间。&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.1.4 B树的插入&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;插入一个元素时：&lt;/p&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;首先判断在B树中是否存在，如果不存在，即在叶子结点处结束，然后在叶子结点中插入该新的元素&lt;/li&gt;
&lt;/ol&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;注意：&lt;br/&gt;
1.1 如果叶子结点空间足够，这里需要向右移动该叶子结点中大于新插入关键字的元素，&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;1.2 如果叶子节点空间满了以致没有足够的空间去添加新的元素，则将该结点进行&quot;分裂&quot;，将一半数量的关键字元素分裂到新的其相邻右结点中，中间关键字元素上移到父结点中（当然，如果父结点空间满了，也同样需要&quot;分裂&quot;操作），而且当结点中关键元素向右移动了，相关的指针也需要向右移。&lt;br/&gt;
1.3 如果在根结点插入新元素，空间满了，则进行分裂操作，这样原来的根结点中的中间关键字元素向上移动到新的根结点中，因此导致树的高度增加一层。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.1.5 B树的删除&lt;/h4&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;首先查找B树中需删除的元素,如果该元素在B树中存在，则将该元素在其结点中进行删除，&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;如果删除该元素后，首先判断该元素是否有左右孩子结点，如果有，则上移孩子结点中的某相近元素到父节点中，然后是移动之后的情况；如果没有，直接删除后，移动之后的情况。&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;3.2 B+树&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.2.1 B+树简介&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;B+ 树是一种树数据结构，是一个n叉树，每个节点通常有多个孩子。&lt;br/&gt;
一棵B+树包含根节点、内部节点和叶子节点。根节点可能是一个叶子节点，也可能是一个包含两个或两个以上孩子节点的节点。&lt;/p&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;B+树用途&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;B+ 树通常用于数据库和操作系统的文件系统中。NTFS, ReiserFS, NSS, XFS, JFS, ReFS 和BFS等文件系统都在使用B+树作为元数据索引。B+ 树的特点是能够保持数据稳定有序，其插入与修改拥有较稳定的对数时间复杂度。B+ 树元素自底向上插入。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.2.2 B+树定义&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;B+树是应文件系统所需而出的一种B-树的变型树。&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/1b373e0a-8510-40e0-b50f-b087843843a5/afdfb4c9-f6e7-4f69-a6db-c1c6ba089687.jpg&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;一棵m阶的B+树和m阶的B-树的差异在于：&lt;br/&gt;
1.有n棵子树的结点中含有n个关键字，每个&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;关键字不保存数据，只用来索引&lt;/strong&gt;，所有&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;数据都保存在叶子节点&lt;/strong&gt;。&lt;br/&gt;
2.所有的叶子结点中包含了全部关键字的信息，及指向含这些关键字记录的指针，且&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;叶子结点本身依关键字的大小自小而大顺序链接&lt;/strong&gt;。&lt;br/&gt;
3.所有的非终端结点可以看成是索引部分，结点中仅含其子树（根结点）中的最大（或最小）关键字。 &lt;br/&gt;
通常在B+树上有两个头指针，一个指向根结点，一个指向关键字最小的叶子结点。&lt;/p&gt;
&lt;hr style=&quot;line-height: 160%; box-sizing: content-box; border-top: 1px solid #eee; margin: 16px 0;&quot;/&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;B+树与B-树的不同&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;B+树是B-树的变体，也是一种多路搜索树：&lt;/p&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;定义基本与B-树同，除了：&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;叶子结点的子树指针与关键字个数相同；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;叶子结点的子树指针P[i]，指向关键字值属于[K[i], K[i+1])的子树（B-树是开区间）；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;为&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;所有叶子结点增加一个链指针&lt;/strong&gt;；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;所有关键字都在叶子结点出现；&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.2.3 B+树的特性：&lt;/h4&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;所有关键字都出现在叶子结点的链表中（稠密索引），且链表中的关键字恰好是有序的；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;不可能在非叶子结点命中；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;非叶子结点相当于是叶子结点的索引（稀疏索引），叶子结点相当于是存储（关键字）数据的数据层；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;更适合文件索引系统；&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.2.4 B+树 vs B树&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;为什么说B+-tree比B 树更适合实际应用中操作系统的文件索引和数据库索引？&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;B+-tree的磁盘读写代价更低&lt;br/&gt;
B+-tree的内部结点并没有指向关键字具体信息的指针。因此其内部结点相对B 树更小。如果把所有同一内部结点的关键字存放在同一盘块中，那么盘块所能容纳的关键字数量也越多。一次性读入内存中的需要查找的关键字也就越多。相对来说IO读写次数也就降低了。&lt;br/&gt;
举个例子，假设磁盘中的一个盘块容纳16bytes，而一个关键字2bytes，一个关键字具体信息指针2bytes。一棵9阶B-tree(一个结点最多8个关键字)的内部结点需要2个盘快。而B+ 树内部结点只需要1个盘快。当需要把内部结点读入内存中的时候，B 树就比B+ 树多一次盘块查找时间(在磁盘中就是盘片旋转的时间)。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;B+-tree的查询效率更加稳定&lt;br/&gt;
由于非终结点并不是最终指向文件内容的结点，而只是叶子结点中关键字的索引。所以任何关键字的查找必须走一条从根结点到叶子结点的路。所有关键字查询的路径长度相同，导致每一个数据的查询效率相当。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;3.3 B*树&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.3.1 B*树简介&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;是B+树的变体，在B+树的非根和非叶子结点再增加指向兄弟的指针；&lt;br/&gt;
B*树定义了非叶子结点关键字个数至少为(2/3)*M，即块的最低使用率为2/3（代替B+树的1/2）；&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/1b373e0a-8510-40e0-b50f-b087843843a5/2502aaf0-b699-43ca-b2fb-1d1c3ac848a2.jpg&quot; /&gt;&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.3.2 B*树 vs B+树&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; color: #333; margin: 0;&quot;&gt;B+树的分裂：&lt;br/&gt;
当一个结点满时，分配一个新的结点，并将原结点中1/2的数据复制到新结点，最后在父结点中增加新结点的指针；B+树的分裂只影响原结点和父结点，而不会影响兄弟结点，所以它不需要指向兄弟的指针；&lt;/p&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; color: #333; margin: 0;&quot;&gt;B*树的分裂：&lt;br/&gt;
当一个结点满时，如果它的下一个兄弟结点未满，那么将一部分数据移到兄弟结点中，再在原结点插入关键字，最后修改父结点中兄弟结点的关键字（因为兄弟结点的关键字范围改变了）；如果兄弟也满了，则在原结点与兄弟结点之间增加新结点，并各复制1/3的数据到新结点，最后在父结点增加新结点的指针；&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;所以，B*树分配新结点的概率比B+树要低，空间使用率更高；&lt;/p&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;3.4 小结：&lt;/h3&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;B-树：&lt;br/&gt;
多路搜索树，每个结点存储M/2到M个关键字，非叶子结点存储指向关键字范围的子结点；&lt;br/&gt;
所有关键字在整颗树中出现，且只出现一次，非叶子结点可以命中；&lt;/li&gt;
&lt;/ul&gt;
&lt;hr style=&quot;line-height: 160%; box-sizing: content-box; border-top: 1px solid #eee; margin: 16px 0;&quot;/&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;B+树：在B-树基础上，为叶子结点增加链表指针，所有关键字都在叶子结点中出现，非叶子结点作为叶子结点的索引；&lt;br/&gt;
B+树总是到叶子结点才命中；&lt;/li&gt;
&lt;/ul&gt;
&lt;hr style=&quot;line-height: 160%; box-sizing: content-box; border-top: 1px solid #eee; margin: 16px 0;&quot;/&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;B*树：在B+树基础上，为非叶子结点也增加链表指针，将结点的最低利用率从1/2提高到2/3；&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;&lt;center style='display:none !important;visibility:collapse !important;height:0 !important;white-space:nowrap;width:100%;overflow:hidden'&gt;%5Btoc%5D%0A%23%23%20%E4%B8%89%20.%20B%E6%A0%91%E3%80%81B%2B%E6%A0%91%E3%80%81B*%E6%A0%91%20%0A%0A%23%23%23%203.1%20B%E6%A0%91(B-%E6%A0%91)%0A%23%23%23%23%203.1.1%20B%E6%A0%91%E7%AE%80%E4%BB%8B%0A*%20B-%E6%A0%91%E6%98%AF%E4%B8%80%E7%A7%8D%E5%A4%9A%E8%B7%AF%E6%90%9C%E7%B4%A2%E6%A0%91%EF%BC%88%E5%B9%B6%E4%B8%8D%E4%B8%80%E5%AE%9A%E6%98%AF%E4%BA%8C%E5%8F%89%E7%9A%84%EF%BC%89%0A*%201970%E5%B9%B4%EF%BC%8CR.Bayer%E5%92%8CE.mccreight%E6%8F%90%E5%87%BA%E4%BA%86%E4%B8%80%E7%A7%8D%E9%80%82%E7%94%A8%E4%BA%8E%E5%A4%96%E6%9F%A5%E6%89%BE%E7%9A%84%E6%A0%91%EF%BC%8C%E5%AE%83%E6%98%AF%E4%B8%80%E7%A7%8D%E5%B9%B3%E8%A1%A1%E7%9A%84%E5%A4%9A%E5%8F%89%E6%A0%91%EF%BC%8C%E7%A7%B0%E4%B8%BAB%E6%A0%91%EF%BC%88%E6%88%96B-%E6%A0%91%E3%80%81B_%E6%A0%91%EF%BC%89%E3%80%82%0A%0A%0AB-Tree%E7%9A%84%E6%8E%A5%E7%82%B9%E7%BB%93%E6%9E%84B-tree%E4%B8%AD%EF%BC%8C%E6%AF%8F%E4%B8%AA**%E7%BB%93%E7%82%B9**%E5%8C%85%E5%90%AB%EF%BC%9A%0A%3E%E6%9C%AC%E7%BB%93%E7%82%B9%E6%89%80%E5%90%AB%E5%85%B3%E9%94%AE%E5%AD%97%E7%9A%84%E4%B8%AA%E6%95%B0%EF%BC%9B%0A%E6%8C%87%E5%90%91%E7%88%B6%E7%BB%93%E7%82%B9%E7%9A%84%E6%8C%87%E9%92%88%EF%BC%9B%0A%E5%85%B3%E9%94%AE%E5%AD%97%EF%BC%9B%0A%E6%8C%87%E5%90%91%E5%AD%90%E7%BB%93%E7%82%B9%E7%9A%84%E6%8C%87%E9%92%88%E6%95%B0%E7%BB%84%EF%BC%9B%0A%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/1b373e0a-8510-40e0-b50f-b087843843a5/1d85ca58-cb9d-4fee-9251-5b1754b4475d.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F569%3A1)%0A%0A%0A%E4%B8%80%E6%A3%B5m%E9%98%B6B%E6%A0%91(balanced%20tree%20of%20order%20m)%E6%98%AF%E4%B8%80%E6%A3%B5%E5%B9%B3%E8%A1%A1%E7%9A%84m%E8%B7%AF%E6%90%9C%E7%B4%A2%E6%A0%91%E3%80%82%E5%AE%83%E6%88%96%E8%80%85%E6%98%AF%E7%A9%BA%E6%A0%91%EF%BC%8C%E6%88%96%E8%80%85%E6%98%AF%E6%BB%A1%E8%B6%B3%E4%B8%8B%E5%88%97%E6%80%A7%E8%B4%A8%E7%9A%84%E6%A0%91%EF%BC%9A%0A1%E3%80%81%E6%A0%B9%E7%BB%93%E7%82%B9%E8%87%B3%E5%B0%91%E6%9C%89%E4%B8%A4%E4%B8%AA%E5%AD%90%E5%A5%B3%EF%BC%9B%0A2%E3%80%81%E6%AF%8F%E4%B8%AA%E9%9D%9E%E6%A0%B9%E8%8A%82%E7%82%B9%E6%89%80%E5%8C%85%E5%90%AB%E7%9A%84%E5%85%B3%E9%94%AE%E5%AD%97%E4%B8%AA%E6%95%B0%20j%20%E6%BB%A1%E8%B6%B3%EF%BC%9Am%2F2%20-%201%20%3C%3D%20j%20%3C%3D%20m%20-%201%EF%BC%9B%0A3%E3%80%81%E9%99%A4%E6%A0%B9%E7%BB%93%E7%82%B9%E4%BB%A5%E5%A4%96%E7%9A%84%E6%89%80%E6%9C%89%E7%BB%93%E7%82%B9%EF%BC%88%E4%B8%8D%E5%8C%85%E6%8B%AC%E5%8F%B6%E5%AD%90%E7%BB%93%E7%82%B9%EF%BC%89%E7%9A%84%E5%BA%A6%E6%95%B0%E6%AD%A3%E5%A5%BD%E6%98%AF%E5%85%B3%E9%94%AE%E5%AD%97%E6%80%BB%E6%95%B0%E5%8A%A01%EF%BC%8C%E6%95%85%E5%86%85%E9%83%A8%E5%AD%90%E6%A0%91%E4%B8%AA%E6%95%B0%20k%20%E6%BB%A1%E8%B6%B3%EF%BC%9Am%2F2%20%3C%3D%20k%20%3C%3D%20m%20%EF%BC%9B%0A4%E3%80%81%E6%89%80%E6%9C%89%E7%9A%84%E5%8F%B6%E5%AD%90%E7%BB%93%E7%82%B9%E9%83%BD%E4%BD%8D%E4%BA%8E%E5%90%8C%E4%B8%80%E5%B1%82%E3%80%82%0A%0A%23%23%23%23%203.1.2%20B%E6%A0%91%E7%89%B9%E7%82%B9%0A%0A%E6%98%AF%E4%B8%80%E7%A7%8D%E5%A4%9A%E8%B7%AF%E6%90%9C%E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7%9A%84%E5%85%B3%E9%94%AE%E5%AD%97%EF%BC%9AK%5B1%5D%2C%20K%5B2%5D%2C%20%E2%80%A6%2C%20K%5BM-1%5D%EF%BC%9B%E4%B8%94K%5Bi%5D%20%3C%20K%5Bi%2B1%5D%EF%BC%9B%0A7.%20%E9%9D%9E%E5%8F%B6%E5%AD%90%E7%BB%93%E7%82%B9%E7%9A%84%E6%8C%87%E9%92%88%EF%BC%9AP%5B1%5D%2C%20P%5B2%5D%2C%20%E2%80%A6%2C%20P%5BM%5D%EF%BC%9B%E5%85%B6%E4%B8%ADP%5B1%5D%E6%8C%87%E5%90%91%E5%85%B3%E9%94%AE%E5%AD%97%E5%B0%8F%E4%BA%8EK%5B1%5D%E7%9A%84%E5%AD%90%E6%A0%91%EF%BC%8CP%5BM%5D%E6%8C%87%E5%90%91%E5%85%B3%E9%94%AE%E5%AD%97%E5%A4%A7%E4%BA%8EK%5BM-1%5D%E7%9A%84%E5%AD%90%E6%A0%91%EF%BC%8C%E5%85%B6%E5%AE%83P%5Bi%5D%E6%8C%87%E5%90%91%E5%85%B3%E9%94%AE%E5%AD%97%E5%B1%9E%E4%BA%8E(K%5Bi-1%5D%2C%20K%5Bi%5D)%E7%9A%84%E5%AD%90%E6%A0%91%EF%BC%9B%0A8.%20%E6%89%80%E6%9C%89%E5%8F%B6%E5%AD%90%E7%BB%93%E7%82%B9%E4%BD%8D%E4%BA%8E%E5%90%8C%E4%B8%80%E5%B1%82%EF%BC%9B%0A%0A%23%23%23%23%203.1.3%20B%E6%A0%91%E7%9A%84%E6%9F%A5%E6%89%BE%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/1b373e0a-8510-40e0-b50f-b087843843a5/635a7e19-ba45-40ef-808e-7ca458e25f2f.png.png%5D(en-resource%3A%2F%2Fdatabase%2F570%3A1)%0A%0A%E5%9C%A8B-%E6%A0%91%E4%B8%AD%E6%9F%A5%E6%89%BE%E7%BB%99%E5%AE%9A%E5%85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BA%E5%85%83%E6%95%B0%E6%8D%AE%E7%B4%A2%E5%BC%95%E3%80%82B%2B%20%E6%A0%91%E7%9A%84%E7%89%B9%E7%82%B9%E6%98%AF%E8%83%BD%E5%A4%9F%E4%BF%9D%E6%8C%81%E6%95%B0%E6%8D%AE%E7%A8%B3%E5%AE%9A%E6%9C%89%E5%BA%8F%EF%BC%8C%E5%85%B6%E6%8F%92%E5%85%A5%E4%B8%8E%E4%BF%AE%E6%94%B9%E6%8B%A5%E6%9C%89%E8%BE%83%E7%A8%B3%E5%AE%9A%E7%9A%84%E5%AF%B9%E6%95%B0%E6%97%B6%E9%97%B4%E5%A4%8D%E6%9D%82%E5%BA%A6%E3%80%82B%2B%20%E6%A0%91%E5%85%83%E7%B4%A0%E8%87%AA%E5%BA%95%E5%90%91%E4%B8%8A%E6%8F%92%E5%85%A5%E3%80%82%0A%0A%23%23%23%23%203.2.2%20B%2B%E6%A0%91%E5%AE%9A%E4%B9%89%0AB%2B%E6%A0%91%E6%98%AF%E5%BA%94%E6%96%87%E4%BB%B6%E7%B3%BB%E7%BB%9F%E6%89%80%E9%9C%80%E8%80%8C%E5%87%BA%E7%9A%84%E4%B8%80%E7%A7%8DB-%E6%A0%91%E7%9A%84%E5%8F%98%E5%9E%8B%E6%A0%91%E3%80%82%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/1b373e0a-8510-40e0-b50f-b087843843a5/afdfb4c9-f6e7-4f69-a6db-c1c6ba089687.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F568%3A1)%0A%0A%E4%B8%80%E6%A3%B5m%E9%98%B6%E7%9A%84B%2B%E6%A0%91%E5%92%8Cm%E9%98%B6%E7%9A%84B-%E6%A0%91%E7%9A%84%E5%B7%AE%E5%BC%82%E5%9C%A8%E4%BA%8E%EF%BC%9A%0A1.%E6%9C%89n%E6%A3%B5%E5%AD%90%E6%A0%91%E7%9A%84%E7%BB%93%E7%82%B9%E4%B8%AD%E5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A%8E%E6%98%AF%E5%8F%B6%E5%AD%90%E7%BB%93%E7%82%B9%E7%9A%84%E7%B4%A2%E5%BC%95%EF%BC%88%E7%A8%80%E7%96%8F%E7%B4%A2%E5%BC%95%EF%BC%89%EF%BC%8C%E5%8F%B6%E5%AD%90%E7%BB%93%E7%82%B9%E7%9B%B8%E5%BD%93%E4%BA%8E%E6%98%AF%E5%AD%98%E5%82%A8%EF%BC%88%E5%85%B3%E9%94%AE%E5%AD%97%EF%BC%89%E6%95%B0%E6%8D%AE%E7%9A%84%E6%95%B0%E6%8D%AE%E5%B1%82%EF%BC%9B%0A4.%20%E6%9B%B4%E9%80%82%E5%90%88%E6%96%87%E4%BB%B6%E7%B4%A2%E5%BC%95%E7%B3%BB%E7%BB%9F%EF%BC%9B%0A%0A%23%23%23%23%203.2.4%20B%2B%E6%A0%91%20vs%20B%E6%A0%91%0A%E4%B8%BA%E4%BB%80%E4%B9%88%E8%AF%B4B%2B-tree%E6%AF%94B%20%E6%A0%91%E6%9B%B4%E9%80%82%E5%90%88%E5%AE%9E%E9%99%85%E5%BA%94%E7%94%A8%E4%B8%AD%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E7%9A%84%E6%96%87%E4%BB%B6%E7%B4%A2%E5%BC%95%E5%92%8C%E6%95%B0%E6%8D%AE%E5%BA%93%E7%B4%A2%E5%BC%95%EF%BC%9F%0A%0A*%20B%2B-tree%E7%9A%84%E7%A3%81%E7%9B%98%E8%AF%BB%E5%86%99%E4%BB%A3%E4%BB%B7%E6%9B%B4%E4%BD%8E%0AB%2B-tree%E7%9A%84%E5%86%85%E9%83%A8%E7%BB%93%E7%82%B9%E5%B9%B6%E6%B2%A1%E6%9C%89%E6%8C%87%E5%90%91%E5%85%B3%E9%94%AE%E5%AD%97%E5%85%B7%E4%BD%93%E4%BF%A1%E6%81%AF%E7%9A%84%E6%8C%87%E9%92%88%E3%80%82%E5%9B%A0%E6%AD%A4%E5%85%B6%E5%86%85%E9%83%A8%E7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%E3%80%82%E4%B8%80%E6%A3%B59%E9%98%B6B-tree(%E4%B8%80%E4%B8%AA%E7%BB%93%E7%82%B9%E6%9C%80%E5%A4%9A8%E4%B8%AA%E5%85%B3%E9%94%AE%E5%AD%97)%E7%9A%84%E5%86%85%E9%83%A8%E7%BB%93%E7%82%B9%E9%9C%80%E8%A6%812%E4%B8%AA%E7%9B%98%E5%BF%AB%E3%80%82%E8%80%8CB%2B%20%E6%A0%91%E5%86%85%E9%83%A8%E7%BB%93%E7%82%B9%E5%8F%AA%E9%9C%80%E8%A6%811%E4%B8%AA%E7%9B%98%E5%BF%AB%E3%80%82%E5%BD%93%E9%9C%80%E8%A6%81%E6%8A%8A%E5%86%85%E9%83%A8%E7%BB%93%E7%82%B9%E8%AF%BB%E5%85%A5%E5%86%85%E5%AD%98%E4%B8%AD%E7%9A%84%E6%97%B6%E5%80%99%EF%BC%8CB%20%E6%A0%91%E5%B0%B1%E6%AF%94B%2B%20%E6%A0%91%E5%A4%9A%E4%B8%80%E6%AC%A1%E7%9B%98%E5%9D%97%E6%9F%A5%E6%89%BE%E6%97%B6%E9%97%B4(%E5%9C%A8%E7%A3%81%E7%9B%98%E4%B8%AD%E5%B0%B1%E6%98%AF%E7%9B%98%E7%89%87%E6%97%8B%E8%BD%AC%E7%9A%84%E6%97%B6%E9%97%B4)%E3%80%82%0A*%20B%2B-tree%E7%9A%84%E6%9F%A5%E8%AF%A2%E6%95%88%E7%8E%87%E6%9B%B4%E5%8A%A0%E7%A8%B3%E5%AE%9A%0A%E7%94%B1%E4%BA%8E%E9%9D%9E%E7%BB%88%E7%BB%93%E7%82%B9%E5%B9%B6%E4%B8%8D%E6%98%AF%E6%9C%80%E7%BB%88%E6%8C%87%E5%90%91%E6%96%87%E4%BB%B6%E5%86%85%E5%AE%B9%E7%9A%84%E7%BB%93%E7%82%B9%EF%BC%8C%E8%80%8C%E5%8F%AA%E6%98%AF%E5%8F%B6%E5%AD%90%E7%BB%93%E7%82%B9%E4%B8%AD%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%97%E7%9A%84%E6%9C%80%E4%BD%8E%E4%BD%BF%E7%94%A8%E7%8E%87%E4%B8%BA2%2F3%EF%BC%88%E4%BB%A3%E6%9B%BFB%2B%E6%A0%91%E7%9A%841%2F2%EF%BC%89%EF%BC%9B%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/1b373e0a-8510-40e0-b50f-b087843843a5/2502aaf0-b699-43ca-b2fb-1d1c3ac848a2.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F567%3A1)%0A%0A%23%23%23%23%203.3.2%20B*%E6%A0%91%20vs%20B%2B%E6%A0%91%0A%0A*%20B%2B%E6%A0%91%E7%9A%84%E5%88%86%E8%A3%82%EF%BC%9A%0A%E5%BD%93%E4%B8%80%E4%B8%AA%E7%BB%93%E7%82%B9%E6%BB%A1%E6%97%B6%EF%BC%8C%E5%88%86%E9%85%8D%E4%B8%80%E4%B8%AA%E6%96%B0%E7%9A%84%E7%BB%93%E7%82%B9%EF%BC%8C%E5%B9%B6%E5%B0%86%E5%8E%9F%E7%BB%93%E7%82%B9%E4%B8%AD1%2F2%E7%9A%84%E6%95%B0%E6%8D%AE%E5%A4%8D%E5%88%B6%E5%88%B0%E6%96%B0%E7%BB%93%E7%82%B9%EF%BC%8C%E6%9C%80%E5%90%8E%E5%9C%A8%E7%88%B6%E7%BB%93%E7%82%B9%E4%B8%AD%E5%A2%9E%E5%8A%A0%E6%96%B0%E7%BB%93%E7%82%B9%E7%9A%84%E6%8C%87%E9%92%88%EF%BC%9BB%2B%E6%A0%91%E7%9A%84%E5%88%86%E8%A3%82%E5%8F%AA%E5%BD%B1%E5%93%8D%E5%8E%9F%E7%BB%93%E7%82%B9%E5%92%8C%E7%88%B6%E7%BB%93%E7%82%B9%EF%BC%8C%E8%80%8C%E4%B8%8D%E4%BC%9A%E5%BD%B1%E5%93%8D%E5%85%84%E5%BC%9F%E7%BB%93%E7%82%B9%EF%BC%8C%E6%89%80%E4%BB%A5%E5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C%8C%E9%9D%9E%E5%8F%B6%E5%AD%90%E7%BB%93%E7%82%B9%E5%8F%AF%E4%BB%A5%E5%91%BD%E4%B8%AD%EF%BC%9B%0A-%20-%20-%0A*%20B%2B%E6%A0%91%EF%BC%9A%E5%9C%A8B-%E6%A0%91%E5%9F%BA%E7%A1%80%E4%B8%8A%EF%BC%8C%E4%B8%BA%E5%8F%B6%E5%AD%90%E7%BB%93%E7%82%B9%E5%A2%9E%E5%8A%A0%E9%93%BE%E8%A1%A8%E6%8C%87%E9%92%88%EF%BC%8C%E6%89%80%E6%9C%89%E5%85%B3%E9%94%AE%E5%AD%97%E9%83%BD%E5%9C%A8%E5%8F%B6%E5%AD%90%E7%BB%93%E7%82%B9%E4%B8%AD%E5%87%BA%E7%8E%B0%EF%BC%8C%E9%9D%9E%E5%8F%B6%E5%AD%90%E7%BB%93%E7%82%B9%E4%BD%9C%E4%B8%BA%E5%8F%B6%E5%AD%90%E7%BB%93%E7%82%B9%E7%9A%84%E7%B4%A2%E5%BC%95%EF%BC%9B%0AB%2B%E6%A0%91%E6%80%BB%E6%98%AF%E5%88%B0%E5%8F%B6%E5%AD%90%E7%BB%93%E7%82%B9%E6%89%8D%E5%91%BD%E4%B8%AD%EF%BC%9B%0A-%20-%20-%0A*%20B*%E6%A0%91%EF%BC%9A%E5%9C%A8B%2B%E6%A0%91%E5%9F%BA%E7%A1%80%E4%B8%8A%EF%BC%8C%E4%B8%BA%E9%9D%9E%E5%8F%B6%E5%AD%90%E7%BB%93%E7%82%B9%E4%B9%9F%E5%A2%9E%E5%8A%A0%E9%93%BE%E8%A1%A8%E6%8C%87%E9%92%88%EF%BC%8C%E5%B0%86%E7%BB%93%E7%82%B9%E7%9A%84%E6%9C%80%E4%BD%8E%E5%88%A9%E7%94%A8%E7%8E%87%E4%BB%8E1%2F2%E6%8F%90%E9%AB%98%E5%88%B02%2F3%EF%BC%9B%0A&lt;/center&gt;&lt;/div&gt;
</content>
  </entry>
  <entry xml:base="http://linzhiteng.postach.io/feed.xml">
    <title type="text">JDK 并发容器总结</title>
    <id>https://linzhiteng.postach.io/post/jdk-bing-fa-rong-qi-zong-jie</id>
    <updated>2019-06-09T13:07:26.799000Z</updated>
    <published>2019-03-13T13:54:23Z</published>
    <link href="https://linzhiteng.postach.io/post/jdk-bing-fa-rong-qi-zong-jie" />
    <author>
      <name>linzhi teng</name>
    </author>
    <category term="xian-cheng" />
    <content type="html">&lt;div&gt;&lt;div style=&quot;font-size: 14px; margin: 0; padding: 0; width: 100%;&quot;&gt;&lt;div style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;JDK 并发容器总结
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.  JDK 提供的并发容器
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2. ConcurrentHashMap
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3. CopyOnWriteArrayList
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1 CopyOnWriteArrayList 简介
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.2 CopyOnWriteArrayList 是如何做到的？
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.3 CopyOnWriteArravList 读取和写入源码简单分析
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.3.1 CopyOnWriteArravList 读取操作的实现
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.3.2 CopyOnWriteArravList 写入操作的实现
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4. ConcurrentLinkedQueue
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;5. BlockingQueue
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;5.1 BlockingQueue 简单介绍
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;5.2 ArrayBlockingQueue
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;5.3 LinkedBlockingQueue
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;5.4 PriorityBlockingQueue
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;6. ConcurrentSkipListMap
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;JDK 并发容器总结&lt;/h2&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;1.  JDK 提供的并发容器&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;JDK提供的这些容器大部分在 java.util.concurrent 包中。&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;ConcurrentHashMap&lt;/strong&gt;： 线程安全的HashMap&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;CopyOnWriteArrayList&lt;/strong&gt;: 线程安全的List，在读多写少的场合性能非常好，远远好于Vector.&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;ConcurrentLinkedQueue&lt;/strong&gt;:高效的并发队列，使用链表实现。可以看做一个线程安全的 LinkedList，这是一个非阻塞队列。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;BlockingQueue&lt;/strong&gt;: 这是一个接口，JDK内部通过链表、数组等方式实现了这个接口。表示阻塞队列，非常适合用于作为数据共享的通道。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;ConcurrentSkipListMap&lt;/strong&gt;: 跳表的实现。这是一个Map，使用跳表的数据结构进行快速查找。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;2. ConcurrentHashMap&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;在ConcurrentHashMap中，无论是读操作还是写操作都能保证很高的性能：在进行读操作时(几乎)不需要加锁，而在写操作时通过锁分段技术只对所操作的段加锁而不影响客户端对其它段的访问。&lt;br/&gt;
在Map集合中已经详细叙述&lt;/p&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;3. CopyOnWriteArrayList&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.1 CopyOnWriteArrayList 简介&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;在很多应用场景中，读操作可能会远远大于写操作。由于读操作根本不会修改原有的数据，因此对于每次读取都进行加锁其实是一种资源浪费。我们应该允许多个线程同时访问List的内部数据，毕竟读取操作是安全的。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;这和我们之前在多线程章节讲过 ReentrantReadWriteLock 读写锁的思想非常类似，也就是读读共享、写写互斥、读写互斥、写读互斥。JDK中提供了 CopyOnWriteArravList 类比相比于在读写锁的思想又更进一步。为了将读取的性能发挥到极致，CopyOnWriteArravList &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;读取是完全不用加锁的&lt;/strong&gt;，并且更厉害的是：&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;写入也不会阻塞读取操作&lt;/strong&gt;。&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;只有写入和写入之间需要进行同步等待&lt;/strong&gt;。这样一来，读操作的性能就会大幅度提升。那它是怎么做的呢？&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.2 CopyOnWriteArrayList 是如何做到的？&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;CopyOnWriteArravList 类的所有可变操作（add，set等等）都是通过&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;创建底层数组的新副本&lt;/strong&gt;来实现的。当 List 需要被修改的时候，&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;并不修改原有内容，而是对原有数据进行一次复制，将修改的内容写入副本&lt;/strong&gt;。写完之后，再将&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;修改完的副本替换原来的数据&lt;/strong&gt;，这样就可以保证写操作不会影响读操作了。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;从 CopyOnWriteArrayList 的名字就能看出CopyOnWriteArravList 是满足CopyOnWrite 的ArrayList，所谓CopyOnWrite 也就是说：在计算机，如果你想要对一块内存进行修改时，我们不在原有内存块中进行写操作，而是将内存拷贝一份，在新的内存中进行写操作，写完之后呢，就将指向原来内存指针指向新的内存，原来的内存就可以被回收掉了。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.3 CopyOnWriteArravList 读取和写入源码简单分析&lt;/h4&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;3.3.1 CopyOnWriteArravList 读取操作的实现&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;读取操作没有任何同步控制和锁操作，理由就是内部数组 array 不会发生修改，只会被另外一个 array 替换，因此可以保证数据安全。&lt;/p&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;    &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;/** The array, accessed only via getArray/setArray. */&lt;/span&gt;
    &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;transient&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;volatile&lt;/span&gt; Object[] array;
    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; E &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; index)&lt;/span&gt; &lt;/span&gt;{
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt; get(getArray(), index);
    }
    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;@SuppressWarnings&lt;/span&gt;(&lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;unchecked&quot;&lt;/span&gt;)
    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;private&lt;/span&gt; E &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(Object[] a, &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; index)&lt;/span&gt; &lt;/span&gt;{
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt; (E) a[index];
    }
    &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;final&lt;/span&gt; Object[] getArray() {
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt; array;
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;3.3.2 CopyOnWriteArravList 写入操作的实现&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;CopyOnWriteArravList 写入操作 add() 方法在添加集合的时候加了锁，保证了同步，避免了多线程写的时候会 copy 出多个副本出来。&lt;/p&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;    &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;/**
     * Appends the specified element to the end of this list.
     *
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@param&lt;/span&gt; e element to be appended to this list
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@return&lt;/span&gt; {&lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@code&lt;/span&gt; true} (as specified by {&lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@link&lt;/span&gt; Collection#add})
     */&lt;/span&gt;
    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;boolean&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(E e)&lt;/span&gt; &lt;/span&gt;{
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;final&lt;/span&gt; ReentrantLock lock = &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;this&lt;/span&gt;.lock;
        lock.lock();&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//加锁&lt;/span&gt;
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;try&lt;/span&gt; {
            Object[] elements = getArray();
            &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; len = elements.length;
            Object[] newElements = Arrays.copyOf(elements, len + &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1&lt;/span&gt;);&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//拷贝新数组&lt;/span&gt;
            newElements[len] = e;
            setArray(newElements);
            &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;true&lt;/span&gt;;
        } &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;finally&lt;/span&gt; {
            lock.unlock();&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//释放锁&lt;/span&gt;
        }
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;4. ConcurrentLinkedQueue&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;Java提供的线程安全的 Queue 可以分为阻塞队列和非阻塞队列，其中阻塞队列的典型例子是 BlockingQueue，非阻塞队列的典型例子是ConcurrentLinkedQueue，在实际应用中要根据实际需要选用阻塞队列或者非阻塞队列。&lt;br/&gt;
阻塞队列可以通过加锁来实现，非阻塞队列可以通过 CAS 操作实现。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;从名字可以看出，ConcurrentLinkedQueue这个队列使用链表作为其数据结构．ConcurrentLinkedQueue 应该算是&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;在高并发环境中性能最好的队列&lt;/strong&gt;了。它之所有能有很好的性能，是因为其内部复杂的实现。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;ConcurrentLinkedQueue 内部代码我们就不分析了，大家知道ConcurrentLinkedQueue 主要使用 CAS 非阻塞算法来实现线程安全就好了。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;ConcurrentLinkedQueue 适合在对性能要求相对较高，同时对队列的读写存在多个线程同时进行的场景，即如果对队列加锁的成本较高则适合使用无锁的ConcurrentLinkedQueue来替代。&lt;/p&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;5. BlockingQueue&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;5.1 BlockingQueue 简单介绍&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;阻塞队列（BlockingQueue）被广泛使用在&quot;生产者-消费者&quot;问题中，其原因是BlockingQueue提供了可阻塞的插入和移除的方法。当队列容器已满，生产者线程会被阻塞，直到队列未满；当队列容器为空时，消费者线程会被阻塞，直至队列非空时为止。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;BlockingQueue 是一个接口，继承自 Queue，所以其实现类也可以作为 Queue 的实现来使用，而 Queue 又继承自 Collection 接口。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;主要介绍一下:&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;ArrayBlockingQueue&lt;/strong&gt;、&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;LinkedBlockingQueue&lt;/strong&gt;、&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;PriorityBlockingQueue&lt;/strong&gt;，这三个 BlockingQueue 的实现类。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;5.2 ArrayBlockingQueue&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;ArrayBlockingQueue 是 BlockingQueue 接口的有界队列实现类，底层采用数组来实现。ArrayBlockingQueue一旦创建，容量不能改变。其并发控制采用可重入锁来控制，不管是插入操作还是读取操作，都需要获取到锁才能进行操作。当队列容量满时，尝试将元素放入队列将导致操作阻塞;尝试从一个空队列中取一个元素也会同样阻塞。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;ArrayBlockingQueue 默认情况下不能保证线程访问队列的公平性，所谓公平性是指严格按照线程等待的绝对时间顺序，即最先等待的线程能够最先访问到 ArrayBlockingQueue。而非公平性则是指访问 ArrayBlockingQueue 的顺序不是遵守严格的时间顺序，有可能存在，当 ArrayBlockingQueue 可以被访问时，长时间阻塞的线程依然无法访问到 ArrayBlockingQueue。如果保证公平性，通常会降低吞吐量。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;可以通过构造函数来实现公平性。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;5.3 LinkedBlockingQueue&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;LinkedBlockingQueue 底层基于单向链表实现的阻塞队列，可以当做无界队列也可以当做有界队列来使用，同样满足FIFO的特性，与ArrayBlockingQueue 相比起来具有更高的吞吐量，为了防止 LinkedBlockingQueue 容量迅速增，损耗大量内存。通常在创建LinkedBlockingQueue 对象时，会指定其大小，如果未指定，容量等于Integer.MAX_VALUE。&lt;/p&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;    &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;/**
     *某种意义上的无界队列
     * Creates a {&lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@code&lt;/span&gt; LinkedBlockingQueue} with a capacity of
     * {&lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@link&lt;/span&gt; Integer#MAX_VALUE}.
     */&lt;/span&gt;
    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;LinkedBlockingQueue&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;this&lt;/span&gt;(Integer.MAX_VALUE);
    }

    &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;/**
     *有界队列
     * Creates a {&lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@code&lt;/span&gt; LinkedBlockingQueue} with the given (fixed) capacity.
     *
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@param&lt;/span&gt; capacity the capacity of this queue
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@throws&lt;/span&gt; IllegalArgumentException if {&lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@code&lt;/span&gt; capacity} is not greater
     *         than zero
     */&lt;/span&gt;
    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;LinkedBlockingQueue&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; capacity)&lt;/span&gt; &lt;/span&gt;{
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;if&lt;/span&gt; (capacity &lt;= &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0&lt;/span&gt;) &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;throw&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; IllegalArgumentException();
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;this&lt;/span&gt;.capacity = capacity;
        last = head = &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; Node&lt;E&gt;(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;null&lt;/span&gt;);
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;5.4 PriorityBlockingQueue&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;PriorityBlockingQueue 是一个支持优先级的无界阻塞队列。默认情况下元素采用自然顺序进行排序，也可以通过自定义类实现 compareTo() 方法来指定元素排序规则，或者初始化时通过构造器参数 Comparator 来指定排序规则。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;PriorityBlockingQueue 并发控制采用的是 ReentrantLock，队列为无界队列（ArrayBlockingQueue 是有界队列，LinkedBlockingQueue 也可以通过在构造函数中传入 capacity 指定队列最大的容量，但是 PriorityBlockingQueue 只能指定初始的队列大小，后面插入元素的时候，如果空间不够的话会自动扩容）。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;简单地说，它就是 PriorityQueue 的线程安全版本。不可以插入 null 值，同时，插入队列的对象必须是可比较大小的（comparable），否则报 ClassCastException 异常。它的插入操作 put 方法不会 block，因为它是无界队列（take 方法在队列为空的时候会阻塞）。&lt;/p&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;6. ConcurrentSkipListMap&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;为了引出ConcurrentSkipListMap，先带着大家简单理解一下跳表。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;对于一个单链表，即使链表是有序的，如果我们想要在其中查找某个数据，也只能从头到尾遍历链表，这样效率自然就会很低，跳表就不一样了。跳表是一种可以用来快速查找的数据结构，有点类似于平衡树。它们都可以对元素进行快速的查找。但一个重要的区别是：对平衡树的插入和删除往往很可能导致平衡树进行一次全局的调整。而对跳表的插入和删除只需要对整个数据结构的局部进行操作即可。这样带来的好处是：在高并发的情况下，你会需要一个全局锁来保证整个平衡树的线程安全。而对于跳表，你只需要部分锁即可。这样，在高并发环境下，你就可以拥有更好的性能。而就查询的性能而言，跳表的时间复杂度也是 O(logn) 所以在并发数据结构中，JDK 使用跳表来实现一个 Map。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;跳表的本质是同时维护了多个链表，并且链表是分层的，&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/cce14de8-4f98-4388-b62b-2f04258c20c6/0f3da28f-d539-4f5e-bd79-01f0dc0e0146.jpg&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;最低层的链表维护了跳表内所有的元素，每上面一层链表都是下面一层的子集。跳表内的所有链表的元素都是排序的。查找时，可以从顶级链表开始找。一旦发现被查找的元素大于当前链表中的取值，就会转入下一层链表继续找。这也就是说在查找过程中，搜索是跳跃式的。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;在跳表中查找元素18。查找18 的时候原来需要遍历 18 次，现在只需要 7 次即可。针对链表长度比较大的时候，构建索引查找效率的提升就会非常明显。&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/cce14de8-4f98-4388-b62b-2f04258c20c6/5682a98f-cad2-47aa-a0d0-1bd178d5fbc7.jpg&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;跳表是一种利用空间换时间的算法&lt;/strong&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;使用跳表实现Map 和使用哈希算法实现Map的另外一个不同之处是：哈希并不会保存元素的顺序，而跳表内所有的元素都是排序的。因此在对跳表进行遍历时，你会得到一个有序的结果。所以，如果你的应用需要有序性，那么跳表就是你不二的选择。JDK 中实现这一数据结构的类是ConcurrentSkipListMap。&lt;/p&gt;
&lt;/div&gt;&lt;center style='display:none !important;visibility:collapse !important;height:0 !important;white-space:nowrap;width:100%;overflow:hidden'&gt;%5Btoc%5D%0A%23%23%20JDK%20%E5%B9%B6%E5%8F%91%E5%AE%B9%E5%99%A8%E6%80%BB%E7%BB%93%0A%23%23%23%201.%20%C2%A0JDK%20%E6%8F%90%E4%BE%9B%E7%9A%84%E5%B9%B6%E5%8F%91%E5%AE%B9%E5%99%A8%0AJDK%E6%8F%90%E4%BE%9B%E7%9A%84%E8%BF%99%E4%BA%9B%E5%AE%B9%E5%99%A8%E5%A4%A7%E9%83%A8%E5%88%86%E5%9C%A8%20java.util.concurrent%20%E5%8C%85%E4%B8%AD%E3%80%82%0A%0A*%20**ConcurrentHashMap**%EF%BC%9A%20%E7%BA%BF%E7%A8%8B%E5%AE%89%E5%85%A8%E7%9A%84HashMap%0A*%20**CopyOnWriteArrayList**%3A%20%E7%BA%BF%E7%A8%8B%E5%AE%89%E5%85%A8%E7%9A%84List%EF%BC%8C%E5%9C%A8%E8%AF%BB%E5%A4%9A%E5%86%99%E5%B0%91%E7%9A%84%E5%9C%BA%E5%90%88%E6%80%A7%E8%83%BD%E9%9D%9E%E5%B8%B8%E5%A5%BD%EF%BC%8C%E8%BF%9C%E8%BF%9C%E5%A5%BD%E4%BA%8EVector.%0A*%20**ConcurrentLinkedQueue**%3A%E9%AB%98%E6%95%88%E7%9A%84%E5%B9%B6%E5%8F%91%E9%98%9F%E5%88%97%EF%BC%8C%E4%BD%BF%E7%94%A8%E9%93%BE%E8%A1%A8%E5%AE%9E%E7%8E%B0%E3%80%82%E5%8F%AF%E4%BB%A5%E7%9C%8B%E5%81%9A%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%E5%AE%89%E5%85%A8%E7%9A%84%20LinkedList%EF%BC%8C%E8%BF%99%E6%98%AF%E4%B8%80%E4%B8%AA%E9%9D%9E%E9%98%BB%E5%A1%9E%E9%98%9F%E5%88%97%E3%80%82%0A*%20**BlockingQueue**%3A%20%E8%BF%99%E6%98%AF%E4%B8%80%E4%B8%AA%E6%8E%A5%E5%8F%A3%EF%BC%8CJDK%E5%86%85%E9%83%A8%E9%80%9A%E8%BF%87%E9%93%BE%E8%A1%A8%E3%80%81%E6%95%B0%E7%BB%84%E7%AD%89%E6%96%B9%E5%BC%8F%E5%AE%9E%E7%8E%B0%E4%BA%86%E8%BF%99%E4%B8%AA%E6%8E%A5%E5%8F%A3%E3%80%82%E8%A1%A8%E7%A4%BA%E9%98%BB%E5%A1%9E%E9%98%9F%E5%88%97%EF%BC%8C%E9%9D%9E%E5%B8%B8%E9%80%82%E5%90%88%E7%94%A8%E4%BA%8E%E4%BD%9C%E4%B8%BA%E6%95%B0%E6%8D%AE%E5%85%B1%E4%BA%AB%E7%9A%84%E9%80%9A%E9%81%93%E3%80%82%0A*%20**ConcurrentSkipListMap**%3A%20%E8%B7%B3%E8%A1%A8%E7%9A%84%E5%AE%9E%E7%8E%B0%E3%80%82%E8%BF%99%E6%98%AF%E4%B8%80%E4%B8%AAMap%EF%BC%8C%E4%BD%BF%E7%94%A8%E8%B7%B3%E8%A1%A8%E7%9A%84%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E8%BF%9B%E8%A1%8C%E5%BF%AB%E9%80%9F%E6%9F%A5%E6%89%BE%E3%80%82%0A%0A%23%23%23%202.%20ConcurrentHashMap%0A%0A%E5%9C%A8ConcurrentHashMap%E4%B8%AD%EF%BC%8C%E6%97%A0%E8%AE%BA%E6%98%AF%E8%AF%BB%E6%93%8D%E4%BD%9C%E8%BF%98%E6%98%AF%E5%86%99%E6%93%8D%E4%BD%9C%E9%83%BD%E8%83%BD%E4%BF%9D%E8%AF%81%E5%BE%88%E9%AB%98%E7%9A%84%E6%80%A7%E8%83%BD%EF%BC%9A%E5%9C%A8%E8%BF%9B%E8%A1%8C%E8%AF%BB%E6%93%8D%E4%BD%9C%E6%97%B6(%E5%87%A0%E4%B9%8E)%E4%B8%8D%E9%9C%80%E8%A6%81%E5%8A%A0%E9%94%81%EF%BC%8C%E8%80%8C%E5%9C%A8%E5%86%99%E6%93%8D%E4%BD%9C%E6%97%B6%E9%80%9A%E8%BF%87%E9%94%81%E5%88%86%E6%AE%B5%E6%8A%80%E6%9C%AF%E5%8F%AA%E5%AF%B9%E6%89%80%E6%93%8D%E4%BD%9C%E7%9A%84%E6%AE%B5%E5%8A%A0%E9%94%81%E8%80%8C%E4%B8%8D%E5%BD%B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E4%BD%9C%E6%98%AF%E5%AE%89%E5%85%A8%E7%9A%84%E3%80%82%0A%0A%E8%BF%99%E5%92%8C%E6%88%91%E4%BB%AC%E4%B9%8B%E5%89%8D%E5%9C%A8%E5%A4%9A%E7%BA%BF%E7%A8%8B%E7%AB%A0%E8%8A%82%E8%AE%B2%E8%BF%87%20ReentrantReadWriteLock%20%E8%AF%BB%E5%86%99%E9%94%81%E7%9A%84%E6%80%9D%E6%83%B3%E9%9D%9E%E5%B8%B8%E7%B1%BB%E4%BC%BC%EF%BC%8C%E4%B9%9F%E5%B0%B1%E6%98%AF%E8%AF%BB%E8%AF%BB%E5%85%B1%E4%BA%AB%E3%80%81%E5%86%99%E5%86%99%E4%BA%92%E6%96%A5%E3%80%81%E8%AF%BB%E5%86%99%E4%BA%92%E6%96%A5%E3%80%81%E5%86%99%E8%AF%BB%E4%BA%92%E6%96%A5%E3%80%82JDK%E4%B8%AD%E6%8F%90%E4%BE%9B%E4%BA%86%20CopyOnWriteArravList%20%E7%B1%BB%E6%AF%94%E7%9B%B8%E6%AF%94%E4%BA%8E%E5%9C%A8%E8%AF%BB%E5%86%99%E9%94%81%E7%9A%84%E6%80%9D%E6%83%B3%E5%8F%88%E6%9B%B4%E8%BF%9B%E4%B8%80%E6%AD%A5%E3%80%82%E4%B8%BA%E4%BA%86%E5%B0%86%E8%AF%BB%E5%8F%96%E7%9A%84%E6%80%A7%E8%83%BD%E5%8F%91%E6%8C%A5%E5%88%B0%E6%9E%81%E8%87%B4%EF%BC%8CCopyOnWriteArravList%20**%E8%AF%BB%E5%8F%96%E6%98%AF%E5%AE%8C%E5%85%A8%E4%B8%8D%E7%94%A8%E5%8A%A0%E9%94%81%E7%9A%84**%EF%BC%8C%E5%B9%B6%E4%B8%94%E6%9B%B4%E5%8E%89%E5%AE%B3%E7%9A%84%E6%98%AF%EF%BC%9A**%E5%86%99%E5%85%A5%E4%B9%9F%E4%B8%8D%E4%BC%9A%E9%98%BB%E5%A1%9E%E8%AF%BB%E5%8F%96%E6%93%8D%E4%BD%9C**%E3%80%82**%E5%8F%AA%E6%9C%89%E5%86%99%E5%85%A5%E5%92%8C%E5%86%99%E5%85%A5%E4%B9%8B%E9%97%B4%E9%9C%80%E8%A6%81%E8%BF%9B%E8%A1%8C%E5%90%8C%E6%AD%A5%E7%AD%89%E5%BE%85**%E3%80%82%E8%BF%99%E6%A0%B7%E4%B8%80%E6%9D%A5%EF%BC%8C%E8%AF%BB%E6%93%8D%E4%BD%9C%E7%9A%84%E6%80%A7%E8%83%BD%E5%B0%B1%E4%BC%9A%E5%A4%A7%E5%B9%85%E5%BA%A6%E6%8F%90%E5%8D%87%E3%80%82%E9%82%A3%E5%AE%83%E6%98%AF%E6%80%8E%E4%B9%88%E5%81%9A%E7%9A%84%E5%91%A2%EF%BC%9F%0A%0A%23%23%23%23%203.2%20CopyOnWriteArrayList%20%E6%98%AF%E5%A6%82%E4%BD%95%E5%81%9A%E5%88%B0%E7%9A%84%EF%BC%9F%0ACopyOnWriteArravList%20%E7%B1%BB%E7%9A%84%E6%89%80%E6%9C%89%E5%8F%AF%E5%8F%98%E6%93%8D%E4%BD%9C%EF%BC%88add%EF%BC%8Cset%E7%AD%89%E7%AD%89%EF%BC%89%E9%83%BD%E6%98%AF%E9%80%9A%E8%BF%87**%E5%88%9B%E5%BB%BA%E5%BA%95%E5%B1%82%E6%95%B0%E7%BB%84%E7%9A%84%E6%96%B0%E5%89%AF%E6%9C%AC**%E6%9D%A5%E5%AE%9E%E7%8E%B0%E7%9A%84%E3%80%82%E5%BD%93%20List%20%E9%9C%80%E8%A6%81%E8%A2%AB%E4%BF%AE%E6%94%B9%E7%9A%84%E6%97%B6%E5%80%99%EF%BC%8C**%E5%B9%B6%E4%B8%8D%E4%BF%AE%E6%94%B9%E5%8E%9F%E6%9C%89%E5%86%85%E5%AE%B9%EF%BC%8C%E8%80%8C%E6%98%AF%E5%AF%B9%E5%8E%9F%E6%9C%89%E6%95%B0%E6%8D%AE%E8%BF%9B%E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%80%8C%E6%98%AF%E5%B0%86%E5%86%85%E5%AD%98%E6%8B%B7%E8%B4%9D%E4%B8%80%E4%BB%BD%EF%BC%8C%E5%9C%A8%E6%96%B0%E7%9A%84%E5%86%85%E5%AD%98%E4%B8%AD%E8%BF%9B%E8%A1%8C%E5%86%99%E6%93%8D%E4%BD%9C%EF%BC%8C%E5%86%99%E5%AE%8C%E4%B9%8B%E5%90%8E%E5%91%A2%EF%BC%8C%E5%B0%B1%E5%B0%86%E6%8C%87%E5%90%91%E5%8E%9F%E6%9D%A5%E5%86%85%E5%AD%98%E6%8C%87%E9%92%88%E6%8C%87%E5%90%91%E6%96%B0%E7%9A%84%E5%86%85%E5%AD%98%EF%BC%8C%E5%8E%9F%E6%9D%A5%E7%9A%84%E5%86%85%E5%AD%98%E5%B0%B1%E5%8F%AF%E4%BB%A5%E8%A2%AB%E5%9B%9E%E6%94%B6%E6%8E%89%E4%BA%86%E3%80%82%0A%0A%23%23%23%23%203.3%20CopyOnWriteArravList%20%E8%AF%BB%E5%8F%96%E5%92%8C%E5%86%99%E5%85%A5%E6%BA%90%E7%A0%81%E7%AE%80%E5%8D%95%E5%88%86%E6%9E%90%0A%0A%23%23%23%23%23%203.3.1%20CopyOnWriteArravList%20%E8%AF%BB%E5%8F%96%E6%93%8D%E4%BD%9C%E7%9A%84%E5%AE%9E%E7%8E%B0%0A%0A%E8%AF%BB%E5%8F%96%E6%93%8D%E4%BD%9C%E6%B2%A1%E6%9C%89%E4%BB%BB%E4%BD%95%E5%90%8C%E6%AD%A5%E6%8E%A7%E5%88%B6%E5%92%8C%E9%94%81%E6%93%8D%E4%BD%9C%EF%BC%8C%E7%90%86%E7%94%B1%E5%B0%B1%E6%98%AF%E5%86%85%E9%83%A8%E6%95%B0%E7%BB%84%20array%20%E4%B8%8D%E4%BC%9A%E5%8F%91%E7%94%9F%E4%BF%AE%E6%94%B9%EF%BC%8C%E5%8F%AA%E4%BC%9A%E8%A2%AB%E5%8F%A6%E5%A4%96%E4%B8%80%E4%B8%AA%20array%20%E6%9B%BF%E6%8D%A2%EF%BC%8C%E5%9B%A0%E6%AD%A4%E5%8F%AF%E4%BB%A5%E4%BF%9D%E8%AF%81%E6%95%B0%E6%8D%AE%E5%AE%89%E5%85%A8%E3%80%82%0A%60%60%60java%0A%20%20%20%20%2F**%20The%20array%2C%20accessed%20only%20via%20getArray%2FsetArray.%20*%2F%0A%20%20%20%20private%20transient%20volatile%20Object%5B%5D%20array%3B%0A%20%20%20%20public%20E%20get(int%20index)%20%7B%0A%20%20%20%20%20%20%20%20return%20get(getArray()%2C%20index)%3B%0A%20%20%20%20%7D%0A%20%20%20%20%40SuppressWarnings(%22unchecked%22)%0A%20%20%20%20private%20E%20get(Object%5B%5D%20a%2C%20int%20index)%20%7B%0A%20%20%20%20%20%20%20%20return%20(E)%20a%5Bindex%5D%3B%0A%20%20%20%20%7D%0A%20%20%20%20final%20Object%5B%5D%20getArray()%20%7B%0A%20%20%20%20%20%20%20%20return%20array%3B%0A%20%20%20%20%7D%0A%60%60%60%0A%0A%23%23%23%23%23%203.3.2%20CopyOnWriteArravList%20%E5%86%99%E5%85%A5%E6%93%8D%E4%BD%9C%E7%9A%84%E5%AE%9E%E7%8E%B0%0A%0ACopyOnWriteArravList%20%E5%86%99%E5%85%A5%E6%93%8D%E4%BD%9C%20add()%20%E6%96%B9%E6%B3%95%E5%9C%A8%E6%B7%BB%E5%8A%A0%E9%9B%86%E5%90%88%E7%9A%84%E6%97%B6%E5%80%99%E5%8A%A0%E4%BA%86%E9%94%81%EF%BC%8C%E4%BF%9D%E8%AF%81%E4%BA%86%E5%90%8C%E6%AD%A5%EF%BC%8C%E9%81%BF%E5%85%8D%E4%BA%86%E5%A4%9A%E7%BA%BF%E7%A8%8B%E5%86%99%E7%9A%84%E6%97%B6%E5%80%99%E4%BC%9A%20copy%20%E5%87%BA%E5%A4%9A%E4%B8%AA%E5%89%AF%E6%9C%AC%E5%87%BA%E6%9D%A5%E3%80%82%0A%60%60%60java%0A%20%20%20%20%2F**%0A%20%20%20%20%20*%20Appends%20the%20specified%20element%20to%20the%20end%20of%20this%20list.%0A%20%20%20%20%20*%0A%20%20%20%20%20*%20%40param%20e%20element%20to%20be%20appended%20to%20this%20list%0A%20%20%20%20%20*%20%40return%20%7B%40code%20true%7D%20(as%20specified%20by%20%7B%40link%20Collection%23add%7D)%0A%20%20%20%20%20*%2F%0A%20%20%20%20public%20boolean%20add(E%20e)%20%7B%0A%20%20%20%20%20%20%20%20final%20ReentrantLock%20lock%20%3D%20this.lock%3B%0A%20%20%20%20%20%20%20%20lock.lock()%3B%2F%2F%E5%8A%A0%E9%94%81%0A%20%20%20%20%20%20%20%20try%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20Object%5B%5D%20elements%20%3D%20getArray()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20int%20len%20%3D%20elements.length%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20Object%5B%5D%20newElements%20%3D%20Arrays.copyOf(elements%2C%20len%20%2B%201)%3B%2F%2F%E6%8B%B7%E8%B4%9D%E6%96%B0%E6%95%B0%E7%BB%84%0A%20%20%20%20%20%20%20%20%20%20%20%20newElements%5Blen%5D%20%3D%20e%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20setArray(newElements)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20true%3B%0A%20%20%20%20%20%20%20%20%7D%20finally%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20lock.unlock()%3B%2F%2F%E9%87%8A%E6%94%BE%E9%94%81%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%60%60%60%0A%0A%23%23%23%204.%20ConcurrentLinkedQueue%0AJava%E6%8F%90%E4%BE%9B%E7%9A%84%E7%BA%BF%E7%A8%8B%E5%AE%89%E5%85%A8%E7%9A%84%20Queue%20%E5%8F%AF%E4%BB%A5%E5%88%86%E4%B8%BA%E9%98%BB%E5%A1%9E%E9%98%9F%E5%88%97%E5%92%8C%E9%9D%9E%E9%98%BB%E5%A1%9E%E9%98%9F%E5%88%97%EF%BC%8C%E5%85%B6%E4%B8%AD%E9%98%BB%E5%A1%9E%E9%98%9F%E5%88%97%E7%9A%84%E5%85%B8%E5%9E%8B%E4%BE%8B%E5%AD%90%E6%98%AF%20BlockingQueue%EF%BC%8C%E9%9D%9E%E9%98%BB%E5%A1%9E%E9%98%9F%E5%88%97%E7%9A%84%E5%85%B8%E5%9E%8B%E4%BE%8B%E5%AD%90%E6%98%AFConcurrentLinkedQueue%EF%BC%8C%E5%9C%A8%E5%AE%9E%E9%99%85%E5%BA%94%E7%94%A8%E4%B8%AD%E8%A6%81%E6%A0%B9%E6%8D%AE%E5%AE%9E%E9%99%85%E9%9C%80%E8%A6%81%E9%80%89%E7%94%A8%E9%98%BB%E5%A1%9E%E9%98%9F%E5%88%97%E6%88%96%E8%80%85%E9%9D%9E%E9%98%BB%E5%A1%9E%E9%98%9F%E5%88%97%E3%80%82%20%0A%E9%98%BB%E5%A1%9E%E9%98%9F%E5%88%97%E5%8F%AF%E4%BB%A5%E9%80%9A%E8%BF%87%E5%8A%A0%E9%94%81%E6%9D%A5%E5%AE%9E%E7%8E%B0%EF%BC%8C%E9%9D%9E%E9%98%BB%E5%A1%9E%E9%98%9F%E5%88%97%E5%8F%AF%E4%BB%A5%E9%80%9A%E8%BF%87%20CAS%20%E6%93%8D%E4%BD%9C%E5%AE%9E%E7%8E%B0%E3%80%82%0A%0A%E4%BB%8E%E5%90%8D%E5%AD%97%E5%8F%AF%E4%BB%A5%E7%9C%8B%E5%87%BA%EF%BC%8CConcurrentLinkedQueue%E8%BF%99%E4%B8%AA%E9%98%9F%E5%88%97%E4%BD%BF%E7%94%A8%E9%93%BE%E8%A1%A8%E4%BD%9C%E4%B8%BA%E5%85%B6%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%EF%BC%8EConcurrentLinkedQueue%20%E5%BA%94%E8%AF%A5%E7%AE%97%E6%98%AF**%E5%9C%A8%E9%AB%98%E5%B9%B6%E5%8F%91%E7%8E%AF%E5%A2%83%E4%B8%AD%E6%80%A7%E8%83%BD%E6%9C%80%E5%A5%BD%E7%9A%84%E9%98%9F%E5%88%97**%E4%BA%86%E3%80%82%E5%AE%83%E4%B9%8B%E6%89%80%E6%9C%89%E8%83%BD%E6%9C%89%E5%BE%88%E5%A5%BD%E7%9A%84%E6%80%A7%E8%83%BD%EF%BC%8C%E6%98%AF%E5%9B%A0%E4%B8%BA%E5%85%B6%E5%86%85%E9%83%A8%E5%A4%8D%E6%9D%82%E7%9A%84%E5%AE%9E%E7%8E%B0%E3%80%82%0A%0AConcurrentLinkedQueue%20%E5%86%85%E9%83%A8%E4%BB%A3%E7%A0%81%E6%88%91%E4%BB%AC%E5%B0%B1%E4%B8%8D%E5%88%86%E6%9E%90%E4%BA%86%EF%BC%8C%E5%A4%A7%E5%AE%B6%E7%9F%A5%E9%81%93ConcurrentLinkedQueue%20%E4%B8%BB%E8%A6%81%E4%BD%BF%E7%94%A8%20CAS%20%E9%9D%9E%E9%98%BB%E5%A1%9E%E7%AE%97%E6%B3%95%E6%9D%A5%E5%AE%9E%E7%8E%B0%E7%BA%BF%E7%A8%8B%E5%AE%89%E5%85%A8%E5%B0%B1%E5%A5%BD%E4%BA%86%E3%80%82%0A%0AConcurrentLinkedQueue%20%E9%80%82%E5%90%88%E5%9C%A8%E5%AF%B9%E6%80%A7%E8%83%BD%E8%A6%81%E6%B1%82%E7%9B%B8%E5%AF%B9%E8%BE%83%E9%AB%98%EF%BC%8C%E5%90%8C%E6%97%B6%E5%AF%B9%E9%98%9F%E5%88%97%E7%9A%84%E8%AF%BB%E5%86%99%E5%AD%98%E5%9C%A8%E5%A4%9A%E4%B8%AA%E7%BA%BF%E7%A8%8B%E5%90%8C%E6%97%B6%E8%BF%9B%E8%A1%8C%E7%9A%84%E5%9C%BA%E6%99%AF%EF%BC%8C%E5%8D%B3%E5%A6%82%E6%9E%9C%E5%AF%B9%E9%98%9F%E5%88%97%E5%8A%A0%E9%94%81%E7%9A%84%E6%88%90%E6%9C%AC%E8%BE%83%E9%AB%98%E5%88%99%E9%80%82%E5%90%88%E4%BD%BF%E7%94%A8%E6%97%A0%E9%94%81%E7%9A%84ConcurrentLinkedQueue%E6%9D%A5%E6%9B%BF%E4%BB%A3%E3%80%82%0A%0A%0A%23%23%23%205.%20BlockingQueue%0A%0A%23%23%23%23%205.1%20BlockingQueue%20%E7%AE%80%E5%8D%95%E4%BB%8B%E7%BB%8D%0A%0A%E9%98%BB%E5%A1%9E%E9%98%9F%E5%88%97%EF%BC%88BlockingQueue%EF%BC%89%E8%A2%AB%E5%B9%BF%E6%B3%9B%E4%BD%BF%E7%94%A8%E5%9C%A8%E2%80%9C%E7%94%9F%E4%BA%A7%E8%80%85-%E6%B6%88%E8%B4%B9%E8%80%85%E2%80%9D%E9%97%AE%E9%A2%98%E4%B8%AD%EF%BC%8C%E5%85%B6%E5%8E%9F%E5%9B%A0%E6%98%AFBlockingQueue%E6%8F%90%E4%BE%9B%E4%BA%86%E5%8F%AF%E9%98%BB%E5%A1%9E%E7%9A%84%E6%8F%92%E5%85%A5%E5%92%8C%E7%A7%BB%E9%99%A4%E7%9A%84%E6%96%B9%E6%B3%95%E3%80%82%E5%BD%93%E9%98%9F%E5%88%97%E5%AE%B9%E5%99%A8%E5%B7%B2%E6%BB%A1%EF%BC%8C%E7%94%9F%E4%BA%A7%E8%80%85%E7%BA%BF%E7%A8%8B%E4%BC%9A%E8%A2%AB%E9%98%BB%E5%A1%9E%EF%BC%8C%E7%9B%B4%E5%88%B0%E9%98%9F%E5%88%97%E6%9C%AA%E6%BB%A1%EF%BC%9B%E5%BD%93%E9%98%9F%E5%88%97%E5%AE%B9%E5%99%A8%E4%B8%BA%E7%A9%BA%E6%97%B6%EF%BC%8C%E6%B6%88%E8%B4%B9%E8%80%85%E7%BA%BF%E7%A8%8B%E4%BC%9A%E8%A2%AB%E9%98%BB%E5%A1%9E%EF%BC%8C%E7%9B%B4%E8%87%B3%E9%98%9F%E5%88%97%E9%9D%9E%E7%A9%BA%E6%97%B6%E4%B8%BA%E6%AD%A2%E3%80%82%0A%0ABlockingQueue%20%E6%98%AF%E4%B8%80%E4%B8%AA%E6%8E%A5%E5%8F%A3%EF%BC%8C%E7%BB%A7%E6%89%BF%E8%87%AA%20Queue%EF%BC%8C%E6%89%80%E4%BB%A5%E5%85%B6%E5%AE%9E%E7%8E%B0%E7%B1%BB%E4%B9%9F%E5%8F%AF%E4%BB%A5%E4%BD%9C%E4%B8%BA%20Queue%20%E7%9A%84%E5%AE%9E%E7%8E%B0%E6%9D%A5%E4%BD%BF%E7%94%A8%EF%BC%8C%E8%80%8C%20Queue%20%E5%8F%88%E7%BB%A7%E6%89%BF%E8%87%AA%20Collection%20%E6%8E%A5%E5%8F%A3%E3%80%82%0A%0A%E4%B8%BB%E8%A6%81%E4%BB%8B%E7%BB%8D%E4%B8%80%E4%B8%8B%3A**ArrayBlockingQueue**%E3%80%81**LinkedBlockingQueue**%E3%80%81**PriorityBlockingQueue**%EF%BC%8C%E8%BF%99%E4%B8%89%E4%B8%AA%20BlockingQueue%20%E7%9A%84%E5%AE%9E%E7%8E%B0%E7%B1%BB%E3%80%82%0A%0A%23%23%23%23%205.2%20ArrayBlockingQueue%0AArrayBlockingQueue%20%E6%98%AF%20BlockingQueue%20%E6%8E%A5%E5%8F%A3%E7%9A%84%E6%9C%89%E7%95%8C%E9%98%9F%E5%88%97%E5%AE%9E%E7%8E%B0%E7%B1%BB%EF%BC%8C%E5%BA%95%E5%B1%82%E9%87%87%E7%94%A8%E6%95%B0%E7%BB%84%E6%9D%A5%E5%AE%9E%E7%8E%B0%E3%80%82ArrayBlockingQueue%E4%B8%80%E6%97%A6%E5%88%9B%E5%BB%BA%EF%BC%8C%E5%AE%B9%E9%87%8F%E4%B8%8D%E8%83%BD%E6%94%B9%E5%8F%98%E3%80%82%E5%85%B6%E5%B9%B6%E5%8F%91%E6%8E%A7%E5%88%B6%E9%87%87%E7%94%A8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B4%E9%A1%BA%E5%BA%8F%EF%BC%8C%E5%8D%B3%E6%9C%80%E5%85%88%E7%AD%89%E5%BE%85%E7%9A%84%E7%BA%BF%E7%A8%8B%E8%83%BD%E5%A4%9F%E6%9C%80%E5%85%88%E8%AE%BF%E9%97%AE%E5%88%B0%20ArrayBlockingQueue%E3%80%82%E8%80%8C%E9%9D%9E%E5%85%AC%E5%B9%B3%E6%80%A7%E5%88%99%E6%98%AF%E6%8C%87%E8%AE%BF%E9%97%AE%20ArrayBlockingQueue%20%E7%9A%84%E9%A1%BA%E5%BA%8F%E4%B8%8D%E6%98%AF%E9%81%B5%E5%AE%88%E4%B8%A5%E6%A0%BC%E7%9A%84%E6%97%B6%E9%97%B4%E9%A1%BA%E5%BA%8F%EF%BC%8C%E6%9C%89%E5%8F%AF%E8%83%BD%E5%AD%98%E5%9C%A8%EF%BC%8C%E5%BD%93%20ArrayBlockingQueue%20%E5%8F%AF%E4%BB%A5%E8%A2%AB%E8%AE%BF%E9%97%AE%E6%97%B6%EF%BC%8C%E9%95%BF%E6%97%B6%E9%97%B4%E9%98%BB%E5%A1%9E%E7%9A%84%E7%BA%BF%E7%A8%8B%E4%BE%9D%E7%84%B6%E6%97%A0%E6%B3%95%E8%AE%BF%E9%97%AE%E5%88%B0%20ArrayBlockingQueue%E3%80%82%E5%A6%82%E6%9E%9C%E4%BF%9D%E8%AF%81%E5%85%AC%E5%B9%B3%E6%80%A7%EF%BC%8C%E9%80%9A%E5%B8%B8%E4%BC%9A%E9%99%8D%E4%BD%8E%E5%90%9E%E5%90%90%E9%87%8F%E3%80%82%0A%0A%E5%8F%AF%E4%BB%A5%E9%80%9A%E8%BF%87%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%E6%9D%A5%E5%AE%9E%E7%8E%B0%E5%85%AC%E5%B9%B3%E6%80%A7%E3%80%82%0A%0A%23%23%23%23%205.3%20LinkedBlockingQueue%0ALinkedBlockingQueue%20%E5%BA%95%E5%B1%82%E5%9F%BA%E4%BA%8E%E5%8D%95%E5%90%91%E9%93%BE%E8%A1%A8%E5%AE%9E%E7%8E%B0%E7%9A%84%E9%98%BB%E5%A1%9E%E9%98%9F%E5%88%97%EF%BC%8C%E5%8F%AF%E4%BB%A5%E5%BD%93%E5%81%9A%E6%97%A0%E7%95%8C%E9%98%9F%E5%88%97%E4%B9%9F%E5%8F%AF%E4%BB%A5%E5%BD%93%E5%81%9A%E6%9C%89%E7%95%8C%E9%98%9F%E5%88%97%E6%9D%A5%E4%BD%BF%E7%94%A8%EF%BC%8C%E5%90%8C%E6%A0%B7%E6%BB%A1%E8%B6%B3FIFO%E7%9A%84%E7%89%B9%E6%80%A7%EF%BC%8C%E4%B8%8EArrayBlockingQueue%20%E7%9B%B8%E6%AF%94%E8%B5%B7%E6%9D%A5%E5%85%B7%E6%9C%89%E6%9B%B4%E9%AB%98%E7%9A%84%E5%90%9E%E5%90%90%E9%87%8F%EF%BC%8C%E4%B8%BA%E4%BA%86%E9%98%B2%E6%AD%A2%20LinkedBlockingQueue%20%E5%AE%B9%E9%87%8F%E8%BF%85%E9%80%9F%E5%A2%9E%EF%BC%8C%E6%8D%9F%E8%80%97%E5%A4%A7%E9%87%8F%E5%86%85%E5%AD%98%E3%80%82%E9%80%9A%E5%B8%B8%E5%9C%A8%E5%88%9B%E5%BB%BALinkedBlockingQueue%20%E5%AF%B9%E8%B1%A1%E6%97%B6%EF%BC%8C%E4%BC%9A%E6%8C%87%E5%AE%9A%E5%85%B6%E5%A4%A7%E5%B0%8F%EF%BC%8C%E5%A6%82%E6%9E%9C%E6%9C%AA%E6%8C%87%E5%AE%9A%EF%BC%8C%E5%AE%B9%E9%87%8F%E7%AD%89%E4%BA%8EInteger.MAX_VALUE%E3%80%82%0A%0A%60%60%60java%0A%20%20%20%20%2F**%0A%20%20%20%20%20*%E6%9F%90%E7%A7%8D%E6%84%8F%E4%B9%89%E4%B8%8A%E7%9A%84%E6%97%A0%E7%95%8C%E9%98%9F%E5%88%97%0A%20%20%20%20%20*%20Creates%20a%20%7B%40code%20LinkedBlockingQueue%7D%20with%20a%20capacity%20of%0A%20%20%20%20%20*%20%7B%40link%20Integer%23MAX_VALUE%7D.%0A%20%20%20%20%20*%2F%0A%20%20%20%20public%20LinkedBlockingQueue()%20%7B%0A%20%20%20%20%20%20%20%20this(Integer.MAX_VALUE)%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20%2F**%0A%20%20%20%20%20*%E6%9C%89%E7%95%8C%E9%98%9F%E5%88%97%0A%20%20%20%20%20*%20Creates%20a%20%7B%40code%20LinkedBlockingQueue%7D%20with%20the%20given%20(fixed)%20capacity.%0A%20%20%20%20%20*%0A%20%20%20%20%20*%20%40param%20capacity%20the%20capacity%20of%20this%20queue%0A%20%20%20%20%20*%20%40throws%20IllegalArgumentException%20if%20%7B%40code%20capacity%7D%20is%20not%20greater%0A%20%20%20%20%20*%20%20%20%20%20%20%20%20%20than%20zero%0A%20%20%20%20%20*%2F%0A%20%20%20%20public%20LinkedBlockingQueue(int%20capacity)%20%7B%0A%20%20%20%20%20%20%20%20if%20(capacity%20%3C%3D%200)%20throw%20new%20IllegalArgumentException()%3B%0A%20%20%20%20%20%20%20%20this.capacity%20%3D%20capacity%3B%0A%20%20%20%20%20%20%20%20last%20%3D%20head%20%3D%20new%20Node%3CE%3E(null)%3B%0A%20%20%20%20%7D%0A%60%60%60%0A%0A%23%23%23%23%205.4%20PriorityBlockingQueue%0APriorityBlockingQueue%20%E6%98%AF%E4%B8%80%E4%B8%AA%E6%94%AF%E6%8C%81%E4%BC%98%E5%85%88%E7%BA%A7%E7%9A%84%E6%97%A0%E7%95%8C%E9%98%BB%E5%A1%9E%E9%98%9F%E5%88%97%E3%80%82%E9%BB%98%E8%AE%A4%E6%83%85%E5%86%B5%E4%B8%8B%E5%85%83%E7%B4%A0%E9%87%87%E7%94%A8%E8%87%AA%E7%84%B6%E9%A1%BA%E5%BA%8F%E8%BF%9B%E8%A1%8C%E6%8E%92%E5%BA%8F%EF%BC%8C%E4%B9%9F%E5%8F%AF%E4%BB%A5%E9%80%9A%E8%BF%87%E8%87%AA%E5%AE%9A%E4%B9%89%E7%B1%BB%E5%AE%9E%E7%8E%B0%20compareTo()%20%E6%96%B9%E6%B3%95%E6%9D%A5%E6%8C%87%E5%AE%9A%E5%85%83%E7%B4%A0%E6%8E%92%E5%BA%8F%E8%A7%84%E5%88%99%EF%BC%8C%E6%88%96%E8%80%85%E5%88%9D%E5%A7%8B%E5%8C%96%E6%97%B6%E9%80%9A%E8%BF%87%E6%9E%84%E9%80%A0%E5%99%A8%E5%8F%82%E6%95%B0%20Comparator%20%E6%9D%A5%E6%8C%87%E5%AE%9A%E6%8E%92%E5%BA%8F%E8%A7%84%E5%88%99%E3%80%82%0A%0APriorityBlockingQueue%20%E5%B9%B6%E5%8F%91%E6%8E%A7%E5%88%B6%E9%87%87%E7%94%A8%E7%9A%84%E6%98%AF%20ReentrantLock%EF%BC%8C%E9%98%9F%E5%88%97%E4%B8%BA%E6%97%A0%E7%95%8C%E9%98%9F%E5%88%97%EF%BC%88ArrayBlockingQueue%20%E6%98%AF%E6%9C%89%E7%95%8C%E9%98%9F%E5%88%97%EF%BC%8CLinkedBlockingQueue%20%E4%B9%9F%E5%8F%AF%E4%BB%A5%E9%80%9A%E8%BF%87%E5%9C%A8%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%E4%B8%AD%E4%BC%A0%E5%85%A5%20capacity%20%E6%8C%87%E5%AE%9A%E9%98%9F%E5%88%97%E6%9C%80%E5%A4%A7%E7%9A%84%E5%AE%B9%E9%87%8F%EF%BC%8C%E4%BD%86%E6%98%AF%20PriorityBlockingQueue%20%E5%8F%AA%E8%83%BD%E6%8C%87%E5%AE%9A%E5%88%9D%E5%A7%8B%E7%9A%84%E9%98%9F%E5%88%97%E5%A4%A7%E5%B0%8F%EF%BC%8C%E5%90%8E%E9%9D%A2%E6%8F%92%E5%85%A5%E5%85%83%E7%B4%A0%E7%9A%84%E6%97%B6%E5%80%99%EF%BC%8C%E5%A6%82%E6%9E%9C%E7%A9%BA%E9%97%B4%E4%B8%8D%E5%A4%9F%E7%9A%84%E8%AF%9D%E4%BC%9A%E8%87%AA%E5%8A%A8%E6%89%A9%E5%AE%B9%EF%BC%89%E3%80%82%0A%0A%E7%AE%80%E5%8D%95%E5%9C%B0%E8%AF%B4%EF%BC%8C%E5%AE%83%E5%B0%B1%E6%98%AF%20PriorityQueue%20%E7%9A%84%E7%BA%BF%E7%A8%8B%E5%AE%89%E5%85%A8%E7%89%88%E6%9C%AC%E3%80%82%E4%B8%8D%E5%8F%AF%E4%BB%A5%E6%8F%92%E5%85%A5%20null%20%E5%80%BC%EF%BC%8C%E5%90%8C%E6%97%B6%EF%BC%8C%E6%8F%92%E5%85%A5%E9%98%9F%E5%88%97%E7%9A%84%E5%AF%B9%E8%B1%A1%E5%BF%85%E9%A1%BB%E6%98%AF%E5%8F%AF%E6%AF%94%E8%BE%83%E5%A4%A7%E5%B0%8F%E7%9A%84%EF%BC%88comparable%EF%BC%89%EF%BC%8C%E5%90%A6%E5%88%99%E6%8A%A5%20ClassCastException%20%E5%BC%82%E5%B8%B8%E3%80%82%E5%AE%83%E7%9A%84%E6%8F%92%E5%85%A5%E6%93%8D%E4%BD%9C%20put%20%E6%96%B9%E6%B3%95%E4%B8%8D%E4%BC%9A%20block%EF%BC%8C%E5%9B%A0%E4%B8%BA%E5%AE%83%E6%98%AF%E6%97%A0%E7%95%8C%E9%98%9F%E5%88%97%EF%BC%88take%20%E6%96%B9%E6%B3%95%E5%9C%A8%E9%98%9F%E5%88%97%E4%B8%BA%E7%A9%BA%E7%9A%84%E6%97%B6%E5%80%99%E4%BC%9A%E9%98%BB%E5%A1%9E%EF%BC%89%E3%80%82%0A%0A%0A%23%23%23%206.%20ConcurrentSkipListMap%0A%E4%B8%BA%E4%BA%86%E5%BC%95%E5%87%BAConcurrentSkipListMap%EF%BC%8C%E5%85%88%E5%B8%A6%E7%9D%80%E5%A4%A7%E5%AE%B6%E7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%E3%80%82%E8%BF%99%E6%A0%B7%EF%BC%8C%E5%9C%A8%E9%AB%98%E5%B9%B6%E5%8F%91%E7%8E%AF%E5%A2%83%E4%B8%8B%EF%BC%8C%E4%BD%A0%E5%B0%B1%E5%8F%AF%E4%BB%A5%E6%8B%A5%E6%9C%89%E6%9B%B4%E5%A5%BD%E7%9A%84%E6%80%A7%E8%83%BD%E3%80%82%E8%80%8C%E5%B0%B1%E6%9F%A5%E8%AF%A2%E7%9A%84%E6%80%A7%E8%83%BD%E8%80%8C%E8%A8%80%EF%BC%8C%E8%B7%B3%E8%A1%A8%E7%9A%84%E6%97%B6%E9%97%B4%E5%A4%8D%E6%9D%82%E5%BA%A6%E4%B9%9F%E6%98%AF%20O(logn)%20%E6%89%80%E4%BB%A5%E5%9C%A8%E5%B9%B6%E5%8F%91%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B8%AD%EF%BC%8CJDK%20%E4%BD%BF%E7%94%A8%E8%B7%B3%E8%A1%A8%E6%9D%A5%E5%AE%9E%E7%8E%B0%E4%B8%80%E4%B8%AA%20Map%E3%80%82%0A%0A%0A%E8%B7%B3%E8%A1%A8%E7%9A%84%E6%9C%AC%E8%B4%A8%E6%98%AF%E5%90%8C%E6%97%B6%E7%BB%B4%E6%8A%A4%E4%BA%86%E5%A4%9A%E4%B8%AA%E9%93%BE%E8%A1%A8%EF%BC%8C%E5%B9%B6%E4%B8%94%E9%93%BE%E8%A1%A8%E6%98%AF%E5%88%86%E5%B1%82%E7%9A%84%EF%BC%8C%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/cce14de8-4f98-4388-b62b-2f04258c20c6/0f3da28f-d539-4f5e-bd79-01f0dc0e0146.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F581%3A1)%0A%0A%0A%E6%9C%80%E4%BD%8E%E5%B1%82%E7%9A%84%E9%93%BE%E8%A1%A8%E7%BB%B4%E6%8A%A4%E4%BA%86%E8%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6%89%BE18%20%E7%9A%84%E6%97%B6%E5%80%99%E5%8E%9F%E6%9D%A5%E9%9C%80%E8%A6%81%E9%81%8D%E5%8E%86%2018%20%E6%AC%A1%EF%BC%8C%E7%8E%B0%E5%9C%A8%E5%8F%AA%E9%9C%80%E8%A6%81%207%20%E6%AC%A1%E5%8D%B3%E5%8F%AF%E3%80%82%E9%92%88%E5%AF%B9%E9%93%BE%E8%A1%A8%E9%95%BF%E5%BA%A6%E6%AF%94%E8%BE%83%E5%A4%A7%E7%9A%84%E6%97%B6%E5%80%99%EF%BC%8C%E6%9E%84%E5%BB%BA%E7%B4%A2%E5%BC%95%E6%9F%A5%E6%89%BE%E6%95%88%E7%8E%87%E7%9A%84%E6%8F%90%E5%8D%87%E5%B0%B1%E4%BC%9A%E9%9D%9E%E5%B8%B8%E6%98%8E%E6%98%BE%E3%80%82%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/cce14de8-4f98-4388-b62b-2f04258c20c6/5682a98f-cad2-47aa-a0d0-1bd178d5fbc7.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F580%3A1)%0A%0A**%E8%B7%B3%E8%A1%A8%E6%98%AF%E4%B8%80%E7%A7%8D%E5%88%A9%E7%94%A8%E7%A9%BA%E9%97%B4%E6%8D%A2%E6%97%B6%E9%97%B4%E7%9A%84%E7%AE%97%E6%B3%95**%0A%0A%E4%BD%BF%E7%94%A8%E8%B7%B3%E8%A1%A8%E5%AE%9E%E7%8E%B0Map%20%E5%92%8C%E4%BD%BF%E7%94%A8%E5%93%88%E5%B8%8C%E7%AE%97%E6%B3%95%E5%AE%9E%E7%8E%B0Map%E7%9A%84%E5%8F%A6%E5%A4%96%E4%B8%80%E4%B8%AA%E4%B8%8D%E5%90%8C%E4%B9%8B%E5%A4%84%E6%98%AF%EF%BC%9A%E5%93%88%E5%B8%8C%E5%B9%B6%E4%B8%8D%E4%BC%9A%E4%BF%9D%E5%AD%98%E5%85%83%E7%B4%A0%E7%9A%84%E9%A1%BA%E5%BA%8F%EF%BC%8C%E8%80%8C%E8%B7%B3%E8%A1%A8%E5%86%85%E6%89%80%E6%9C%89%E7%9A%84%E5%85%83%E7%B4%A0%E9%83%BD%E6%98%AF%E6%8E%92%E5%BA%8F%E7%9A%84%E3%80%82%E5%9B%A0%E6%AD%A4%E5%9C%A8%E5%AF%B9%E8%B7%B3%E8%A1%A8%E8%BF%9B%E8%A1%8C%E9%81%8D%E5%8E%86%E6%97%B6%EF%BC%8C%E4%BD%A0%E4%BC%9A%E5%BE%97%E5%88%B0%E4%B8%80%E4%B8%AA%E6%9C%89%E5%BA%8F%E7%9A%84%E7%BB%93%E6%9E%9C%E3%80%82%E6%89%80%E4%BB%A5%EF%BC%8C%E5%A6%82%E6%9E%9C%E4%BD%A0%E7%9A%84%E5%BA%94%E7%94%A8%E9%9C%80%E8%A6%81%E6%9C%89%E5%BA%8F%E6%80%A7%EF%BC%8C%E9%82%A3%E4%B9%88%E8%B7%B3%E8%A1%A8%E5%B0%B1%E6%98%AF%E4%BD%A0%E4%B8%8D%E4%BA%8C%E7%9A%84%E9%80%89%E6%8B%A9%E3%80%82JDK%20%E4%B8%AD%E5%AE%9E%E7%8E%B0%E8%BF%99%E4%B8%80%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E7%9A%84%E7%B1%BB%E6%98%AFConcurrentSkipListMap%E3%80%82%0A%0A&lt;/center&gt;&lt;/div&gt;
</content>
  </entry>
  <entry xml:base="http://linzhiteng.postach.io/feed.xml">
    <title type="text">八. AQS 原理以及 AQS 同步组件总结</title>
    <id>https://linzhiteng.postach.io/post/ba-aqs-yuan-li-yi-ji-aqs-tong-bu-zu-jian-zong-jie</id>
    <updated>2019-06-09T13:07:31.108000Z</updated>
    <published>2019-03-13T11:52:20Z</published>
    <link href="https://linzhiteng.postach.io/post/ba-aqs-yuan-li-yi-ji-aqs-tong-bu-zu-jian-zong-jie" />
    <author>
      <name>linzhi teng</name>
    </author>
    <category term="xian-cheng" />
    <content type="html">&lt;div&gt;&lt;div style=&quot;font-size: 14px; margin: 0; padding: 0; width: 100%;&quot;&gt;&lt;div style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;八. AQS 原理以及 AQS 同步组件总结
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1. AQS 简单介绍
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2. AQS 原理
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.1 AQS 原理概览
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.2 AQS 对资源的共享方式
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.3 AQS底层使用了模板方法模式
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3. Semaphore(信号量)-允许多个线程同时访问
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4. CountDownLatch （倒计时器）
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.1 CountDownLatch 的两种典型用法
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.2 CountDownLatch 的使用示例
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.3 CountDownLatch 的不足
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;5. CyclicBarrier(循环栅栏)
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;5.1 CyclicBarrier 的应用场景
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;5.2 CyclicBarrier 的使用示例
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;5.3 CyclicBarrier和CountDownLatch的区别
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;八. AQS 原理以及 AQS 同步组件总结&lt;/h2&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/9c392d1e-685a-4953-8bda-1b27de318db1/0628152e-cb60-4ce5-af97-b8532e01ba6a.jpg&quot; /&gt;&lt;/p&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;1. AQS 简单介绍&lt;/h3&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;AQS的全称为（AbstractQueuedSynchronizer），这个类在java.util.concurrent.locks包下面。&lt;/p&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;AQS是一个用来构建&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;锁&lt;/strong&gt;和&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;同步器&lt;/strong&gt;的框架，使用AQS能简单且高效地构造出应用广泛的大量的同步器，比如我们提到的ReentrantLock，Semaphore，其他的诸如ReentrantReadWriteLock，SynchronousQueue，FutureTask等等皆是基于AQS的。当然，我们自己也能利用AQS非常轻松容易地构造出符合我们自己需求的同步器。&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;2. AQS 原理&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.1 AQS 原理概览&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;AQS核心思想是，如果被请求的共享资源空闲，则将当前请求资源的线程设置为有效的工作线程，并且将共享资源设置为锁定状态。如果被请求的共享资源被占用，那么就需要一套线程阻塞等待以及被唤醒时锁分配的机制，这个机制AQS是用&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;CLH队列锁&lt;/strong&gt;实现的，即将&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;暂时获取不到锁的线程加入到队列中&lt;/strong&gt;。&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;CLH(Craig,Landin,and Hagersten)队列是一个虚拟的双向队列（虚拟的双向队列即不存在队列实例，仅存在结点之间的关联关系）。AQS是将每条请求共享资源的线程封装成一个CLH锁队列的一个结点（Node）来实现锁的分配。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;AQS(AbstractQueuedSynchronizer)原理图&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/9c392d1e-685a-4953-8bda-1b27de318db1/291f36a1-7e28-42ff-9deb-cb1544de908e.png&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;AQS使用一个int成员变量state来表示同步状态，通过内置的FIFO队列来完成获取资源线程的排队工作。AQS使用CAS对该同步状态进行原子操作实现对其值的修改。&lt;/p&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;volatile&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; state;&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//共享变量，使用volatile修饰保证线程可见性&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;状态信息通过procted类型的getState，setState，compareAndSetState进行操作&lt;/p&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//返回同步状态的当前值&lt;/span&gt;
&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;protected&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;final&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;getState&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{  
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt; state;
}
 &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;// 设置同步状态的值&lt;/span&gt;
&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;protected&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;final&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;setState&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; newState)&lt;/span&gt; &lt;/span&gt;{ 
        state = newState;
}
&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//原子地（CAS操作）将同步状态值设置为给定值update如果当前同步状态的值等于expect（期望值）&lt;/span&gt;
&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;protected&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;final&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;boolean&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;compareAndSetState&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; expect, &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; update)&lt;/span&gt; &lt;/span&gt;{
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt; unsafe.compareAndSwapInt(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;this&lt;/span&gt;, stateOffset, expect, update);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.2 AQS 对资源的共享方式&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;AQS定义两种资源共享方式&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;Exclusive（独占）：只有一个线程能执行，如ReentrantLock。又可分为公平锁和非公平锁：
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;公平锁：按照线程在队列中的排队顺序，先到者先拿到锁&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;非公平锁：当线程要获取锁时，无视队列顺序直接去抢锁，谁抢到就是谁的&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;Share（共享）：多个线程可同时执行，如Semaphore/CountDownLatch。Semaphore、CountDownLatCh、 CyclicBarrier、ReadWriteLock 我们都会在后面讲到。&lt;/li&gt;
&lt;/ul&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;ReentrantReadWriteLock 可以看成是组合式，因为ReentrantReadWriteLock也就是读写锁允许多个线程同时对某一资源进行读。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;不同的&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;自定义同步器&lt;/strong&gt;争用共享资源的方式也不同。自定义同步器在实现时&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;只需要实现共享资源 state 的获取与释放方式即可&lt;/strong&gt;，至于具体线程等待队列的维护（如获取资源失败入队/唤醒出队等），AQS已经在上层已经帮我们实现好了。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.3 AQS底层使用了模板方法模式&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;同步器的设计是&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;基于模板方法模式&lt;/strong&gt;的，如果需要自定义同步器一般的方式是这样（模板方法模式很经典的一个应用）：&lt;/p&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;使用者继承AbstractQueuedSynchronizer并重写指定的方法。（这些重写方法很简单，无非是对于共享资源state的获取和释放）&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;将AQS组合在自定义同步组件的实现中，并调用其模板方法，而这些模板方法会调用使用者重写的方法。&lt;/li&gt;
&lt;/ol&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;模板方法模式&lt;/strong&gt;，模板方法模式是一个很容易理解的设计模式之一&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;模板方法模式是基于&quot;继承&quot;的，主要是为了在不改变模板结构的前提下在子类中重新定义模板中的内容以实现复用代码。&lt;br/&gt;
举个很简单的例子假如我们要去一个地方的步骤是：购票buyTicket()-&gt;安检securityCheck()-&gt;乘坐某某工具回家ride()-&gt;到达目的地arrive()。我们可能乘坐不同的交通工具回家比如飞机或者火车，所以除了ride()方法，其他方法的实现几乎相同。&lt;br/&gt;
我们可以定义一个包含了这些方法的抽象类，然后用户根据自己的需要继承该抽象类然后修改 ride()方法。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;AQS使用了模板方法模式，自定义同步器时需要重写下面几个AQS提供的模板方法：&lt;/p&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;isHeldExclusively()&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//该线程是否正在独占资源。只有用到condition才需要去实现它。&lt;/span&gt;

tryAcquire(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt;)&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//独占方式。尝试获取资源，成功则返回true，失败则返回false。&lt;/span&gt;

tryRelease(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt;)&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//独占方式。尝试释放资源，成功则返回true，失败则返回false。&lt;/span&gt;

tryAcquireShared(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt;)&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//共享方式。尝试获取资源。负数表示失败；0表示成功，但没有剩余可用资源；正数表示成功，且有剩余资源。&lt;/span&gt;

tryReleaseShared(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt;)&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//共享方式。尝试释放资源，成功则返回true，失败则返回false。&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;默认情况下，每个方法都抛出 UnsupportedOperationException。 这些方法的实现必须是内部线程安全的，并且通常应该简短而不是阻塞。AQS类中的其他方法都是final ，所以无法被其他类使用，只有这几个方法可以被其他类使用。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;以ReentrantLock为例&lt;/strong&gt;，state初始化为0，表示未锁定状态。A线程lock()时，会调用tryAcquire()独占该锁并将state+1。此后，其他线程再tryAcquire()时就会失败，直到A线程unlock()到state=0（即释放锁）为止，其它线程才有机会获取该锁。当然，释放锁之前，A线程自己是可以重复获取此锁的（state会累加），这就是可重入的概念。但要注意，获取多少次就要释放多么次，这样才能保证state是能回到零态的。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;再&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;以CountDownLatch以例&lt;/strong&gt;，任务分为N个子线程去执行，state也初始化为N（注意N要与线程个数一致）。这N个子线程是并行执行的，每个子线程执行完后countDown()一次，state会CAS(Compare and Swap)减1。等到所有子线程都执行完后(即state=0)，会unpark()主调用线程，然后主调用线程就会从await()函数返回，继续后余动作。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;一般来说，自定义同步器要么是独占方法，要么是共享方式，他们也只需实现&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;tryAcquire-tryRelease&lt;/code&gt;、&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;tryAcquireShared-tryReleaseShared&lt;/code&gt;中的一种即可。但AQS也支持自定义同步器同时实现独占和共享两种方式，如ReentrantReadWriteLock。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;a href=&quot;http://www.cnblogs.com/waterystone/p/4920797.html&quot; style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;AQS源码解析&lt;/a&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;a href=&quot;https://www.cnblogs.com/chengxiao/archive/2017/07/24/7141160.html&quot; style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;AQS源码解析&lt;/a&gt;&lt;/p&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;3. Semaphore(信号量)-允许多个线程同时访问&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;synchronized 和 ReentrantLock 都是一次只允许一个线程访问某个资源，Semaphore(信号量)可以指定多个线程同时访问某个资源。&lt;/strong&gt;&lt;/p&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;/**
 * 
 * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@author&lt;/span&gt; Snailclimb
 * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@date&lt;/span&gt; 2018年9月30日
 * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@Description&lt;/span&gt;: 需要一次性拿一个许可的情况
 */&lt;/span&gt;
&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;SemaphoreExample1&lt;/span&gt; &lt;/span&gt;{
	&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;// 请求的数量&lt;/span&gt;
	&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;final&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; threadCount = &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;550&lt;/span&gt;;

	&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;main&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(String[] args)&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;throws&lt;/span&gt; InterruptedException &lt;/span&gt;{
		&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;// 创建一个具有固定线程数量的线程池对象（如果这里线程池的线程数量给太少的话你会发现执行的很慢）&lt;/span&gt;
		ExecutorService threadPool = Executors.newFixedThreadPool(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;300&lt;/span&gt;);
		&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;// 一次只能允许执行的线程数量。&lt;/span&gt;
		&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;final&lt;/span&gt; Semaphore semaphore = &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; Semaphore(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;20&lt;/span&gt;);

		&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; i = &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0&lt;/span&gt;; i &lt; threadCount; i++) {
			&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;final&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; threadnum = i;
			threadPool.execute(() -&gt; {&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;// Lambda 表达式的运用&lt;/span&gt;
				&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;try&lt;/span&gt; {
					semaphore.acquire();&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;// 获取一个许可，所以可运行线程数量为20/1=20&lt;/span&gt;
					test(threadnum);
					semaphore.release();&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;// 释放一个许可&lt;/span&gt;
				} &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;catch&lt;/span&gt; (InterruptedException e) {
					&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;// TODO Auto-generated catch block&lt;/span&gt;
					e.printStackTrace();
				}

			});
		}
		threadPool.shutdown();
		System.out.println(&lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;finish&quot;&lt;/span&gt;);
	}

	&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;test&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; threadnum)&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;throws&lt;/span&gt; InterruptedException &lt;/span&gt;{
		Thread.sleep(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1000&lt;/span&gt;);&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;// 模拟请求的耗时操作&lt;/span&gt;
		System.out.println(&lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;threadnum:&quot;&lt;/span&gt; + threadnum);
		Thread.sleep(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1000&lt;/span&gt;);&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;// 模拟请求的耗时操作&lt;/span&gt;
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;执行 acquire 方法阻塞，直到有一个许可证可以获得然后拿走一个许可证；每个 release 方法增加一个许可证，这可能会释放一个阻塞的acquire方法。然而，其实并没有实际的许可证这个对象，Semaphore只是维持了一个可获得许可证的数量。 Semaphore经常&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;用于限制获取某种资源的线程数量&lt;/strong&gt;。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;除了 acquire方法之外，另一个比较常用的与之对应的方法是tryAcquire方法，该方法如果获取不到许可就立即返回false。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;Semaphore 有两种模式，公平模式和非公平模式。&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;公平模式： 调用acquire的顺序就是获取许可证的顺序，遵循FIFO；&lt;br/&gt;
非公平模式： 抢占式的。（默认）&lt;br/&gt;
构造函数可以指定模式。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;4. CountDownLatch （倒计时器）&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;CountDownLatch是一个同步工具类，用来协调多个线程之间的同步。这个工具通常用来&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;控制线程等待，它可以让某一个线程等待直到倒计时结束，再开始执行&lt;/strong&gt;。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;4.1 CountDownLatch 的两种典型用法&lt;/h4&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;某一线程在开始运行前等待n个线程执行完毕。将 CountDownLatch 的计数器初始化为n ：&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;new CountDownLatch(n)&lt;/code&gt;，每当一个任务线程执行完毕，就将计数器减1 &lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;countdownlatch.countDown()&lt;/code&gt;，当计数器的值变为0时，在&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;CountDownLatch上 await()&lt;/code&gt;的线程就会被唤醒。一个典型应用场景就是启动一个服务时，主线程需要等待多个组件加载完毕，之后再继续执行。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;实现多个线程开始执行任务的最大并行性。注意是并行性，不是并发，强调的是多个线程在某一时刻同时开始执行。类似于赛跑，将多个线程放到起点，等待发令枪响，然后同时开跑。做法是初始化一个共享的 CountDownLatch 对象，将其计数器初始化为 1 ：&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;new CountDownLatch(1)&lt;/code&gt;，多个线程在开始执行任务前首先 &lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;coundownlatch.await()&lt;/code&gt;，当主线程调用 countDown() 时，计数器变为0，多个线程同时被唤醒。&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;4.2 CountDownLatch 的使用示例&lt;/h4&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;/**
 * 
 * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@author&lt;/span&gt; SnailClimb
 * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@date&lt;/span&gt; 2018年10月1日
 * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@Description&lt;/span&gt;: CountDownLatch 使用方法示例
 */&lt;/span&gt;
&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;CountDownLatchExample1&lt;/span&gt; &lt;/span&gt;{
	&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;// 请求的数量&lt;/span&gt;
	&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;final&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; threadCount = &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;550&lt;/span&gt;;

	&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;main&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(String[] args)&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;throws&lt;/span&gt; InterruptedException &lt;/span&gt;{
		&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;// 创建一个具有固定线程数量的线程池对象（如果这里线程池的线程数量给太少的话你会发现执行的很慢）&lt;/span&gt;
		ExecutorService threadPool = Executors.newFixedThreadPool(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;300&lt;/span&gt;);
		&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;final&lt;/span&gt; CountDownLatch countDownLatch = &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; CountDownLatch(threadCount);
		&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; i = &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0&lt;/span&gt;; i &lt; threadCount; i++) {
			&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;final&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; threadnum = i;
			threadPool.execute(() -&gt; {&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;// Lambda 表达式的运用&lt;/span&gt;
				&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;try&lt;/span&gt; {
					test(threadnum);
				} &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;catch&lt;/span&gt; (InterruptedException e) {
					&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;// TODO Auto-generated catch block&lt;/span&gt;
					e.printStackTrace();
				} &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;finally&lt;/span&gt; {
					countDownLatch.countDown();&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;// 表示一个请求已经被完成&lt;/span&gt;
				}

			});
		}
		countDownLatch.await();
		threadPool.shutdown();
		System.out.println(&lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;finish&quot;&lt;/span&gt;);
	}

	&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;test&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; threadnum)&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;throws&lt;/span&gt; InterruptedException &lt;/span&gt;{
		Thread.sleep(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1000&lt;/span&gt;);&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;// 模拟请求的耗时操作&lt;/span&gt;
		System.out.println(&lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;threadnum:&quot;&lt;/span&gt; + threadnum);
		Thread.sleep(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1000&lt;/span&gt;);&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;// 模拟请求的耗时操作&lt;/span&gt;
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;4.3 CountDownLatch 的不足&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;CountDownLatch是一次性的，计数器的值只能在构造方法中初始化一次，之后没有任何机制再次对其设置值，当CountDownLatch使用完毕后，它不能再次被使用。&lt;/p&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;5. CyclicBarrier(循环栅栏)&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;CyclicBarrier 和 CountDownLatch 非常类似，它也可以实现线程间的技术等待，但是它的功能比 CountDownLatch 更加复杂和强大。主要应用场景和 CountDownLatch 类似。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;CyclicBarrier 的字面意思是可循环使用（Cyclic）的屏障（Barrier）。它要做的事情是，让一组线程到达一个屏障（也可以叫同步点）时被阻塞，直到最后一个线程到达屏障时，屏障才会开门，所有被屏障拦截的线程才会继续干活。CyclicBarrier默认的构造方法是 CyclicBarrier(int parties)，其参数表示屏障拦截的线程数量，每个线程调用await方法告诉 CyclicBarrier 我已经到达了屏障，然后当前线程被阻塞。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;5.1 CyclicBarrier 的应用场景&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;CyclicBarrier 可以用于多线程计算数据，最后合并计算结果的应用场景。比如我们用一个Excel保存了用户所有银行流水，每个Sheet保存一个帐户近一年的每笔银行流水，现在需要统计用户的日均银行流水，先用多线程处理每个sheet里的银行流水，都执行完之后，得到每个sheet的日均银行流水，最后，再用barrierAction用这些线程的计算结果，计算出整个Excel的日均银行流水。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;5.2 CyclicBarrier 的使用示例&lt;/h4&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;/**
 * 
 * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@author&lt;/span&gt; Snailclimb
 * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@date&lt;/span&gt; 2018年10月1日
 * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@Description&lt;/span&gt;: 测试 CyclicBarrier 类中带参数的 await() 方法
 */&lt;/span&gt;
&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;CyclicBarrierExample2&lt;/span&gt; &lt;/span&gt;{
	&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;// 请求的数量&lt;/span&gt;
	&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;final&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; threadCount = &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;550&lt;/span&gt;;
	&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;// 需要同步的线程数量&lt;/span&gt;
	&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;final&lt;/span&gt; CyclicBarrier cyclicBarrier = &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; CyclicBarrier(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;5&lt;/span&gt;);

	&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;main&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(String[] args)&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;throws&lt;/span&gt; InterruptedException &lt;/span&gt;{
		&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;// 创建线程池&lt;/span&gt;
		ExecutorService threadPool = Executors.newFixedThreadPool(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;10&lt;/span&gt;);

		&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; i = &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0&lt;/span&gt;; i &lt; threadCount; i++) {
			&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;final&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; threadNum = i;
			Thread.sleep(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1000&lt;/span&gt;);
			threadPool.execute(() -&gt; {
				&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;try&lt;/span&gt; {
					test(threadNum);
				} &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;catch&lt;/span&gt; (InterruptedException e) {
					&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;// TODO Auto-generated catch block&lt;/span&gt;
					e.printStackTrace();
				} &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;catch&lt;/span&gt; (BrokenBarrierException e) {
					&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;// TODO Auto-generated catch block&lt;/span&gt;
					e.printStackTrace();
				}
			});
		}
		threadPool.shutdown();
	}

	&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;test&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; threadnum)&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;throws&lt;/span&gt; InterruptedException, BrokenBarrierException &lt;/span&gt;{
		System.out.println(&lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;threadnum:&quot;&lt;/span&gt; + threadnum + &lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;is ready&quot;&lt;/span&gt;);
		&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;try&lt;/span&gt; {
			cyclicBarrier.await(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;2000&lt;/span&gt;, TimeUnit.MILLISECONDS);
		} &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;catch&lt;/span&gt; (Exception e) {
			System.out.println(&lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;-----CyclicBarrierException------&quot;&lt;/span&gt;);
		}
		System.out.println(&lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;threadnum:&quot;&lt;/span&gt; + threadnum + &lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;is finish&quot;&lt;/span&gt;);
	}

}
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;5.3 CyclicBarrier和CountDownLatch的区别&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;对于CountDownLatch来说，重点是&quot;一个线程（多个线程）等待&quot;，而其他的N个线程在完成&quot;某件事情&quot;之后，可以终止，也可以等待。&lt;br/&gt;
而对于CyclicBarrier，重点是多个线程，在&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;任意一个线程没有完成，所有的线程都必须等待&lt;/strong&gt;。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;CountDownLatch是计数器，线程完成一个记录一个，只不过计数不是递增而是递减，&lt;br/&gt;
而CyclicBarrier更像是一个阀门，需要所有线程都到达，阀门才能打开，然后继续执行。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/div&gt;&lt;center style='display:none !important;visibility:collapse !important;height:0 !important;white-space:nowrap;width:100%;overflow:hidden'&gt;%5Btoc%5D%0A%23%23%20%E5%85%AB.%20AQS%20%E5%8E%9F%E7%90%86%E4%BB%A5%E5%8F%8A%20AQS%20%E5%90%8C%E6%AD%A5%E7%BB%84%E4%BB%B6%E6%80%BB%E7%BB%93%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/9c392d1e-685a-4953-8bda-1b27de318db1/0628152e-cb60-4ce5-af97-b8532e01ba6a.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F591%3A1)%0A%23%23%23%201.%20AQS%20%E7%AE%80%E5%8D%95%E4%BB%8B%E7%BB%8D%0A1.%20AQS%E7%9A%84%E5%85%A8%E7%A7%B0%E4%B8%BA%EF%BC%88AbstractQueuedSynchronizer%EF%BC%89%EF%BC%8C%E8%BF%99%E4%B8%AA%E7%B1%BB%E5%9C%A8java.util.concurrent.locks%E5%8C%85%E4%B8%8B%E9%9D%A2%E3%80%82%0A%0A2.%20AQS%E6%98%AF%E4%B8%80%E4%B8%AA%E7%94%A8%E6%9D%A5%E6%9E%84%E5%BB%BA**%E9%94%81**%E5%92%8C**%E5%90%8C%E6%AD%A5%E5%99%A8**%E7%9A%84%E6%A1%86%E6%9E%B6%EF%BC%8C%E4%BD%BF%E7%94%A8AQS%E8%83%BD%E7%AE%80%E5%8D%95%E4%B8%94%E9%AB%98%E6%95%88%E5%9C%B0%E6%9E%84%E9%80%A0%E5%87%BA%E5%BA%94%E7%94%A8%E5%B9%BF%E6%B3%9B%E7%9A%84%E5%A4%A7%E9%87%8F%E7%9A%84%E5%90%8C%E6%AD%A5%E5%99%A8%EF%BC%8C%E6%AF%94%E5%A6%82%E6%88%91%E4%BB%AC%E6%8F%90%E5%88%B0%E7%9A%84ReentrantLock%EF%BC%8CSemaphore%EF%BC%8C%E5%85%B6%E4%BB%96%E7%9A%84%E8%AF%B8%E5%A6%82ReentrantReadWriteLock%EF%BC%8CSynchronousQueue%EF%BC%8CFutureTask%E7%AD%89%E7%AD%89%E7%9A%86%E6%98%AF%E5%9F%BA%E4%BA%8EAQS%E7%9A%84%E3%80%82%E5%BD%93%E7%84%B6%E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%A8%8B%E9%98%BB%E5%A1%9E%E7%AD%89%E5%BE%85%E4%BB%A5%E5%8F%8A%E8%A2%AB%E5%94%A4%E9%86%92%E6%97%B6%E9%94%81%E5%88%86%E9%85%8D%E7%9A%84%E6%9C%BA%E5%88%B6%EF%BC%8C%E8%BF%99%E4%B8%AA%E6%9C%BA%E5%88%B6AQS%E6%98%AF%E7%94%A8**CLH%E9%98%9F%E5%88%97%E9%94%81**%E5%AE%9E%E7%8E%B0%E7%9A%84%EF%BC%8C%E5%8D%B3%E5%B0%86**%E6%9A%82%E6%97%B6%E8%8E%B7%E5%8F%96%E4%B8%8D%E5%88%B0%E9%94%81%E7%9A%84%E7%BA%BF%E7%A8%8B%E5%8A%A0%E5%85%A5%E5%88%B0%E9%98%9F%E5%88%97%E4%B8%AD**%E3%80%82%0A%3ECLH(Craig%2CLandin%2Cand%20Hagersten)%E9%98%9F%E5%88%97%E6%98%AF%E4%B8%80%E4%B8%AA%E8%99%9A%E6%8B%9F%E7%9A%84%E5%8F%8C%E5%90%91%E9%98%9F%E5%88%97%EF%BC%88%E8%99%9A%E6%8B%9F%E7%9A%84%E5%8F%8C%E5%90%91%E9%98%9F%E5%88%97%E5%8D%B3%E4%B8%8D%E5%AD%98%E5%9C%A8%E9%98%9F%E5%88%97%E5%AE%9E%E4%BE%8B%EF%BC%8C%E4%BB%85%E5%AD%98%E5%9C%A8%E7%BB%93%E7%82%B9%E4%B9%8B%E9%97%B4%E7%9A%84%E5%85%B3%E8%81%94%E5%85%B3%E7%B3%BB%EF%BC%89%E3%80%82AQS%E6%98%AF%E5%B0%86%E6%AF%8F%E6%9D%A1%E8%AF%B7%E6%B1%82%E5%85%B1%E4%BA%AB%E8%B5%84%E6%BA%90%E7%9A%84%E7%BA%BF%E7%A8%8B%E5%B0%81%E8%A3%85%E6%88%90%E4%B8%80%E4%B8%AACLH%E9%94%81%E9%98%9F%E5%88%97%E7%9A%84%E4%B8%80%E4%B8%AA%E7%BB%93%E7%82%B9%EF%BC%88Node%EF%BC%89%E6%9D%A5%E5%AE%9E%E7%8E%B0%E9%94%81%E7%9A%84%E5%88%86%E9%85%8D%E3%80%82%0A%0AAQS(AbstractQueuedSynchronizer)%E5%8E%9F%E7%90%86%E5%9B%BE%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/9c392d1e-685a-4953-8bda-1b27de318db1/291f36a1-7e28-42ff-9deb-cb1544de908e.png.png%5D(en-resource%3A%2F%2Fdatabase%2F592%3A1)%0A%0AAQS%E4%BD%BF%E7%94%A8%E4%B8%80%E4%B8%AAint%E6%88%90%E5%91%98%E5%8F%98%E9%87%8Fstate%E6%9D%A5%E8%A1%A8%E7%A4%BA%E5%90%8C%E6%AD%A5%E7%8A%B6%E6%80%81%EF%BC%8C%E9%80%9A%E8%BF%87%E5%86%85%E7%BD%AE%E7%9A%84FIFO%E9%98%9F%E5%88%97%E6%9D%A5%E5%AE%8C%E6%88%90%E8%8E%B7%E5%8F%96%E8%B5%84%E6%BA%90%E7%BA%BF%E7%A8%8B%E7%9A%84%E6%8E%92%E9%98%9F%E5%B7%A5%E4%BD%9C%E3%80%82AQS%E4%BD%BF%E7%94%A8CAS%E5%AF%B9%E8%AF%A5%E5%90%8C%E6%AD%A5%E7%8A%B6%E6%80%81%E8%BF%9B%E8%A1%8C%E5%8E%9F%E5%AD%90%E6%93%8D%E4%BD%9C%E5%AE%9E%E7%8E%B0%E5%AF%B9%E5%85%B6%E5%80%BC%E7%9A%84%E4%BF%AE%E6%94%B9%E3%80%82%0A%60%60%60java%0Aprivate%20volatile%20int%20state%3B%2F%2F%E5%85%B1%E4%BA%AB%E5%8F%98%E9%87%8F%EF%BC%8C%E4%BD%BF%E7%94%A8volatile%E4%BF%AE%E9%A5%B0%E4%BF%9D%E8%AF%81%E7%BA%BF%E7%A8%8B%E5%8F%AF%E8%A7%81%E6%80%A7%0A%60%60%60%0A%E7%8A%B6%E6%80%81%E4%BF%A1%E6%81%AF%E9%80%9A%E8%BF%87procted%E7%B1%BB%E5%9E%8B%E7%9A%84getState%EF%BC%8CsetState%EF%BC%8CcompareAndSetState%E8%BF%9B%E8%A1%8C%E6%93%8D%E4%BD%9C%0A%60%60%60java%0A%2F%2F%E8%BF%94%E5%9B%9E%E5%90%8C%E6%AD%A5%E7%8A%B6%E6%80%81%E7%9A%84%E5%BD%93%E5%89%8D%E5%80%BC%0Aprotected%20final%20int%20getState()%20%7B%20%20%0A%20%20%20%20%20%20%20%20return%20state%3B%0A%7D%0A%20%2F%2F%20%E8%AE%BE%E7%BD%AE%E5%90%8C%E6%AD%A5%E7%8A%B6%E6%80%81%E7%9A%84%E5%80%BC%0Aprotected%20final%20void%20setState(int%20newState)%20%7B%20%0A%20%20%20%20%20%20%20%20state%20%3D%20newState%3B%0A%7D%0A%2F%2F%E5%8E%9F%E5%AD%90%E5%9C%B0%EF%BC%88CAS%E6%93%8D%E4%BD%9C%EF%BC%89%E5%B0%86%E5%90%8C%E6%AD%A5%E7%8A%B6%E6%80%81%E5%80%BC%E8%AE%BE%E7%BD%AE%E4%B8%BA%E7%BB%99%E5%AE%9A%E5%80%BCupdate%E5%A6%82%E6%9E%9C%E5%BD%93%E5%89%8D%E5%90%8C%E6%AD%A5%E7%8A%B6%E6%80%81%E7%9A%84%E5%80%BC%E7%AD%89%E4%BA%8Eexpect%EF%BC%88%E6%9C%9F%E6%9C%9B%E5%80%BC%EF%BC%89%0Aprotected%20final%20boolean%20compareAndSetState(int%20expect%2C%20int%20update)%20%7B%0A%20%20%20%20%20%20%20%20return%20unsafe.compareAndSwapInt(this%2C%20stateOffset%2C%20expect%2C%20update)%3B%0A%7D%0A%60%60%60%0A%0A%0A%23%23%23%23%202.2%20AQS%20%E5%AF%B9%E8%B5%84%E6%BA%90%E7%9A%84%E5%85%B1%E4%BA%AB%E6%96%B9%E5%BC%8F%0AAQS%E5%AE%9A%E4%B9%89%E4%B8%A4%E7%A7%8D%E8%B5%84%E6%BA%90%E5%85%B1%E4%BA%AB%E6%96%B9%E5%BC%8F%0A%0A*%20Exclusive%EF%BC%88%E7%8B%AC%E5%8D%A0%EF%BC%89%EF%BC%9A%E5%8F%AA%E6%9C%89%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%E8%83%BD%E6%89%A7%E8%A1%8C%EF%BC%8C%E5%A6%82ReentrantLock%E3%80%82%E5%8F%88%E5%8F%AF%E5%88%86%E4%B8%BA%E5%85%AC%E5%B9%B3%E9%94%81%E5%92%8C%E9%9D%9E%E5%85%AC%E5%B9%B3%E9%94%81%EF%BC%9A%0A%20%20%20%20*%20%E5%85%AC%E5%B9%B3%E9%94%81%EF%BC%9A%E6%8C%89%E7%85%A7%E7%BA%BF%E7%A8%8B%E5%9C%A8%E9%98%9F%E5%88%97%E4%B8%AD%E7%9A%84%E6%8E%92%E9%98%9F%E9%A1%BA%E5%BA%8F%EF%BC%8C%E5%85%88%E5%88%B0%E8%80%85%E5%85%88%E6%8B%BF%E5%88%B0%E9%94%81%0A%20%20%20%20*%20%E9%9D%9E%E5%85%AC%E5%B9%B3%E9%94%81%EF%BC%9A%E5%BD%93%E7%BA%BF%E7%A8%8B%E8%A6%81%E8%8E%B7%E5%8F%96%E9%94%81%E6%97%B6%EF%BC%8C%E6%97%A0%E8%A7%86%E9%98%9F%E5%88%97%E9%A1%BA%E5%BA%8F%E7%9B%B4%E6%8E%A5%E5%8E%BB%E6%8A%A2%E9%94%81%EF%BC%8C%E8%B0%81%E6%8A%A2%E5%88%B0%E5%B0%B1%E6%98%AF%E8%B0%81%E7%9A%84%0A*%20Share%EF%BC%88%E5%85%B1%E4%BA%AB%EF%BC%89%EF%BC%9A%E5%A4%9A%E4%B8%AA%E7%BA%BF%E7%A8%8B%E5%8F%AF%E5%90%8C%E6%97%B6%E6%89%A7%E8%A1%8C%EF%BC%8C%E5%A6%82Semaphore%2FCountDownLatch%E3%80%82Semaphore%E3%80%81CountDownLatCh%E3%80%81%20CyclicBarrier%E3%80%81ReadWriteLock%20%E6%88%91%E4%BB%AC%E9%83%BD%E4%BC%9A%E5%9C%A8%E5%90%8E%E9%9D%A2%E8%AE%B2%E5%88%B0%E3%80%82%0A%0AReentrantReadWriteLock%20%E5%8F%AF%E4%BB%A5%E7%9C%8B%E6%88%90%E6%98%AF%E7%BB%84%E5%90%88%E5%BC%8F%EF%BC%8C%E5%9B%A0%E4%B8%BAReentrantReadWriteLock%E4%B9%9F%E5%B0%B1%E6%98%AF%E8%AF%BB%E5%86%99%E9%94%81%E5%85%81%E8%AE%B8%E5%A4%9A%E4%B8%AA%E7%BA%BF%E7%A8%8B%E5%90%8C%E6%97%B6%E5%AF%B9%E6%9F%90%E4%B8%80%E8%B5%84%E6%BA%90%E8%BF%9B%E8%A1%8C%E8%AF%BB%E3%80%82%0A%0A%E4%B8%8D%E5%90%8C%E7%9A%84**%E8%87%AA%E5%AE%9A%E4%B9%89%E5%90%8C%E6%AD%A5%E5%99%A8**%E4%BA%89%E7%94%A8%E5%85%B1%E4%BA%AB%E8%B5%84%E6%BA%90%E7%9A%84%E6%96%B9%E5%BC%8F%E4%B9%9F%E4%B8%8D%E5%90%8C%E3%80%82%E8%87%AA%E5%AE%9A%E4%B9%89%E5%90%8C%E6%AD%A5%E5%99%A8%E5%9C%A8%E5%AE%9E%E7%8E%B0%E6%97%B6**%E5%8F%AA%E9%9C%80%E8%A6%81%E5%AE%9E%E7%8E%B0%E5%85%B1%E4%BA%AB%E8%B5%84%E6%BA%90%20state%20%E7%9A%84%E8%8E%B7%E5%8F%96%E4%B8%8E%E9%87%8A%E6%94%BE%E6%96%B9%E5%BC%8F%E5%8D%B3%E5%8F%AF**%EF%BC%8C%E8%87%B3%E4%BA%8E%E5%85%B7%E4%BD%93%E7%BA%BF%E7%A8%8B%E7%AD%89%E5%BE%85%E9%98%9F%E5%88%97%E7%9A%84%E7%BB%B4%E6%8A%A4%EF%BC%88%E5%A6%82%E8%8E%B7%E5%8F%96%E8%B5%84%E6%BA%90%E5%A4%B1%E8%B4%A5%E5%85%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B3%95%E7%9A%84%E6%8A%BD%E8%B1%A1%E7%B1%BB%EF%BC%8C%E7%84%B6%E5%90%8E%E7%94%A8%E6%88%B7%E6%A0%B9%E6%8D%AE%E8%87%AA%E5%B7%B1%E7%9A%84%E9%9C%80%E8%A6%81%E7%BB%A7%E6%89%BF%E8%AF%A5%E6%8A%BD%E8%B1%A1%E7%B1%BB%E7%84%B6%E5%90%8E%E4%BF%AE%E6%94%B9%20ride()%E6%96%B9%E6%B3%95%E3%80%82%0A%0AAQS%E4%BD%BF%E7%94%A8%E4%BA%86%E6%A8%A1%E6%9D%BF%E6%96%B9%E6%B3%95%E6%A8%A1%E5%BC%8F%EF%BC%8C%E8%87%AA%E5%AE%9A%E4%B9%89%E5%90%8C%E6%AD%A5%E5%99%A8%E6%97%B6%E9%9C%80%E8%A6%81%E9%87%8D%E5%86%99%E4%B8%8B%E9%9D%A2%E5%87%A0%E4%B8%AAAQS%E6%8F%90%E4%BE%9B%E7%9A%84%E6%A8%A1%E6%9D%BF%E6%96%B9%E6%B3%95%EF%BC%9A%0A%60%60%60java%0AisHeldExclusively()%2F%2F%E8%AF%A5%E7%BA%BF%E7%A8%8B%E6%98%AF%E5%90%A6%E6%AD%A3%E5%9C%A8%E7%8B%AC%E5%8D%A0%E8%B5%84%E6%BA%90%E3%80%82%E5%8F%AA%E6%9C%89%E7%94%A8%E5%88%B0condition%E6%89%8D%E9%9C%80%E8%A6%81%E5%8E%BB%E5%AE%9E%E7%8E%B0%E5%AE%83%E3%80%82%0A%0AtryAcquire(int)%2F%2F%E7%8B%AC%E5%8D%A0%E6%96%B9%E5%BC%8F%E3%80%82%E5%B0%9D%E8%AF%95%E8%8E%B7%E5%8F%96%E8%B5%84%E6%BA%90%EF%BC%8C%E6%88%90%E5%8A%9F%E5%88%99%E8%BF%94%E5%9B%9Etrue%EF%BC%8C%E5%A4%B1%E8%B4%A5%E5%88%99%E8%BF%94%E5%9B%9Efalse%E3%80%82%0A%0AtryRelease(int)%2F%2F%E7%8B%AC%E5%8D%A0%E6%96%B9%E5%BC%8F%E3%80%82%E5%B0%9D%E8%AF%95%E9%87%8A%E6%94%BE%E8%B5%84%E6%BA%90%EF%BC%8C%E6%88%90%E5%8A%9F%E5%88%99%E8%BF%94%E5%9B%9Etrue%EF%BC%8C%E5%A4%B1%E8%B4%A5%E5%88%99%E8%BF%94%E5%9B%9Efalse%E3%80%82%0A%0AtryAcquireShared(int)%2F%2F%E5%85%B1%E4%BA%AB%E6%96%B9%E5%BC%8F%E3%80%82%E5%B0%9D%E8%AF%95%E8%8E%B7%E5%8F%96%E8%B5%84%E6%BA%90%E3%80%82%E8%B4%9F%E6%95%B0%E8%A1%A8%E7%A4%BA%E5%A4%B1%E8%B4%A5%EF%BC%9B0%E8%A1%A8%E7%A4%BA%E6%88%90%E5%8A%9F%EF%BC%8C%E4%BD%86%E6%B2%A1%E6%9C%89%E5%89%A9%E4%BD%99%E5%8F%AF%E7%94%A8%E8%B5%84%E6%BA%90%EF%BC%9B%E6%AD%A3%E6%95%B0%E8%A1%A8%E7%A4%BA%E6%88%90%E5%8A%9F%EF%BC%8C%E4%B8%94%E6%9C%89%E5%89%A9%E4%BD%99%E8%B5%84%E6%BA%90%E3%80%82%0A%0AtryReleaseShared(int)%2F%2F%E5%85%B1%E4%BA%AB%E6%96%B9%E5%BC%8F%E3%80%82%E5%B0%9D%E8%AF%95%E9%87%8A%E6%94%BE%E8%B5%84%E6%BA%90%EF%BC%8C%E6%88%90%E5%8A%9F%E5%88%99%E8%BF%94%E5%9B%9Etrue%EF%BC%8C%E5%A4%B1%E8%B4%A5%E5%88%99%E8%BF%94%E5%9B%9Efalse%E3%80%82%0A%0A%60%60%60%0A%0A%E9%BB%98%E8%AE%A4%E6%83%85%E5%86%B5%E4%B8%8B%EF%BC%8C%E6%AF%8F%E4%B8%AA%E6%96%B9%E6%B3%95%E9%83%BD%E6%8A%9B%E5%87%BA%C2%A0UnsupportedOperationException%E3%80%82%20%E8%BF%99%E4%BA%9B%E6%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B0%60tryAcquire-tryRelease%60%E3%80%81%60tryAcquireShared-tryReleaseShared%60%E4%B8%AD%E7%9A%84%E4%B8%80%E7%A7%8D%E5%8D%B3%E5%8F%AF%E3%80%82%E4%BD%86AQS%E4%B9%9F%E6%94%AF%E6%8C%81%E8%87%AA%E5%AE%9A%E4%B9%89%E5%90%8C%E6%AD%A5%E5%99%A8%E5%90%8C%E6%97%B6%E5%AE%9E%E7%8E%B0%E7%8B%AC%E5%8D%A0%E5%92%8C%E5%85%B1%E4%BA%AB%E4%B8%A4%E7%A7%8D%E6%96%B9%E5%BC%8F%EF%BC%8C%E5%A6%82ReentrantReadWriteLock%E3%80%82%0A%0A%5BAQS%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90%5D(http%3A%2F%2Fwww.cnblogs.com%2Fwaterystone%2Fp%2F4920797.html)%0A%5BAQS%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90%5D(https%3A%2F%2Fwww.cnblogs.com%2Fchengxiao%2Farchive%2F2017%2F07%2F24%2F7141160.html)%0A%0A%23%23%23%203.%20Semaphore(%E4%BF%A1%E5%8F%B7%E9%87%8F)-%E5%85%81%E8%AE%B8%E5%A4%9A%E4%B8%AA%E7%BA%BF%E7%A8%8B%E5%90%8C%E6%97%B6%E8%AE%BF%E9%97%AE%0A**synchronized%20%E5%92%8C%20ReentrantLock%20%E9%83%BD%E6%98%AF%E4%B8%80%E6%AC%A1%E5%8F%AA%E5%85%81%E8%AE%B8%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%E8%AE%BF%E9%97%AE%E6%9F%90%E4%B8%AA%E8%B5%84%E6%BA%90%EF%BC%8CSemaphore(%E4%BF%A1%E5%8F%B7%E9%87%8F)%E5%8F%AF%E4%BB%A5%E6%8C%87%E5%AE%9A%E5%A4%9A%E4%B8%AA%E7%BA%BF%E7%A8%8B%E5%90%8C%E6%97%B6%E8%AE%BF%E9%97%AE%E6%9F%90%E4%B8%AA%E8%B5%84%E6%BA%90%E3%80%82**%0A%60%60%60java%0A%2F**%0A%20*%20%0A%20*%20%40author%20Snailclimb%0A%20*%20%40date%202018%E5%B9%B49%E6%9C%8830%E6%97%A5%0A%20*%20%40Description%3A%20%E9%9C%80%E8%A6%81%E4%B8%80%E6%AC%A1%E6%80%A7%E6%8B%BF%E4%B8%80%E4%B8%AA%E8%AE%B8%E5%8F%AF%E7%9A%84%E6%83%85%E5%86%B5%0A%20*%2F%0Apublic%20class%20SemaphoreExample1%20%7B%0A%09%2F%2F%20%E8%AF%B7%E6%B1%82%E7%9A%84%E6%95%B0%E9%87%8F%0A%09private%20static%20final%20int%20threadCount%20%3D%20550%3B%0A%0A%09public%20static%20void%20main(String%5B%5D%20args)%20throws%20InterruptedException%20%7B%0A%09%09%2F%2F%20%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E5%85%B7%E6%9C%89%E5%9B%BA%E5%AE%9A%E7%BA%BF%E7%A8%8B%E6%95%B0%E9%87%8F%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%B1%A0%E5%AF%B9%E8%B1%A1%EF%BC%88%E5%A6%82%E6%9E%9C%E8%BF%99%E9%87%8C%E7%BA%BF%E7%A8%8B%E6%B1%A0%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%95%B0%E9%87%8F%E7%BB%99%E5%A4%AA%E5%B0%91%E7%9A%84%E8%AF%9D%E4%BD%A0%E4%BC%9A%E5%8F%91%E7%8E%B0%E6%89%A7%E8%A1%8C%E7%9A%84%E5%BE%88%E6%85%A2%EF%BC%89%0A%09%09ExecutorService%20threadPool%20%3D%20Executors.newFixedThreadPool(300)%3B%0A%09%09%2F%2F%20%E4%B8%80%E6%AC%A1%E5%8F%AA%E8%83%BD%E5%85%81%E8%AE%B8%E6%89%A7%E8%A1%8C%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%95%B0%E9%87%8F%E3%80%82%0A%09%09final%20Semaphore%20semaphore%20%3D%20new%20Semaphore(20)%3B%0A%0A%09%09for%20(int%20i%20%3D%200%3B%20i%20%3C%20threadCount%3B%20i%2B%2B)%20%7B%0A%09%09%09final%20int%20threadnum%20%3D%20i%3B%0A%09%09%09threadPool.execute(()%20-%3E%20%7B%2F%2F%20Lambda%20%E8%A1%A8%E8%BE%BE%E5%BC%8F%E7%9A%84%E8%BF%90%E7%94%A8%0A%09%09%09%09try%20%7B%0A%09%09%09%09%09semaphore.acquire()%3B%2F%2F%20%E8%8E%B7%E5%8F%96%E4%B8%80%E4%B8%AA%E8%AE%B8%E5%8F%AF%EF%BC%8C%E6%89%80%E4%BB%A5%E5%8F%AF%E8%BF%90%E8%A1%8C%E7%BA%BF%E7%A8%8B%E6%95%B0%E9%87%8F%E4%B8%BA20%2F1%3D20%0A%09%09%09%09%09test(threadnum)%3B%0A%09%09%09%09%09semaphore.release()%3B%2F%2F%20%E9%87%8A%E6%94%BE%E4%B8%80%E4%B8%AA%E8%AE%B8%E5%8F%AF%0A%09%09%09%09%7D%20catch%20(InterruptedException%20e)%20%7B%0A%09%09%09%09%09%2F%2F%20TODO%20Auto-generated%20catch%20block%0A%09%09%09%09%09e.printStackTrace()%3B%0A%09%09%09%09%7D%0A%0A%09%09%09%7D)%3B%0A%09%09%7D%0A%09%09threadPool.shutdown()%3B%0A%09%09System.out.println(%22finish%22)%3B%0A%09%7D%0A%0A%09public%20static%20void%20test(int%20threadnum)%20throws%20InterruptedException%20%7B%0A%09%09Thread.sleep(1000)%3B%2F%2F%20%E6%A8%A1%E6%8B%9F%E8%AF%B7%E6%B1%82%E7%9A%84%E8%80%97%E6%97%B6%E6%93%8D%E4%BD%9C%0A%09%09System.out.println(%22threadnum%3A%22%20%2B%20threadnum)%3B%0A%09%09Thread.sleep(1000)%3B%2F%2F%20%E6%A8%A1%E6%8B%9F%E8%AF%B7%E6%B1%82%E7%9A%84%E8%80%97%E6%97%B6%E6%93%8D%E4%BD%9C%0A%09%7D%0A%7D%0A%60%60%60%0A%E6%89%A7%E8%A1%8C%20acquire%20%E6%96%B9%E6%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%A7%E8%A1%8C%E3%80%82%E7%B1%BB%E4%BC%BC%E4%BA%8E%E8%B5%9B%E8%B7%91%EF%BC%8C%E5%B0%86%E5%A4%9A%E4%B8%AA%E7%BA%BF%E7%A8%8B%E6%94%BE%E5%88%B0%E8%B5%B7%E7%82%B9%EF%BC%8C%E7%AD%89%E5%BE%85%E5%8F%91%E4%BB%A4%E6%9E%AA%E5%93%8D%EF%BC%8C%E7%84%B6%E5%90%8E%E5%90%8C%E6%97%B6%E5%BC%80%E8%B7%91%E3%80%82%E5%81%9A%E6%B3%95%E6%98%AF%E5%88%9D%E5%A7%8B%E5%8C%96%E4%B8%80%E4%B8%AA%E5%85%B1%E4%BA%AB%E7%9A%84%20CountDownLatch%20%E5%AF%B9%E8%B1%A1%EF%BC%8C%E5%B0%86%E5%85%B6%E8%AE%A1%E6%95%B0%E5%99%A8%E5%88%9D%E5%A7%8B%E5%8C%96%E4%B8%BA%201%20%EF%BC%9A%60new%20CountDownLatch(1)%60%EF%BC%8C%E5%A4%9A%E4%B8%AA%E7%BA%BF%E7%A8%8B%E5%9C%A8%E5%BC%80%E5%A7%8B%E6%89%A7%E8%A1%8C%E4%BB%BB%E5%8A%A1%E5%89%8D%E9%A6%96%E5%85%88%20%60coundownlatch.await()%60%EF%BC%8C%E5%BD%93%E4%B8%BB%E7%BA%BF%E7%A8%8B%E8%B0%83%E7%94%A8%20countDown()%20%E6%97%B6%EF%BC%8C%E8%AE%A1%E6%95%B0%E5%99%A8%E5%8F%98%E4%B8%BA0%EF%BC%8C%E5%A4%9A%E4%B8%AA%E7%BA%BF%E7%A8%8B%E5%90%8C%E6%97%B6%E8%A2%AB%E5%94%A4%E9%86%92%E3%80%82%0A%0A%0A%23%23%23%23%204.2%20CountDownLatch%20%E7%9A%84%E4%BD%BF%E7%94%A8%E7%A4%BA%E4%BE%8B%0A%60%60%60java%0A%2F**%0A%20*%20%0A%20*%20%40author%20SnailClimb%0A%20*%20%40date%202018%E5%B9%B410%E6%9C%881%E6%97%A5%0A%20*%20%40Description%3A%20CountDownLatch%20%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95%E7%A4%BA%E4%BE%8B%0A%20*%2F%0Apublic%20class%20CountDownLatchExample1%20%7B%0A%09%2F%2F%20%E8%AF%B7%E6%B1%82%E7%9A%84%E6%95%B0%E9%87%8F%0A%09private%20static%20final%20int%20threadCount%20%3D%20550%3B%0A%0A%09public%20static%20void%20main(String%5B%5D%20args)%20throws%20InterruptedException%20%7B%0A%09%09%2F%2F%20%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E5%85%B7%E6%9C%89%E5%9B%BA%E5%AE%9A%E7%BA%BF%E7%A8%8B%E6%95%B0%E9%87%8F%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%B1%A0%E5%AF%B9%E8%B1%A1%EF%BC%88%E5%A6%82%E6%9E%9C%E8%BF%99%E9%87%8C%E7%BA%BF%E7%A8%8B%E6%B1%A0%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%95%B0%E9%87%8F%E7%BB%99%E5%A4%AA%E5%B0%91%E7%9A%84%E8%AF%9D%E4%BD%A0%E4%BC%9A%E5%8F%91%E7%8E%B0%E6%89%A7%E8%A1%8C%E7%9A%84%E5%BE%88%E6%85%A2%EF%BC%89%0A%09%09ExecutorService%20threadPool%20%3D%20Executors.newFixedThreadPool(300)%3B%0A%09%09final%20CountDownLatch%20countDownLatch%20%3D%20new%20CountDownLatch(threadCount)%3B%0A%09%09for%20(int%20i%20%3D%200%3B%20i%20%3C%20threadCount%3B%20i%2B%2B)%20%7B%0A%09%09%09final%20int%20threadnum%20%3D%20i%3B%0A%09%09%09threadPool.execute(()%20-%3E%20%7B%2F%2F%20Lambda%20%E8%A1%A8%E8%BE%BE%E5%BC%8F%E7%9A%84%E8%BF%90%E7%94%A8%0A%09%09%09%09try%20%7B%0A%09%09%09%09%09test(threadnum)%3B%0A%09%09%09%09%7D%20catch%20(InterruptedException%20e)%20%7B%0A%09%09%09%09%09%2F%2F%20TODO%20Auto-generated%20catch%20block%0A%09%09%09%09%09e.printStackTrace()%3B%0A%09%09%09%09%7D%20finally%20%7B%0A%09%09%09%09%09countDownLatch.countDown()%3B%2F%2F%20%E8%A1%A8%E7%A4%BA%E4%B8%80%E4%B8%AA%E8%AF%B7%E6%B1%82%E5%B7%B2%E7%BB%8F%E8%A2%AB%E5%AE%8C%E6%88%90%0A%09%09%09%09%7D%0A%0A%09%09%09%7D)%3B%0A%09%09%7D%0A%09%09countDownLatch.await()%3B%0A%09%09threadPool.shutdown()%3B%0A%09%09System.out.println(%22finish%22)%3B%0A%09%7D%0A%0A%09public%20static%20void%20test(int%20threadnum)%20throws%20InterruptedException%20%7B%0A%09%09Thread.sleep(1000)%3B%2F%2F%20%E6%A8%A1%E6%8B%9F%E8%AF%B7%E6%B1%82%E7%9A%84%E8%80%97%E6%97%B6%E6%93%8D%E4%BD%9C%0A%09%09System.out.println(%22threadnum%3A%22%20%2B%20threadnum)%3B%0A%09%09Thread.sleep(1000)%3B%2F%2F%20%E6%A8%A1%E6%8B%9F%E8%AF%B7%E6%B1%82%E7%9A%84%E8%80%97%E6%97%B6%E6%93%8D%E4%BD%9C%0A%09%7D%0A%7D%0A%60%60%60%0A%0A%23%23%23%23%204.3%20CountDownLatch%20%E7%9A%84%E4%B8%8D%E8%B6%B3%0ACountDownLatch%E6%98%AF%E4%B8%80%E6%AC%A1%E6%80%A7%E7%9A%84%EF%BC%8C%E8%AE%A1%E6%95%B0%E5%99%A8%E7%9A%84%E5%80%BC%E5%8F%AA%E8%83%BD%E5%9C%A8%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95%E4%B8%AD%E5%88%9D%E5%A7%8B%E5%8C%96%E4%B8%80%E6%AC%A1%EF%BC%8C%E4%B9%8B%E5%90%8E%E6%B2%A1%E6%9C%89%E4%BB%BB%E4%BD%95%E6%9C%BA%E5%88%B6%E5%86%8D%E6%AC%A1%E5%AF%B9%E5%85%B6%E8%AE%BE%E7%BD%AE%E5%80%BC%EF%BC%8C%E5%BD%93CountDownLatch%E4%BD%BF%E7%94%A8%E5%AE%8C%E6%AF%95%E5%90%8E%EF%BC%8C%E5%AE%83%E4%B8%8D%E8%83%BD%E5%86%8D%E6%AC%A1%E8%A2%AB%E4%BD%BF%E7%94%A8%E3%80%82%0A%0A%23%23%23%205.%20CyclicBarrier(%E5%BE%AA%E7%8E%AF%E6%A0%85%E6%A0%8F)%0ACyclicBarrier%20%E5%92%8C%20CountDownLatch%20%E9%9D%9E%E5%B8%B8%E7%B1%BB%E4%BC%BC%EF%BC%8C%E5%AE%83%E4%B9%9F%E5%8F%AF%E4%BB%A5%E5%AE%9E%E7%8E%B0%E7%BA%BF%E7%A8%8B%E9%97%B4%E7%9A%84%E6%8A%80%E6%9C%AF%E7%AD%89%E5%BE%85%EF%BC%8C%E4%BD%86%E6%98%AF%E5%AE%83%E7%9A%84%E5%8A%9F%E8%83%BD%E6%AF%94%20CountDownLatch%20%E6%9B%B4%E5%8A%A0%E5%A4%8D%E6%9D%82%E5%92%8C%E5%BC%BA%E5%A4%A7%E3%80%82%E4%B8%BB%E8%A6%81%E5%BA%94%E7%94%A8%E5%9C%BA%E6%99%AF%E5%92%8C%20CountDownLatch%20%E7%B1%BB%E4%BC%BC%E3%80%82%0A%0ACyclicBarrier%20%E7%9A%84%E5%AD%97%E9%9D%A2%E6%84%8F%E6%80%9D%E6%98%AF%E5%8F%AF%E5%BE%AA%E7%8E%AF%E4%BD%BF%E7%94%A8%EF%BC%88Cyclic%EF%BC%89%E7%9A%84%E5%B1%8F%E9%9A%9C%EF%BC%88Barrier%EF%BC%89%E3%80%82%E5%AE%83%E8%A6%81%E5%81%9A%E7%9A%84%E4%BA%8B%E6%83%85%E6%98%AF%EF%BC%8C%E8%AE%A9%E4%B8%80%E7%BB%84%E7%BA%BF%E7%A8%8B%E5%88%B0%E8%BE%BE%E4%B8%80%E4%B8%AA%E5%B1%8F%E9%9A%9C%EF%BC%88%E4%B9%9F%E5%8F%AF%E4%BB%A5%E5%8F%AB%E5%90%8C%E6%AD%A5%E7%82%B9%EF%BC%89%E6%97%B6%E8%A2%AB%E9%98%BB%E5%A1%9E%EF%BC%8C%E7%9B%B4%E5%88%B0%E6%9C%80%E5%90%8E%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%E5%88%B0%E8%BE%BE%E5%B1%8F%E9%9A%9C%E6%97%B6%EF%BC%8C%E5%B1%8F%E9%9A%9C%E6%89%8D%E4%BC%9A%E5%BC%80%E9%97%A8%EF%BC%8C%E6%89%80%E6%9C%89%E8%A2%AB%E5%B1%8F%E9%9A%9C%E6%8B%A6%E6%88%AA%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%89%8D%E4%BC%9A%E7%BB%A7%E7%BB%AD%E5%B9%B2%E6%B4%BB%E3%80%82CyclicBarrier%E9%BB%98%E8%AE%A4%E7%9A%84%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95%E6%98%AF%20CyclicBarrier(int%20parties)%EF%BC%8C%E5%85%B6%E5%8F%82%E6%95%B0%E8%A1%A8%E7%A4%BA%E5%B1%8F%E9%9A%9C%E6%8B%A6%E6%88%AA%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%95%B0%E9%87%8F%EF%BC%8C%E6%AF%8F%E4%B8%AA%E7%BA%BF%E7%A8%8B%E8%B0%83%E7%94%A8await%E6%96%B9%E6%B3%95%E5%91%8A%E8%AF%89%20CyclicBarrier%20%E6%88%91%E5%B7%B2%E7%BB%8F%E5%88%B0%E8%BE%BE%E4%BA%86%E5%B1%8F%E9%9A%9C%EF%BC%8C%E7%84%B6%E5%90%8E%E5%BD%93%E5%89%8D%E7%BA%BF%E7%A8%8B%E8%A2%AB%E9%98%BB%E5%A1%9E%E3%80%82%0A%0A%23%23%23%23%205.1%20CyclicBarrier%20%E7%9A%84%E5%BA%94%E7%94%A8%E5%9C%BA%E6%99%AF%0ACyclicBarrier%20%E5%8F%AF%E4%BB%A5%E7%94%A8%E4%BA%8E%E5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8%8B%E7%9A%84%E8%AE%A1%E7%AE%97%E7%BB%93%E6%9E%9C%EF%BC%8C%E8%AE%A1%E7%AE%97%E5%87%BA%E6%95%B4%E4%B8%AAExcel%E7%9A%84%E6%97%A5%E5%9D%87%E9%93%B6%E8%A1%8C%E6%B5%81%E6%B0%B4%E3%80%82%0A%0A%23%23%23%23%205.2%20CyclicBarrier%20%E7%9A%84%E4%BD%BF%E7%94%A8%E7%A4%BA%E4%BE%8B%0A%60%60%60java%0A%2F**%0A%20*%20%0A%20*%20%40author%20Snailclimb%0A%20*%20%40date%202018%E5%B9%B410%E6%9C%881%E6%97%A5%0A%20*%20%40Description%3A%20%E6%B5%8B%E8%AF%95%20CyclicBarrier%20%E7%B1%BB%E4%B8%AD%E5%B8%A6%E5%8F%82%E6%95%B0%E7%9A%84%20await()%20%E6%96%B9%E6%B3%95%0A%20*%2F%0Apublic%20class%20CyclicBarrierExample2%20%7B%0A%09%2F%2F%20%E8%AF%B7%E6%B1%82%E7%9A%84%E6%95%B0%E9%87%8F%0A%09private%20static%20final%20int%20threadCount%20%3D%20550%3B%0A%09%2F%2F%20%E9%9C%80%E8%A6%81%E5%90%8C%E6%AD%A5%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%95%B0%E9%87%8F%0A%09private%20static%20final%20CyclicBarrier%20cyclicBarrier%20%3D%20new%20CyclicBarrier(5)%3B%0A%0A%09public%20static%20void%20main(String%5B%5D%20args)%20throws%20InterruptedException%20%7B%0A%09%09%2F%2F%20%E5%88%9B%E5%BB%BA%E7%BA%BF%E7%A8%8B%E6%B1%A0%0A%09%09ExecutorService%20threadPool%20%3D%20Executors.newFixedThreadPool(10)%3B%0A%0A%09%09for%20(int%20i%20%3D%200%3B%20i%20%3C%20threadCount%3B%20i%2B%2B)%20%7B%0A%09%09%09final%20int%20threadNum%20%3D%20i%3B%0A%09%09%09Thread.sleep(1000)%3B%0A%09%09%09threadPool.execute(()%20-%3E%20%7B%0A%09%09%09%09try%20%7B%0A%09%09%09%09%09test(threadNum)%3B%0A%09%09%09%09%7D%20catch%20(InterruptedException%20e)%20%7B%0A%09%09%09%09%09%2F%2F%20TODO%20Auto-generated%20catch%20block%0A%09%09%09%09%09e.printStackTrace()%3B%0A%09%09%09%09%7D%20catch%20(BrokenBarrierException%20e)%20%7B%0A%09%09%09%09%09%2F%2F%20TODO%20Auto-generated%20catch%20block%0A%09%09%09%09%09e.printStackTrace()%3B%0A%09%09%09%09%7D%0A%09%09%09%7D)%3B%0A%09%09%7D%0A%09%09threadPool.shutdown()%3B%0A%09%7D%0A%0A%09public%20static%20void%20test(int%20threadnum)%20throws%20InterruptedException%2C%20BrokenBarrierException%20%7B%0A%09%09System.out.println(%22threadnum%3A%22%20%2B%20threadnum%20%2B%20%22is%20ready%22)%3B%0A%09%09try%20%7B%0A%09%09%09cyclicBarrier.await(2000%2C%20TimeUnit.MILLISECONDS)%3B%0A%09%09%7D%20catch%20(Exception%20e)%20%7B%0A%09%09%09System.out.println(%22-----CyclicBarrierException------%22)%3B%0A%09%09%7D%0A%09%09System.out.println(%22threadnum%3A%22%20%2B%20threadnum%20%2B%20%22is%20finish%22)%3B%0A%09%7D%0A%0A%7D%0A%60%60%60%0A%0A%0A%23%23%23%23%205.3%20CyclicBarrier%E5%92%8CCountDownLatch%E7%9A%84%E5%8C%BA%E5%88%AB%0A%3E%E5%AF%B9%E4%BA%8ECountDownLatch%E6%9D%A5%E8%AF%B4%EF%BC%8C%E9%87%8D%E7%82%B9%E6%98%AF%E2%80%9C%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%EF%BC%88%E5%A4%9A%E4%B8%AA%E7%BA%BF%E7%A8%8B%EF%BC%89%E7%AD%89%E5%BE%85%E2%80%9D%EF%BC%8C%E8%80%8C%E5%85%B6%E4%BB%96%E7%9A%84N%E4%B8%AA%E7%BA%BF%E7%A8%8B%E5%9C%A8%E5%AE%8C%E6%88%90%E2%80%9C%E6%9F%90%E4%BB%B6%E4%BA%8B%E6%83%85%E2%80%9D%E4%B9%8B%E5%90%8E%EF%BC%8C%E5%8F%AF%E4%BB%A5%E7%BB%88%E6%AD%A2%EF%BC%8C%E4%B9%9F%E5%8F%AF%E4%BB%A5%E7%AD%89%E5%BE%85%E3%80%82%0A%E8%80%8C%E5%AF%B9%E4%BA%8ECyclicBarrier%EF%BC%8C%E9%87%8D%E7%82%B9%E6%98%AF%E5%A4%9A%E4%B8%AA%E7%BA%BF%E7%A8%8B%EF%BC%8C%E5%9C%A8**%E4%BB%BB%E6%84%8F%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%E6%B2%A1%E6%9C%89%E5%AE%8C%E6%88%90%EF%BC%8C%E6%89%80%E6%9C%89%E7%9A%84%E7%BA%BF%E7%A8%8B%E9%83%BD%E5%BF%85%E9%A1%BB%E7%AD%89%E5%BE%85**%E3%80%82%0A%0A%3ECountDownLatch%E6%98%AF%E8%AE%A1%E6%95%B0%E5%99%A8%EF%BC%8C%E7%BA%BF%E7%A8%8B%E5%AE%8C%E6%88%90%E4%B8%80%E4%B8%AA%E8%AE%B0%E5%BD%95%E4%B8%80%E4%B8%AA%EF%BC%8C%E5%8F%AA%E4%B8%8D%E8%BF%87%E8%AE%A1%E6%95%B0%E4%B8%8D%E6%98%AF%E9%80%92%E5%A2%9E%E8%80%8C%E6%98%AF%E9%80%92%E5%87%8F%EF%BC%8C%0A%E8%80%8CCyclicBarrier%E6%9B%B4%E5%83%8F%E6%98%AF%E4%B8%80%E4%B8%AA%E9%98%80%E9%97%A8%EF%BC%8C%E9%9C%80%E8%A6%81%E6%89%80%E6%9C%89%E7%BA%BF%E7%A8%8B%E9%83%BD%E5%88%B0%E8%BE%BE%EF%BC%8C%E9%98%80%E9%97%A8%E6%89%8D%E8%83%BD%E6%89%93%E5%BC%80%EF%BC%8C%E7%84%B6%E5%90%8E%E7%BB%A7%E7%BB%AD%E6%89%A7%E8%A1%8C%E3%80%82%0A&lt;/center&gt;&lt;/div&gt;
</content>
  </entry>
  <entry xml:base="http://linzhiteng.postach.io/feed.xml">
    <title type="text">七. JUC 中的 Atomic 原子类总结</title>
    <id>https://linzhiteng.postach.io/post/qi-juc-zhong-de-atomic-yuan-zi-lei-zong-jie</id>
    <updated>2019-06-09T13:07:37.105000Z</updated>
    <published>2019-03-13T09:49:10Z</published>
    <link href="https://linzhiteng.postach.io/post/qi-juc-zhong-de-atomic-yuan-zi-lei-zong-jie" />
    <author>
      <name>linzhi teng</name>
    </author>
    <category term="xian-cheng" />
    <content type="html">&lt;div&gt;&lt;div style=&quot;font-size: 14px; margin: 0; padding: 0; width: 100%;&quot;&gt;&lt;div style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;七. JUC 中的 Atomic 原子类总结
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1. Atomic 原子类介绍
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.1 原子类类型
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;基本类型
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;数组类型
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;引用类型
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;对象的属性修改类型
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2. 基本类型原子类
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.1 基本类型原子类介绍
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.2 AtomicInteger 常见方法使用
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.3 基本数据类型原子类的优势
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.4 AtomicInteger 线程安全原理简单分析
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3. 数组类型原子类
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1 数组类型原子类介绍
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.2 AtomicIntegerArray 常见方法使用
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4. 引用类型原子类
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.1 引用类型原子类介绍
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.2 AtomicReference 类使用示例
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;5. 对象的属性修改类型原子类
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;5.1 对象的属性修改类型原子类介绍
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;5.2 AtomicIntegerFieldUpdater 类使用示例
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;七. JUC 中的 Atomic 原子类总结&lt;/h2&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/8c6ce7bf-9cf7-4151-b61b-40e09574af44/5e677e9b-8b27-4a65-8e68-451fe6c3c458.jpg&quot; /&gt;&lt;/p&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;1. Atomic 原子类介绍&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;Atomic 翻译成中文是原子的意思。在化学上，我们知道原子是构成一般物质的最小单位，在化学反应中是不可分割的。在我们这里 Atomic 是指一个操作是不可中断的。即使是在多个线程一起执行的时候，一个操作一旦开始，就不会被其他线程干扰。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;所以，所谓原子类说简单点就是具有原子/原子操作特征的类。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;并发包  &lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;java.util.concurrent&lt;/code&gt;  的原子类都存放在 &lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;java.util.concurrent.atomic&lt;/code&gt; 下&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.1 原子类类型&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;根据操作的数据类型，可以将JUC包中的原子类分为4类&lt;/p&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;基本类型&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0;&quot;&gt;使用原子的方式更新基本类型&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;AtomicInteger：整形原子类&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;AtomicLong：长整型原子类&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;AtomicBoolean ：布尔型原子类&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;数组类型&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0;&quot;&gt;使用原子的方式更新数组里的某个元素&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;AtomicIntegerArray：整形数组原子类&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;AtomicLongArray：长整形数组原子类&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;AtomicReferenceArray ：引用类型数组原子类&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;引用类型&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0;&quot;&gt;AtomicReference：引用类型原子类&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;AtomicStampedRerence：原子更新引用类型里的字段原子类&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;AtomicMarkableReference ：原子更新带有标记位的引用类型&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;对象的属性修改类型&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;AtomicIntegerFieldUpdater:原子更新整形字段的更新器&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;AtomicLongFieldUpdater：原子更新长整形字段的更新器&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;AtomicStampedReference ：原子更新带有版本号的引用类型。该类将整数值与引用关联起来，可用于解决原子的更新数据和数据的版本号，可以解决使用 CAS 进行原子更新时可能出现的 ABA 问题。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;2. 基本类型原子类&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.1 基本类型原子类介绍&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;使用原子的方式更新基本类型&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;AtomicInteger：整形原子类&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;AtomicLong：长整型原子类&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;AtomicBoolean ：布尔型原子类&lt;/li&gt;
&lt;/ul&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;上面三个类提供的方法几乎相同，所以我们这里以 AtomicInteger 为例子来介绍。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;AtomicInteger 类常用方法&lt;/p&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;final&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;()&lt;/span&gt; &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//获取当前的值&lt;/span&gt;

&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;final&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;getAndSet&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; newValue)&lt;/span&gt;&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//获取当前的值，并设置新的值&lt;/span&gt;

&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;final&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;getAndIncrement&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//获取当前的值，并自增&lt;/span&gt;

&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;final&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;getAndDecrement&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;()&lt;/span&gt; &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//获取当前的值，并自减&lt;/span&gt;

&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;final&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;getAndAdd&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; delta)&lt;/span&gt; &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//获取当前的值，并加上预期的值&lt;/span&gt;

&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;boolean&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;compareAndSet&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; expect, &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; update)&lt;/span&gt; &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//如果输入的数值等于预期值，则以原子方式将该值设置为输入值（update）&lt;/span&gt;

&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;final&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;lazySet&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; newValue)&lt;/span&gt;&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//最终设置为newValue,使用 lazySet 设置之后可能导致其他线程在之后的一小段时间内还是可以读到旧的值。&lt;/span&gt;

&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.2 AtomicInteger 常见方法使用&lt;/h4&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;import&lt;/span&gt; java.util.concurrent.atomic.AtomicInteger;

&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;AtomicIntegerTest&lt;/span&gt; &lt;/span&gt;{

	&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;main&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(String[] args)&lt;/span&gt; &lt;/span&gt;{
		&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;// TODO Auto-generated method stub&lt;/span&gt;
		&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; temvalue = &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0&lt;/span&gt;;
		AtomicInteger i = &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; AtomicInteger(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0&lt;/span&gt;);
		temvalue = i.getAndSet(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;3&lt;/span&gt;);
		System.out.println(&lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;temvalue:&quot;&lt;/span&gt; + temvalue + &lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;;  i:&quot;&lt;/span&gt; + i);&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//temvalue:0;  i:3&lt;/span&gt;
		temvalue = i.getAndIncrement();
		System.out.println(&lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;temvalue:&quot;&lt;/span&gt; + temvalue + &lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;;  i:&quot;&lt;/span&gt; + i);&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//temvalue:3;  i:4&lt;/span&gt;
		temvalue = i.getAndAdd(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;5&lt;/span&gt;);
		System.out.println(&lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;temvalue:&quot;&lt;/span&gt; + temvalue + &lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;;  i:&quot;&lt;/span&gt; + i);&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//temvalue:4;  i:9&lt;/span&gt;
	}

}
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.3 基本数据类型原子类的优势&lt;/h4&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;多线程环境不使用原子类保证线程安全（基本数据类型）&lt;/li&gt;
&lt;/ol&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;Test&lt;/span&gt; &lt;/span&gt;{
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;volatile&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; count = &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0&lt;/span&gt;;
        &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//若要线程安全执行执行count++，需要加锁&lt;/span&gt;
        &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;synchronized&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;increment&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{
                  count++; 
        }

        &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;getCount&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{
                  &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt; count;
        }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;ol start=&quot;2&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;多线程环境使用原子类保证线程安全（基本数据类型）&lt;/li&gt;
&lt;/ol&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;Test2&lt;/span&gt; &lt;/span&gt;{
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;private&lt;/span&gt; AtomicInteger count = &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; AtomicInteger();

        &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;increment&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{
                  count.incrementAndGet();
        }
      &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//使用AtomicInteger之后，不需要加锁，也可以实现线程安全。&lt;/span&gt;
       &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;getCount&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{
                &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt; count.get();
        }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.4 AtomicInteger 线程安全原理简单分析&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;AtomicInteger 类的部分源码：&lt;/p&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;    &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;// setup to use Unsafe.compareAndSwapInt for updates（更新操作时提供&quot;比较并替换&quot;的作用）&lt;/span&gt;
    &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;final&lt;/span&gt; Unsafe unsafe = Unsafe.getUnsafe();
    &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;final&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;long&lt;/span&gt; valueOffset;

    &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;static&lt;/span&gt; {
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;try&lt;/span&gt; {
            valueOffset = unsafe.objectFieldOffset
                (AtomicInteger.class.getDeclaredField(&lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;value&quot;&lt;/span&gt;));
        } &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;catch&lt;/span&gt; (Exception ex) { &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;throw&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; Error(ex); }
    }

    &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;volatile&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; value;
&lt;/code&gt;&lt;/pre&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;AtomicInteger 类主要利用 CAS (compare and swap) + volatile 和 native 方法来保证原子操作，从而避免 synchronized 的高开销，执行效率大为提升。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;CAS的原理是拿期望的值和原本的一个值作比较，如果相同则更新成新的值。UnSafe 类的 objectFieldOffset() 方法是一个本地方法，这个方法是用来拿到&quot;原来的值&quot;的内存地址，返回值是 valueOffset。另外 value 是一个volatile变量，在内存中可见，因此 JVM 可以保证任何时刻任何线程总能拿到该变量的最新值。&lt;/p&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;3. 数组类型原子类&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.1 数组类型原子类介绍&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;使用原子的方式更新数组里的某个元素&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;AtomicIntegerArray：整形数组原子类&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;AtomicLongArray：长整形数组原子类&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;AtomicReferenceArray ：引用类型数组原子类&lt;/li&gt;
&lt;/ul&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;上面三个类提供的方法几乎相同，所以我们这里以 AtomicIntegerArray 为例子来介绍。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;AtomicIntegerArray 类常用方法&lt;/p&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;final&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; i)&lt;/span&gt; &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//获取 index=i 位置元素的值&lt;/span&gt;

&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;final&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;getAndSet&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; i, &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; newValue)&lt;/span&gt;&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//返回 index=i 位置的当前的值，并将其设置为新值：newValue&lt;/span&gt;

&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;final&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;getAndIncrement&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; i)&lt;/span&gt;&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//获取 index=i 位置元素的值，并让该位置的元素自增&lt;/span&gt;

&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;final&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;getAndDecrement&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; i)&lt;/span&gt; &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//获取 index=i 位置元素的值，并让该位置的元素自减&lt;/span&gt;

&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;final&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;getAndAdd&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; delta)&lt;/span&gt; &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//获取 index=i 位置元素的值，并加上预期的值&lt;/span&gt;

&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;boolean&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;compareAndSet&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; expect, &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; update)&lt;/span&gt; &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//如果输入的数值等于预期值，则以原子方式将 index=i 位置的元素值设置为输入值（update）&lt;/span&gt;

&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;final&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;lazySet&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; i, &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; newValue)&lt;/span&gt;&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//最终 将index=i 位置的元素设置为newValue,使用 lazySet 设置之后可能导致其他线程在之后的一小段时间内还是可以读到旧的值。&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.2 AtomicIntegerArray 常见方法使用&lt;/h4&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;
&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;import&lt;/span&gt; java.util.concurrent.atomic.AtomicIntegerArray;

&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;AtomicIntegerArrayTest&lt;/span&gt; &lt;/span&gt;{

	&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;main&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(String[] args)&lt;/span&gt; &lt;/span&gt;{
		&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;// TODO Auto-generated method stub&lt;/span&gt;
		&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; temvalue = &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0&lt;/span&gt;;
		&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt;[] nums = { &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;2&lt;/span&gt;, &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;3&lt;/span&gt;, &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;4&lt;/span&gt;, &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;5&lt;/span&gt;, &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;6&lt;/span&gt; };
		AtomicIntegerArray i = &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; AtomicIntegerArray(nums);
		&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; j = &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0&lt;/span&gt;; j &lt; nums.length; j++) {
			System.out.println(i.get(j));
		}
		temvalue = i.getAndSet(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;2&lt;/span&gt;);
		System.out.println(&lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;temvalue:&quot;&lt;/span&gt; + temvalue + &lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;;  i:&quot;&lt;/span&gt; + i);
		temvalue = i.getAndIncrement(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0&lt;/span&gt;);
		System.out.println(&lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;temvalue:&quot;&lt;/span&gt; + temvalue + &lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;;  i:&quot;&lt;/span&gt; + i);
		temvalue = i.getAndAdd(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;5&lt;/span&gt;);
		System.out.println(&lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;temvalue:&quot;&lt;/span&gt; + temvalue + &lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;;  i:&quot;&lt;/span&gt; + i);
	}

}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;4. 引用类型原子类&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;4.1 引用类型原子类介绍&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;基本类型原子类只能更新一个变量，如果需要原子更新多个变量，需要使用 引用类型原子类。&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;AtomicReference：引用类型原子类&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;AtomicStampedRerence：原子更新引用类型里的字段原子类&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;AtomicMarkableReference ：原子更新带有标记位的引用类型&lt;/li&gt;
&lt;/ul&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;上面三个类提供的方法几乎相同，所以我们这里以 AtomicReference 为例子来介绍。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;4.2 AtomicReference 类使用示例&lt;/h4&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;import&lt;/span&gt; java.util.concurrent.atomic.AtomicReference;

&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;AtomicReferenceTest&lt;/span&gt; &lt;/span&gt;{

	&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;main&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(String[] args)&lt;/span&gt; &lt;/span&gt;{
		AtomicReference&lt;Person&gt; ar = &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; AtomicReference&lt;Person&gt;();
		Person person = &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; Person(&lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;SnailClimb&quot;&lt;/span&gt;, &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;22&lt;/span&gt;);
		ar.set(person);
		Person updatePerson = &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; Person(&lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;Daisy&quot;&lt;/span&gt;, &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;20&lt;/span&gt;);
		ar.compareAndSet(person, updatePerson);

		System.out.println(ar.get().getName());
		System.out.println(ar.get().getAge());
	}
}

&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;Person&lt;/span&gt; &lt;/span&gt;{
	&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;private&lt;/span&gt; String name;
	&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; age;

	&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;Person&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(String name, &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; age)&lt;/span&gt; &lt;/span&gt;{
		&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;super&lt;/span&gt;();
		&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;this&lt;/span&gt;.name = name;
		&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;this&lt;/span&gt;.age = age;
	}

	&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; String &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;getName&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{
		&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt; name;
	}

	&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;setName&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(String name)&lt;/span&gt; &lt;/span&gt;{
		&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;this&lt;/span&gt;.name = name;
	}

	&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;getAge&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{
		&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt; age;
	}

	&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;setAge&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; age)&lt;/span&gt; &lt;/span&gt;{
		&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;this&lt;/span&gt;.age = age;
	}

}
&lt;/code&gt;&lt;/pre&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;首先创建了一个 Person 对象，然后把 Person 对象设置进 AtomicReference 对象中，然后调用 compareAndSet 方法，该方法就是通过通过 CAS 操作设置 ar。如果 ar 的值为 person 的话，则将其设置为 updatePerson。实现原理与 AtomicInteger 类中的 compareAndSet 方法相同。&lt;/p&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;5. 对象的属性修改类型原子类&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;5.1 对象的属性修改类型原子类介绍&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;如果需要原子更新某个类里的某个字段时，需要用到对象的属性修改类型原子类。&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;AtomicIntegerFieldUpdater:原子更新整形字段的更新器&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;AtomicLongFieldUpdater：原子更新长整形字段的更新器&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;AtomicStampedReference ：原子更新带有版本号的引用类型。该类将整数值与引用关联起来，可用于解决原子的更新数据和数据的版本号，可以解决使用 CAS 进行原子更新时可能出现的 ABA 问题。&lt;/li&gt;
&lt;/ul&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;要想原子地更新对象的属性需要两步。第一步，因为对象的属性修改类型原子类都是抽象类，所以每次使用都必须使用静态方法 newUpdater()创建一个更新器，并且需要设置想要更新的类和属性。第二步，更新的对象属性必须使用 public volatile 修饰符。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;上面三个类提供的方法几乎相同，所以我们这里以&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;AtomicIntegerFieldUpdater&lt;/code&gt; 为例子来介绍。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;5.2 AtomicIntegerFieldUpdater 类使用示例&lt;/h4&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;import&lt;/span&gt; java.util.concurrent.atomic.AtomicIntegerFieldUpdater;

&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;AtomicIntegerFieldUpdaterTest&lt;/span&gt; &lt;/span&gt;{
	&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;main&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(String[] args)&lt;/span&gt; &lt;/span&gt;{
		AtomicIntegerFieldUpdater&lt;User&gt; a = AtomicIntegerFieldUpdater.newUpdater(User.class, &lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;age&quot;&lt;/span&gt;);

		User user = &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; User(&lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;Java&quot;&lt;/span&gt;, &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;22&lt;/span&gt;);
		System.out.println(a.getAndIncrement(user));&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;// 22&lt;/span&gt;
		System.out.println(a.get(user));&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;// 23&lt;/span&gt;
	}
}

&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;User&lt;/span&gt; &lt;/span&gt;{
	&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;private&lt;/span&gt; String name;
	&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;volatile&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; age;

	&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;User&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(String name, &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; age)&lt;/span&gt; &lt;/span&gt;{
		&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;super&lt;/span&gt;();
		&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;this&lt;/span&gt;.name = name;
		&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;this&lt;/span&gt;.age = age;
	}

	&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; String &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;getName&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{
		&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt; name;
	}

	&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;setName&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(String name)&lt;/span&gt; &lt;/span&gt;{
		&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;this&lt;/span&gt;.name = name;
	}

	&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;getAge&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{
		&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt; age;
	}

	&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;setAge&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; age)&lt;/span&gt; &lt;/span&gt;{
		&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;this&lt;/span&gt;.age = age;
	}

}
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;center style='display:none !important;visibility:collapse !important;height:0 !important;white-space:nowrap;width:100%;overflow:hidden'&gt;%5Btoc%5D%0A%23%23%20%E4%B8%83.%20JUC%20%E4%B8%AD%E7%9A%84%20Atomic%20%E5%8E%9F%E5%AD%90%E7%B1%BB%E6%80%BB%E7%BB%93%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/8c6ce7bf-9cf7-4151-b61b-40e09574af44/5e677e9b-8b27-4a65-8e68-451fe6c3c458.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F604%3A1)%0A%23%23%23%201.%20Atomic%20%E5%8E%9F%E5%AD%90%E7%B1%BB%E4%BB%8B%E7%BB%8D%0AAtomic%20%E7%BF%BB%E8%AF%91%E6%88%90%E4%B8%AD%E6%96%87%E6%98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E5%BE%81%E7%9A%84%E7%B1%BB%E3%80%82%0A%0A%E5%B9%B6%E5%8F%91%E5%8C%85%20%20%60java.util.concurrent%60%20%20%E7%9A%84%E5%8E%9F%E5%AD%90%E7%B1%BB%E9%83%BD%E5%AD%98%E6%94%BE%E5%9C%A8%20%60java.util.concurrent.atomic%60%20%E4%B8%8B%0A%0A%23%23%23%23%201.1%20%E5%8E%9F%E5%AD%90%E7%B1%BB%E7%B1%BB%E5%9E%8B%0A%E6%A0%B9%E6%8D%AE%E6%93%8D%E4%BD%9C%E7%9A%84%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%EF%BC%8C%E5%8F%AF%E4%BB%A5%E5%B0%86JUC%E5%8C%85%E4%B8%AD%E7%9A%84%E5%8E%9F%E5%AD%90%E7%B1%BB%E5%88%86%E4%B8%BA4%E7%B1%BB%0A%0A%23%23%23%23%23%20%E5%9F%BA%E6%9C%AC%E7%B1%BB%E5%9E%8B%0A%3E%E4%BD%BF%E7%94%A8%E5%8E%9F%E5%AD%90%E7%9A%84%E6%96%B9%E5%BC%8F%E6%9B%B4%E6%96%B0%E5%9F%BA%E6%9C%AC%E7%B1%BB%E5%9E%8B%0A%3E*%20AtomicInteger%EF%BC%9A%E6%95%B4%E5%BD%A2%E5%8E%9F%E5%AD%90%E7%B1%BB%0A%3E*%20AtomicLong%EF%BC%9A%E9%95%BF%E6%95%B4%E5%9E%8B%E5%8E%9F%E5%AD%90%E7%B1%BB%0A%3E*%20AtomicBoolean%20%EF%BC%9A%E5%B8%83%E5%B0%94%E5%9E%8B%E5%8E%9F%E5%AD%90%E7%B1%BB%0A%0A%23%23%23%23%23%20%E6%95%B0%E7%BB%84%E7%B1%BB%E5%9E%8B%0A%3E%E4%BD%BF%E7%94%A8%E5%8E%9F%E5%AD%90%E7%9A%84%E6%96%B9%E5%BC%8F%E6%9B%B4%E6%96%B0%E6%95%B0%E7%BB%84%E9%87%8C%E7%9A%84%E6%9F%90%E4%B8%AA%E5%85%83%E7%B4%A0%0A%3E*%20AtomicIntegerArray%EF%BC%9A%E6%95%B4%E5%BD%A2%E6%95%B0%E7%BB%84%E5%8E%9F%E5%AD%90%E7%B1%BB%0A%3E*%20AtomicLongArray%EF%BC%9A%E9%95%BF%E6%95%B4%E5%BD%A2%E6%95%B0%E7%BB%84%E5%8E%9F%E5%AD%90%E7%B1%BB%0A%3E*%20AtomicReferenceArray%20%EF%BC%9A%E5%BC%95%E7%94%A8%E7%B1%BB%E5%9E%8B%E6%95%B0%E7%BB%84%E5%8E%9F%E5%AD%90%E7%B1%BB%0A%0A%23%23%23%23%23%20%E5%BC%95%E7%94%A8%E7%B1%BB%E5%9E%8B%0A%3EAtomicReference%EF%BC%9A%E5%BC%95%E7%94%A8%E7%B1%BB%E5%9E%8B%E5%8E%9F%E5%AD%90%E7%B1%BB%0A%3E*%20AtomicStampedRerence%EF%BC%9A%E5%8E%9F%E5%AD%90%E6%9B%B4%E6%96%B0%E5%BC%95%E7%94%A8%E7%B1%BB%E5%9E%8B%E9%87%8C%E7%9A%84%E5%AD%97%E6%AE%B5%E5%8E%9F%E5%AD%90%E7%B1%BB%0A%3E*%20AtomicMarkableReference%20%EF%BC%9A%E5%8E%9F%E5%AD%90%E6%9B%B4%E6%96%B0%E5%B8%A6%E6%9C%89%E6%A0%87%E8%AE%B0%E4%BD%8D%E7%9A%84%E5%BC%95%E7%94%A8%E7%B1%BB%E5%9E%8B%0A%0A%23%23%23%23%23%20%E5%AF%B9%E8%B1%A1%E7%9A%84%E5%B1%9E%E6%80%A7%E4%BF%AE%E6%94%B9%E7%B1%BB%E5%9E%8B%0A%3E*%20AtomicIntegerFieldUpdater%3A%E5%8E%9F%E5%AD%90%E6%9B%B4%E6%96%B0%E6%95%B4%E5%BD%A2%E5%AD%97%E6%AE%B5%E7%9A%84%E6%9B%B4%E6%96%B0%E5%99%A8%0A%3E*%20AtomicLongFieldUpdater%EF%BC%9A%E5%8E%9F%E5%AD%90%E6%9B%B4%E6%96%B0%E9%95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4%E5%BD%A2%E5%8E%9F%E5%AD%90%E7%B1%BB%0A*%20AtomicLong%EF%BC%9A%E9%95%BF%E6%95%B4%E5%9E%8B%E5%8E%9F%E5%AD%90%E7%B1%BB%0A*%20AtomicBoolean%20%EF%BC%9A%E5%B8%83%E5%B0%94%E5%9E%8B%E5%8E%9F%E5%AD%90%E7%B1%BB%0A%0A%E4%B8%8A%E9%9D%A2%E4%B8%89%E4%B8%AA%E7%B1%BB%E6%8F%90%E4%BE%9B%E7%9A%84%E6%96%B9%E6%B3%95%E5%87%A0%E4%B9%8E%E7%9B%B8%E5%90%8C%EF%BC%8C%E6%89%80%E4%BB%A5%E6%88%91%E4%BB%AC%E8%BF%99%E9%87%8C%E4%BB%A5%20AtomicInteger%20%E4%B8%BA%E4%BE%8B%E5%AD%90%E6%9D%A5%E4%BB%8B%E7%BB%8D%E3%80%82%0A%0AAtomicInteger%20%E7%B1%BB%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%95%0A%60%60%60java%0Apublic%20final%20int%20get()%20%2F%2F%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E7%9A%84%E5%80%BC%0A%0Apublic%20final%20int%20getAndSet(int%20newValue)%2F%2F%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E7%9A%84%E5%80%BC%EF%BC%8C%E5%B9%B6%E8%AE%BE%E7%BD%AE%E6%96%B0%E7%9A%84%E5%80%BC%0A%0Apublic%20final%20int%20getAndIncrement()%2F%2F%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E7%9A%84%E5%80%BC%EF%BC%8C%E5%B9%B6%E8%87%AA%E5%A2%9E%0A%0Apublic%20final%20int%20getAndDecrement()%20%2F%2F%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E7%9A%84%E5%80%BC%EF%BC%8C%E5%B9%B6%E8%87%AA%E5%87%8F%0A%0Apublic%20final%20int%20getAndAdd(int%20delta)%20%2F%2F%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E7%9A%84%E5%80%BC%EF%BC%8C%E5%B9%B6%E5%8A%A0%E4%B8%8A%E9%A2%84%E6%9C%9F%E7%9A%84%E5%80%BC%0A%0Aboolean%20compareAndSet(int%20expect%2C%20int%20update)%20%2F%2F%E5%A6%82%E6%9E%9C%E8%BE%93%E5%85%A5%E7%9A%84%E6%95%B0%E5%80%BC%E7%AD%89%E4%BA%8E%E9%A2%84%E6%9C%9F%E5%80%BC%EF%BC%8C%E5%88%99%E4%BB%A5%E5%8E%9F%E5%AD%90%E6%96%B9%E5%BC%8F%E5%B0%86%E8%AF%A5%E5%80%BC%E8%AE%BE%E7%BD%AE%E4%B8%BA%E8%BE%93%E5%85%A5%E5%80%BC%EF%BC%88update%EF%BC%89%0A%0Apublic%20final%20void%20lazySet(int%20newValue)%2F%2F%E6%9C%80%E7%BB%88%E8%AE%BE%E7%BD%AE%E4%B8%BAnewValue%2C%E4%BD%BF%E7%94%A8%20lazySet%20%E8%AE%BE%E7%BD%AE%E4%B9%8B%E5%90%8E%E5%8F%AF%E8%83%BD%E5%AF%BC%E8%87%B4%E5%85%B6%E4%BB%96%E7%BA%BF%E7%A8%8B%E5%9C%A8%E4%B9%8B%E5%90%8E%E7%9A%84%E4%B8%80%E5%B0%8F%E6%AE%B5%E6%97%B6%E9%97%B4%E5%86%85%E8%BF%98%E6%98%AF%E5%8F%AF%E4%BB%A5%E8%AF%BB%E5%88%B0%E6%97%A7%E7%9A%84%E5%80%BC%E3%80%82%0A%0A%60%60%60%0A%0A%23%23%23%23%202.2%20AtomicInteger%20%E5%B8%B8%E8%A7%81%E6%96%B9%E6%B3%95%E4%BD%BF%E7%94%A8%0A%60%60%60java%0Aimport%20java.util.concurrent.atomic.AtomicInteger%3B%0A%0Apublic%20class%20AtomicIntegerTest%20%7B%0A%0A%09public%20static%20void%20main(String%5B%5D%20args)%20%7B%0A%09%09%2F%2F%20TODO%20Auto-generated%20method%20stub%0A%09%09int%20temvalue%20%3D%200%3B%0A%09%09AtomicInteger%20i%20%3D%20new%20AtomicInteger(0)%3B%0A%09%09temvalue%20%3D%20i.getAndSet(3)%3B%0A%09%09System.out.println(%22temvalue%3A%22%20%2B%20temvalue%20%2B%20%22%3B%20%20i%3A%22%20%2B%20i)%3B%2F%2Ftemvalue%3A0%3B%20%20i%3A3%0A%09%09temvalue%20%3D%20i.getAndIncrement()%3B%0A%09%09System.out.println(%22temvalue%3A%22%20%2B%20temvalue%20%2B%20%22%3B%20%20i%3A%22%20%2B%20i)%3B%2F%2Ftemvalue%3A3%3B%20%20i%3A4%0A%09%09temvalue%20%3D%20i.getAndAdd(5)%3B%0A%09%09System.out.println(%22temvalue%3A%22%20%2B%20temvalue%20%2B%20%22%3B%20%20i%3A%22%20%2B%20i)%3B%2F%2Ftemvalue%3A4%3B%20%20i%3A9%0A%09%7D%0A%0A%7D%0A%60%60%60%0A%0A%23%23%23%23%202.3%20%E5%9F%BA%E6%9C%AC%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E5%8E%9F%E5%AD%90%E7%B1%BB%E7%9A%84%E4%BC%98%E5%8A%BF%0A1.%20%E5%A4%9A%E7%BA%BF%E7%A8%8B%E7%8E%AF%E5%A2%83%E4%B8%8D%E4%BD%BF%E7%94%A8%E5%8E%9F%E5%AD%90%E7%B1%BB%E4%BF%9D%E8%AF%81%E7%BA%BF%E7%A8%8B%E5%AE%89%E5%85%A8%EF%BC%88%E5%9F%BA%E6%9C%AC%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%EF%BC%89%0A%60%60%60java%0Aclass%20Test%20%7B%0A%20%20%20%20%20%20%20%20private%20volatile%20int%20count%20%3D%200%3B%0A%20%20%20%20%20%20%20%20%2F%2F%E8%8B%A5%E8%A6%81%E7%BA%BF%E7%A8%8B%E5%AE%89%E5%85%A8%E6%89%A7%E8%A1%8C%E6%89%A7%E8%A1%8Ccount%2B%2B%EF%BC%8C%E9%9C%80%E8%A6%81%E5%8A%A0%E9%94%81%0A%20%20%20%20%20%20%20%20public%20synchronized%20void%20increment()%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20count%2B%2B%3B%20%0A%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20public%20int%20getCount()%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return%20count%3B%0A%20%20%20%20%20%20%20%20%7D%0A%7D%0A%60%60%60%0A2.%20%E5%A4%9A%E7%BA%BF%E7%A8%8B%E7%8E%AF%E5%A2%83%E4%BD%BF%E7%94%A8%E5%8E%9F%E5%AD%90%E7%B1%BB%E4%BF%9D%E8%AF%81%E7%BA%BF%E7%A8%8B%E5%AE%89%E5%85%A8%EF%BC%88%E5%9F%BA%E6%9C%AC%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%EF%BC%89%0A%60%60%60java%0Aclass%20Test2%20%7B%0A%20%20%20%20%20%20%20%20private%20AtomicInteger%20count%20%3D%20new%20AtomicInteger()%3B%0A%0A%20%20%20%20%20%20%20%20public%20void%20increment()%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20count.incrementAndGet()%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%2F%2F%E4%BD%BF%E7%94%A8AtomicInteger%E4%B9%8B%E5%90%8E%EF%BC%8C%E4%B8%8D%E9%9C%80%E8%A6%81%E5%8A%A0%E9%94%81%EF%BC%8C%E4%B9%9F%E5%8F%AF%E4%BB%A5%E5%AE%9E%E7%8E%B0%E7%BA%BF%E7%A8%8B%E5%AE%89%E5%85%A8%E3%80%82%0A%20%20%20%20%20%20%20public%20int%20getCount()%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return%20count.get()%3B%0A%20%20%20%20%20%20%20%20%7D%0A%7D%0A%60%60%60%0A%0A%23%23%23%23%202.4%20AtomicInteger%20%E7%BA%BF%E7%A8%8B%E5%AE%89%E5%85%A8%E5%8E%9F%E7%90%86%E7%AE%80%E5%8D%95%E5%88%86%E6%9E%90%0A%0AAtomicInteger%20%E7%B1%BB%E7%9A%84%E9%83%A8%E5%88%86%E6%BA%90%E7%A0%81%EF%BC%9A%0A%60%60%60java%0A%20%20%20%20%2F%2F%20setup%20to%20use%20Unsafe.compareAndSwapInt%20for%20updates%EF%BC%88%E6%9B%B4%E6%96%B0%E6%93%8D%E4%BD%9C%E6%97%B6%E6%8F%90%E4%BE%9B%E2%80%9C%E6%AF%94%E8%BE%83%E5%B9%B6%E6%9B%BF%E6%8D%A2%E2%80%9D%E7%9A%84%E4%BD%9C%E7%94%A8%EF%BC%89%0A%20%20%20%20private%20static%20final%20Unsafe%20unsafe%20%3D%20Unsafe.getUnsafe()%3B%0A%20%20%20%20private%20static%20final%20long%20valueOffset%3B%0A%0A%20%20%20%20static%20%7B%0A%20%20%20%20%20%20%20%20try%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20valueOffset%20%3D%20unsafe.objectFieldOffset%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20(AtomicInteger.class.getDeclaredField(%22value%22))%3B%0A%20%20%20%20%20%20%20%20%7D%20catch%20(Exception%20ex)%20%7B%20throw%20new%20Error(ex)%3B%20%7D%0A%20%20%20%20%7D%0A%0A%20%20%20%20private%20volatile%20int%20value%3B%0A%60%60%60%0AAtomicInteger%20%E7%B1%BB%E4%B8%BB%E8%A6%81%E5%88%A9%E7%94%A8%20CAS%20(compare%20and%20swap)%20%2B%20volatile%20%E5%92%8C%20native%20%E6%96%B9%E6%B3%95%E6%9D%A5%E4%BF%9D%E8%AF%81%E5%8E%9F%E5%AD%90%E6%93%8D%E4%BD%9C%EF%BC%8C%E4%BB%8E%E8%80%8C%E9%81%BF%E5%85%8D%20synchronized%20%E7%9A%84%E9%AB%98%E5%BC%80%E9%94%80%EF%BC%8C%E6%89%A7%E8%A1%8C%E6%95%88%E7%8E%87%E5%A4%A7%E4%B8%BA%E6%8F%90%E5%8D%87%E3%80%82%0A%0ACAS%E7%9A%84%E5%8E%9F%E7%90%86%E6%98%AF%E6%8B%BF%E6%9C%9F%E6%9C%9B%E7%9A%84%E5%80%BC%E5%92%8C%E5%8E%9F%E6%9C%AC%E7%9A%84%E4%B8%80%E4%B8%AA%E5%80%BC%E4%BD%9C%E6%AF%94%E8%BE%83%EF%BC%8C%E5%A6%82%E6%9E%9C%E7%9B%B8%E5%90%8C%E5%88%99%E6%9B%B4%E6%96%B0%E6%88%90%E6%96%B0%E7%9A%84%E5%80%BC%E3%80%82UnSafe%20%E7%B1%BB%E7%9A%84%20objectFieldOffset()%20%E6%96%B9%E6%B3%95%E6%98%AF%E4%B8%80%E4%B8%AA%E6%9C%AC%E5%9C%B0%E6%96%B9%E6%B3%95%EF%BC%8C%E8%BF%99%E4%B8%AA%E6%96%B9%E6%B3%95%E6%98%AF%E7%94%A8%E6%9D%A5%E6%8B%BF%E5%88%B0%E2%80%9C%E5%8E%9F%E6%9D%A5%E7%9A%84%E5%80%BC%E2%80%9D%E7%9A%84%E5%86%85%E5%AD%98%E5%9C%B0%E5%9D%80%EF%BC%8C%E8%BF%94%E5%9B%9E%E5%80%BC%E6%98%AF%20valueOffset%E3%80%82%E5%8F%A6%E5%A4%96%20value%20%E6%98%AF%E4%B8%80%E4%B8%AAvolatile%E5%8F%98%E9%87%8F%EF%BC%8C%E5%9C%A8%E5%86%85%E5%AD%98%E4%B8%AD%E5%8F%AF%E8%A7%81%EF%BC%8C%E5%9B%A0%E6%AD%A4%20JVM%20%E5%8F%AF%E4%BB%A5%E4%BF%9D%E8%AF%81%E4%BB%BB%E4%BD%95%E6%97%B6%E5%88%BB%E4%BB%BB%E4%BD%95%E7%BA%BF%E7%A8%8B%E6%80%BB%E8%83%BD%E6%8B%BF%E5%88%B0%E8%AF%A5%E5%8F%98%E9%87%8F%E7%9A%84%E6%9C%80%E6%96%B0%E5%80%BC%E3%80%82%0A%0A%23%23%23%203.%20%E6%95%B0%E7%BB%84%E7%B1%BB%E5%9E%8B%E5%8E%9F%E5%AD%90%E7%B1%BB%0A%0A%23%23%23%23%203.1%20%E6%95%B0%E7%BB%84%E7%B1%BB%E5%9E%8B%E5%8E%9F%E5%AD%90%E7%B1%BB%E4%BB%8B%E7%BB%8D%0A%0A%E4%BD%BF%E7%94%A8%E5%8E%9F%E5%AD%90%E7%9A%84%E6%96%B9%E5%BC%8F%E6%9B%B4%E6%96%B0%E6%95%B0%E7%BB%84%E9%87%8C%E7%9A%84%E6%9F%90%E4%B8%AA%E5%85%83%E7%B4%A0%0A*%20AtomicIntegerArray%EF%BC%9A%E6%95%B4%E5%BD%A2%E6%95%B0%E7%BB%84%E5%8E%9F%E5%AD%90%E7%B1%BB%0A*%20AtomicLongArray%EF%BC%9A%E9%95%BF%E6%95%B4%E5%BD%A2%E6%95%B0%E7%BB%84%E5%8E%9F%E5%AD%90%E7%B1%BB%0A*%20AtomicReferenceArray%20%EF%BC%9A%E5%BC%95%E7%94%A8%E7%B1%BB%E5%9E%8B%E6%95%B0%E7%BB%84%E5%8E%9F%E5%AD%90%E7%B1%BB%0A%0A%E4%B8%8A%E9%9D%A2%E4%B8%89%E4%B8%AA%E7%B1%BB%E6%8F%90%E4%BE%9B%E7%9A%84%E6%96%B9%E6%B3%95%E5%87%A0%E4%B9%8E%E7%9B%B8%E5%90%8C%EF%BC%8C%E6%89%80%E4%BB%A5%E6%88%91%E4%BB%AC%E8%BF%99%E9%87%8C%E4%BB%A5%20AtomicIntegerArray%20%E4%B8%BA%E4%BE%8B%E5%AD%90%E6%9D%A5%E4%BB%8B%E7%BB%8D%E3%80%82%0A%0AAtomicIntegerArray%20%E7%B1%BB%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%95%0A%60%60%60java%0Apublic%20final%20int%20get(int%20i)%20%2F%2F%E8%8E%B7%E5%8F%96%20index%3Di%20%E4%BD%8D%E7%BD%AE%E5%85%83%E7%B4%A0%E7%9A%84%E5%80%BC%0A%0Apublic%20final%20int%20getAndSet(int%20i%2C%20int%20newValue)%2F%2F%E8%BF%94%E5%9B%9E%20index%3Di%20%E4%BD%8D%E7%BD%AE%E7%9A%84%E5%BD%93%E5%89%8D%E7%9A%84%E5%80%BC%EF%BC%8C%E5%B9%B6%E5%B0%86%E5%85%B6%E8%AE%BE%E7%BD%AE%E4%B8%BA%E6%96%B0%E5%80%BC%EF%BC%9AnewValue%0A%0Apublic%20final%20int%20getAndIncrement(int%20i)%2F%2F%E8%8E%B7%E5%8F%96%20index%3Di%20%E4%BD%8D%E7%BD%AE%E5%85%83%E7%B4%A0%E7%9A%84%E5%80%BC%EF%BC%8C%E5%B9%B6%E8%AE%A9%E8%AF%A5%E4%BD%8D%E7%BD%AE%E7%9A%84%E5%85%83%E7%B4%A0%E8%87%AA%E5%A2%9E%0A%0Apublic%20final%20int%20getAndDecrement(int%20i)%20%2F%2F%E8%8E%B7%E5%8F%96%20index%3Di%20%E4%BD%8D%E7%BD%AE%E5%85%83%E7%B4%A0%E7%9A%84%E5%80%BC%EF%BC%8C%E5%B9%B6%E8%AE%A9%E8%AF%A5%E4%BD%8D%E7%BD%AE%E7%9A%84%E5%85%83%E7%B4%A0%E8%87%AA%E5%87%8F%0A%0Apublic%20final%20int%20getAndAdd(int%20delta)%20%2F%2F%E8%8E%B7%E5%8F%96%20index%3Di%20%E4%BD%8D%E7%BD%AE%E5%85%83%E7%B4%A0%E7%9A%84%E5%80%BC%EF%BC%8C%E5%B9%B6%E5%8A%A0%E4%B8%8A%E9%A2%84%E6%9C%9F%E7%9A%84%E5%80%BC%0A%0Aboolean%20compareAndSet(int%20expect%2C%20int%20update)%20%2F%2F%E5%A6%82%E6%9E%9C%E8%BE%93%E5%85%A5%E7%9A%84%E6%95%B0%E5%80%BC%E7%AD%89%E4%BA%8E%E9%A2%84%E6%9C%9F%E5%80%BC%EF%BC%8C%E5%88%99%E4%BB%A5%E5%8E%9F%E5%AD%90%E6%96%B9%E5%BC%8F%E5%B0%86%20index%3Di%20%E4%BD%8D%E7%BD%AE%E7%9A%84%E5%85%83%E7%B4%A0%E5%80%BC%E8%AE%BE%E7%BD%AE%E4%B8%BA%E8%BE%93%E5%85%A5%E5%80%BC%EF%BC%88update%EF%BC%89%0A%0Apublic%20final%20void%20lazySet(int%20i%2C%20int%20newValue)%2F%2F%E6%9C%80%E7%BB%88%20%E5%B0%86index%3Di%20%E4%BD%8D%E7%BD%AE%E7%9A%84%E5%85%83%E7%B4%A0%E8%AE%BE%E7%BD%AE%E4%B8%BAnewValue%2C%E4%BD%BF%E7%94%A8%20lazySet%20%E8%AE%BE%E7%BD%AE%E4%B9%8B%E5%90%8E%E5%8F%AF%E8%83%BD%E5%AF%BC%E8%87%B4%E5%85%B6%E4%BB%96%E7%BA%BF%E7%A8%8B%E5%9C%A8%E4%B9%8B%E5%90%8E%E7%9A%84%E4%B8%80%E5%B0%8F%E6%AE%B5%E6%97%B6%E9%97%B4%E5%86%85%E8%BF%98%E6%98%AF%E5%8F%AF%E4%BB%A5%E8%AF%BB%E5%88%B0%E6%97%A7%E7%9A%84%E5%80%BC%E3%80%82%0A%60%60%60%0A%0A%23%23%23%23%203.2%20AtomicIntegerArray%20%E5%B8%B8%E8%A7%81%E6%96%B9%E6%B3%95%E4%BD%BF%E7%94%A8%0A%60%60%60java%0A%0Aimport%20java.util.concurrent.atomic.AtomicIntegerArray%3B%0A%0Apublic%20class%20AtomicIntegerArrayTest%20%7B%0A%0A%09public%20static%20void%20main(String%5B%5D%20args)%20%7B%0A%09%09%2F%2F%20TODO%20Auto-generated%20method%20stub%0A%09%09int%20temvalue%20%3D%200%3B%0A%09%09int%5B%5D%20nums%20%3D%20%7B%201%2C%202%2C%203%2C%204%2C%205%2C%206%20%7D%3B%0A%09%09AtomicIntegerArray%20i%20%3D%20new%20AtomicIntegerArray(nums)%3B%0A%09%09for%20(int%20j%20%3D%200%3B%20j%20%3C%20nums.length%3B%20j%2B%2B)%20%7B%0A%09%09%09System.out.println(i.get(j))%3B%0A%09%09%7D%0A%09%09temvalue%20%3D%20i.getAndSet(0%2C%202)%3B%0A%09%09System.out.println(%22temvalue%3A%22%20%2B%20temvalue%20%2B%20%22%3B%20%20i%3A%22%20%2B%20i)%3B%0A%09%09temvalue%20%3D%20i.getAndIncrement(0)%3B%0A%09%09System.out.println(%22temvalue%3A%22%20%2B%20temvalue%20%2B%20%22%3B%20%20i%3A%22%20%2B%20i)%3B%0A%09%09temvalue%20%3D%20i.getAndAdd(0%2C%205)%3B%0A%09%09System.out.println(%22temvalue%3A%22%20%2B%20temvalue%20%2B%20%22%3B%20%20i%3A%22%20%2B%20i)%3B%0A%09%7D%0A%0A%7D%0A%60%60%60%0A%0A%23%23%23%204.%20%E5%BC%95%E7%94%A8%E7%B1%BB%E5%9E%8B%E5%8E%9F%E5%AD%90%E7%B1%BB%0A%23%23%23%23%204.1%20%E5%BC%95%E7%94%A8%E7%B1%BB%E5%9E%8B%E5%8E%9F%E5%AD%90%E7%B1%BB%E4%BB%8B%E7%BB%8D%0A%E5%9F%BA%E6%9C%AC%E7%B1%BB%E5%9E%8B%E5%8E%9F%E5%AD%90%E7%B1%BB%E5%8F%AA%E8%83%BD%E6%9B%B4%E6%96%B0%E4%B8%80%E4%B8%AA%E5%8F%98%E9%87%8F%EF%BC%8C%E5%A6%82%E6%9E%9C%E9%9C%80%E8%A6%81%E5%8E%9F%E5%AD%90%E6%9B%B4%E6%96%B0%E5%A4%9A%E4%B8%AA%E5%8F%98%E9%87%8F%EF%BC%8C%E9%9C%80%E8%A6%81%E4%BD%BF%E7%94%A8%20%E5%BC%95%E7%94%A8%E7%B1%BB%E5%9E%8B%E5%8E%9F%E5%AD%90%E7%B1%BB%E3%80%82%0A*%20AtomicReference%EF%BC%9A%E5%BC%95%E7%94%A8%E7%B1%BB%E5%9E%8B%E5%8E%9F%E5%AD%90%E7%B1%BB%0A*%20AtomicStampedRerence%EF%BC%9A%E5%8E%9F%E5%AD%90%E6%9B%B4%E6%96%B0%E5%BC%95%E7%94%A8%E7%B1%BB%E5%9E%8B%E9%87%8C%E7%9A%84%E5%AD%97%E6%AE%B5%E5%8E%9F%E5%AD%90%E7%B1%BB%0A*%20AtomicMarkableReference%20%EF%BC%9A%E5%8E%9F%E5%AD%90%E6%9B%B4%E6%96%B0%E5%B8%A6%E6%9C%89%E6%A0%87%E8%AE%B0%E4%BD%8D%E7%9A%84%E5%BC%95%E7%94%A8%E7%B1%BB%E5%9E%8B%0A%0A%E4%B8%8A%E9%9D%A2%E4%B8%89%E4%B8%AA%E7%B1%BB%E6%8F%90%E4%BE%9B%E7%9A%84%E6%96%B9%E6%B3%95%E5%87%A0%E4%B9%8E%E7%9B%B8%E5%90%8C%EF%BC%8C%E6%89%80%E4%BB%A5%E6%88%91%E4%BB%AC%E8%BF%99%E9%87%8C%E4%BB%A5%20AtomicReference%20%E4%B8%BA%E4%BE%8B%E5%AD%90%E6%9D%A5%E4%BB%8B%E7%BB%8D%E3%80%82%0A%0A%23%23%23%23%204.2%20AtomicReference%20%E7%B1%BB%E4%BD%BF%E7%94%A8%E7%A4%BA%E4%BE%8B%0A%60%60%60java%0Aimport%20java.util.concurrent.atomic.AtomicReference%3B%0A%0Apublic%20class%20AtomicReferenceTest%20%7B%0A%0A%09public%20static%20void%20main(String%5B%5D%20args)%20%7B%0A%09%09AtomicReference%3CPerson%3E%20ar%20%3D%20new%20AtomicReference%3CPerson%3E()%3B%0A%09%09Person%20person%20%3D%20new%20Person(%22SnailClimb%22%2C%2022)%3B%0A%09%09ar.set(person)%3B%0A%09%09Person%20updatePerson%20%3D%20new%20Person(%22Daisy%22%2C%2020)%3B%0A%09%09ar.compareAndSet(person%2C%20updatePerson)%3B%0A%0A%09%09System.out.println(ar.get().getName())%3B%0A%09%09System.out.println(ar.get().getAge())%3B%0A%09%7D%0A%7D%0A%0Aclass%20Person%20%7B%0A%09private%20String%20name%3B%0A%09private%20int%20age%3B%0A%0A%09public%20Person(String%20name%2C%20int%20age)%20%7B%0A%09%09super()%3B%0A%09%09this.name%20%3D%20name%3B%0A%09%09this.age%20%3D%20age%3B%0A%09%7D%0A%0A%09public%20String%20getName()%20%7B%0A%09%09return%20name%3B%0A%09%7D%0A%0A%09public%20void%20setName(String%20name)%20%7B%0A%09%09this.name%20%3D%20name%3B%0A%09%7D%0A%0A%09public%20int%20getAge()%20%7B%0A%09%09return%20age%3B%0A%09%7D%0A%0A%09public%20void%20setAge(int%20age)%20%7B%0A%09%09this.age%20%3D%20age%3B%0A%09%7D%0A%0A%7D%0A%60%60%60%0A%E9%A6%96%E5%85%88%E5%88%9B%E5%BB%BA%E4%BA%86%E4%B8%80%E4%B8%AA%20Person%20%E5%AF%B9%E8%B1%A1%EF%BC%8C%E7%84%B6%E5%90%8E%E6%8A%8A%20Person%20%E5%AF%B9%E8%B1%A1%E8%AE%BE%E7%BD%AE%E8%BF%9B%20AtomicReference%20%E5%AF%B9%E8%B1%A1%E4%B8%AD%EF%BC%8C%E7%84%B6%E5%90%8E%E8%B0%83%E7%94%A8%20compareAndSet%20%E6%96%B9%E6%B3%95%EF%BC%8C%E8%AF%A5%E6%96%B9%E6%B3%95%E5%B0%B1%E6%98%AF%E9%80%9A%E8%BF%87%E9%80%9A%E8%BF%87%20CAS%20%E6%93%8D%E4%BD%9C%E8%AE%BE%E7%BD%AE%20ar%E3%80%82%E5%A6%82%E6%9E%9C%20ar%20%E7%9A%84%E5%80%BC%E4%B8%BA%20person%20%E7%9A%84%E8%AF%9D%EF%BC%8C%E5%88%99%E5%B0%86%E5%85%B6%E8%AE%BE%E7%BD%AE%E4%B8%BA%20updatePerson%E3%80%82%E5%AE%9E%E7%8E%B0%E5%8E%9F%E7%90%86%E4%B8%8E%20AtomicInteger%20%E7%B1%BB%E4%B8%AD%E7%9A%84%20compareAndSet%20%E6%96%B9%E6%B3%95%E7%9B%B8%E5%90%8C%E3%80%82%0A%0A%23%23%23%205.%20%E5%AF%B9%E8%B1%A1%E7%9A%84%E5%B1%9E%E6%80%A7%E4%BF%AE%E6%94%B9%E7%B1%BB%E5%9E%8B%E5%8E%9F%E5%AD%90%E7%B1%BB%0A%23%23%23%23%205.1%20%E5%AF%B9%E8%B1%A1%E7%9A%84%E5%B1%9E%E6%80%A7%E4%BF%AE%E6%94%B9%E7%B1%BB%E5%9E%8B%E5%8E%9F%E5%AD%90%E7%B1%BB%E4%BB%8B%E7%BB%8D%0A%E5%A6%82%E6%9E%9C%E9%9C%80%E8%A6%81%E5%8E%9F%E5%AD%90%E6%9B%B4%E6%96%B0%E6%9F%90%E4%B8%AA%E7%B1%BB%E9%87%8C%E7%9A%84%E6%9F%90%E4%B8%AA%E5%AD%97%E6%AE%B5%E6%97%B6%EF%BC%8C%E9%9C%80%E8%A6%81%E7%94%A8%E5%88%B0%E5%AF%B9%E8%B1%A1%E7%9A%84%E5%B1%9E%E6%80%A7%E4%BF%AE%E6%94%B9%E7%B1%BB%E5%9E%8B%E5%8E%9F%E5%AD%90%E7%B1%BB%E3%80%82%0A*%20AtomicIntegerFieldUpdater%3A%E5%8E%9F%E5%AD%90%E6%9B%B4%E6%96%B0%E6%95%B4%E5%BD%A2%E5%AD%97%E6%AE%B5%E7%9A%84%E6%9B%B4%E6%96%B0%E5%99%A8%0A*%20AtomicLongFieldUpdater%EF%BC%9A%E5%8E%9F%E5%AD%90%E6%9B%B4%E6%96%B0%E9%95%BF%E6%95%B4%E5%BD%A2%E5%AD%97%E6%AE%B5%E7%9A%84%E6%9B%B4%E6%96%B0%E5%99%A8%0A*%20AtomicStampedReference%20%EF%BC%9A%E5%8E%9F%E5%AD%90%E6%9B%B4%E6%96%B0%E5%B8%A6%E6%9C%89%E7%89%88%E6%9C%AC%E5%8F%B7%E7%9A%84%E5%BC%95%E7%94%A8%E7%B1%BB%E5%9E%8B%E3%80%82%E8%AF%A5%E7%B1%BB%E5%B0%86%E6%95%B4%E6%95%B0%E5%80%BC%E4%B8%8E%E5%BC%95%E7%94%A8%E5%85%B3%E8%81%94%E8%B5%B7%E6%9D%A5%EF%BC%8C%E5%8F%AF%E7%94%A8%E4%BA%8E%E8%A7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C%AC%E4%BA%8C%E6%AD%A5%EF%BC%8C%E6%9B%B4%E6%96%B0%E7%9A%84%E5%AF%B9%E8%B1%A1%E5%B1%9E%E6%80%A7%E5%BF%85%E9%A1%BB%E4%BD%BF%E7%94%A8%20public%20volatile%20%E4%BF%AE%E9%A5%B0%E7%AC%A6%E3%80%82%0A%0A%E4%B8%8A%E9%9D%A2%E4%B8%89%E4%B8%AA%E7%B1%BB%E6%8F%90%E4%BE%9B%E7%9A%84%E6%96%B9%E6%B3%95%E5%87%A0%E4%B9%8E%E7%9B%B8%E5%90%8C%EF%BC%8C%E6%89%80%E4%BB%A5%E6%88%91%E4%BB%AC%E8%BF%99%E9%87%8C%E4%BB%A5%60%20AtomicIntegerFieldUpdater%60%20%E4%B8%BA%E4%BE%8B%E5%AD%90%E6%9D%A5%E4%BB%8B%E7%BB%8D%E3%80%82%0A%0A%23%23%23%23%205.2%20AtomicIntegerFieldUpdater%20%E7%B1%BB%E4%BD%BF%E7%94%A8%E7%A4%BA%E4%BE%8B%0A%60%60%60java%0Aimport%20java.util.concurrent.atomic.AtomicIntegerFieldUpdater%3B%0A%0Apublic%20class%20AtomicIntegerFieldUpdaterTest%20%7B%0A%09public%20static%20void%20main(String%5B%5D%20args)%20%7B%0A%09%09AtomicIntegerFieldUpdater%3CUser%3E%20a%20%3D%20AtomicIntegerFieldUpdater.newUpdater(User.class%2C%20%22age%22)%3B%0A%0A%09%09User%20user%20%3D%20new%20User(%22Java%22%2C%2022)%3B%0A%09%09System.out.println(a.getAndIncrement(user))%3B%2F%2F%2022%0A%09%09System.out.println(a.get(user))%3B%2F%2F%2023%0A%09%7D%0A%7D%0A%0Aclass%20User%20%7B%0A%09private%20String%20name%3B%0A%09public%20volatile%20int%20age%3B%0A%0A%09public%20User(String%20name%2C%20int%20age)%20%7B%0A%09%09super()%3B%0A%09%09this.name%20%3D%20name%3B%0A%09%09this.age%20%3D%20age%3B%0A%09%7D%0A%0A%09public%20String%20getName()%20%7B%0A%09%09return%20name%3B%0A%09%7D%0A%0A%09public%20void%20setName(String%20name)%20%7B%0A%09%09this.name%20%3D%20name%3B%0A%09%7D%0A%0A%09public%20int%20getAge()%20%7B%0A%09%09return%20age%3B%0A%09%7D%0A%0A%09public%20void%20setAge(int%20age)%20%7B%0A%09%09this.age%20%3D%20age%3B%0A%09%7D%0A%0A%7D%0A%60%60%60&lt;/center&gt;&lt;/div&gt;
</content>
  </entry>
  <entry xml:base="http://linzhiteng.postach.io/feed.xml">
    <title type="text">Synchronized 关键字使用、底层原理、JDK1.6 之后的底层优化以及 和ReenTrantLock 的对比</title>
    <id>https://linzhiteng.postach.io/post/synchronized-guan-jian-zi-shi-yong-di-ceng-yuan-li-jdk1-6-zhi-hou-de-di-ceng-you-hua-yi-ji-he-reentrantlock-de-dui-bi</id>
    <updated>2019-06-09T13:07:41.490000Z</updated>
    <published>2019-03-12T14:51:09Z</published>
    <link href="https://linzhiteng.postach.io/post/synchronized-guan-jian-zi-shi-yong-di-ceng-yuan-li-jdk1-6-zhi-hou-de-di-ceng-you-hua-yi-ji-he-reentrantlock-de-dui-bi" />
    <author>
      <name>linzhi teng</name>
    </author>
    <category term="xian-cheng" />
    <content type="html">&lt;div&gt;&lt;div style=&quot;font-size: 14px; margin: 0; padding: 0; width: 100%;&quot;&gt;&lt;div style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;Synchronized 关键字使用、底层原理、JDK1.6 之后的底层优化以及 和ReenTrantLock 的对比
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1. synchronized关键字最主要的三种使用方式的总结
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.1 双重校验锁实现对象单例（线程安全）
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2. synchronized 关键字底层原理总结
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.1 synchronized 同步语句块的情况
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.2 synchronized 修饰方法的的情况
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3. JDK1.6 之后的底层优化
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1 JDK1.6之前
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.2 JDK1.6 之后
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;锁的状态
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1. 偏向锁
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2. 轻量级锁
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3. 自旋锁和自适应自旋
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4. 锁消除
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;5. 锁粗化
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4. Synchronized 和 ReenTrantLock 的对比
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.1  两者都是可重入锁
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.2 synchronized 依赖于 JVM 而 ReenTrantLock 依赖于 API
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.3 ReenTrantLock 比 synchronized 增加了一些高级功能
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;等待可中断
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;可实现公平锁
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;可实现选择性通知
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.4 性能已不是选择标准
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;Synchronized 关键字使用、底层原理、JDK1.6 之后的底层优化以及 和ReenTrantLock 的对比&lt;/h2&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/ea89d2d9-ebc9-4310-990b-067c26f54c8b/69efd701-83a6-4340-8219-98568ef4f91b.jpg&quot; /&gt;&lt;/p&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;1. synchronized关键字最主要的三种使用方式的总结&lt;/h3&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;修饰实例方法，作用于当前对象实例加锁，进入同步代码前要获得当前对象实例的锁&lt;/strong&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;修饰静态方法，作用于当前类对象加锁，进入同步代码前要获得当前类对象的锁&lt;/strong&gt;。也就是给当前类加锁，会作用于类的所有对象实例，因为静态成员不属于任何一个实例对象，是类成员（ static 表明这是该类的一个静态资源，不管new了多少个对象，只有一份，所以对该类的所有对象都加了锁）。所以如果一个线程A调用一个实例对象的非静态 synchronized 方法，而线程B需要调用这个实例对象所属类的静态 synchronized 方法，是允许的，不会发生互斥现象，因为访问静态 synchronized 方法占用的锁是当前类的锁，而访问非静态 synchronized 方法占用的锁是当前实例对象锁。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;修饰代码块，指定加锁对象，对给定对象加锁，进入同步代码块前要获得给定对象的锁&lt;/strong&gt;。 和 synchronized 方法一样，synchronized(this)代码块也是锁定当前对象的。synchronized 关键字加到 static 静态方法和 synchronized(class)代码块上都是是给 Class 类上锁。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;这里再提一下：synchronized关键字加到非 static 静态方法上是给对象实例上锁。另外需要注意的是：尽量不要使用 synchronized(String a) 因为JVM中，字符串常量池具有缓冲功能！&lt;/li&gt;
&lt;/ul&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;面试中面试官经常会说：&quot;单例模式了解吗？来给我手写一下！给我解释一下双重检验锁方式实现单例模式的原理呗！&quot;&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.1 双重校验锁实现对象单例（线程安全）&lt;/h4&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;Singleton&lt;/span&gt; &lt;/span&gt;{

    &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;volatile&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;static&lt;/span&gt; Singleton uniqueInstance;

    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;Singleton&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{
    }

    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;static&lt;/span&gt; Singleton &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;getUniqueInstance&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{
       &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//先判断对象是否已经实例过，没有实例化过才进入加锁代码&lt;/span&gt;
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;if&lt;/span&gt; (uniqueInstance == &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;null&lt;/span&gt;) {
            &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//类对象加锁&lt;/span&gt;
            &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;synchronized&lt;/span&gt; (Singleton.class) {
                &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;if&lt;/span&gt; (uniqueInstance == &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;null&lt;/span&gt;) {
                    uniqueInstance = &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; Singleton();
                }
            }
        }
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt; uniqueInstance;
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;需要注意 uniqueInstance 采用 static 关键字修饰也是很有必要。&lt;br/&gt;
uniqueInstance 采用 volatile 关键字修饰也是很有必要的，&lt;br/&gt;
uniqueInstance = new Singleton(); 这段代码其实是分为三步执行：&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;为 uniqueInstance 分配内存空间&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;初始化 uniqueInstance&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;将 uniqueInstance 指向分配的内存地址&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;但是由于 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;JVM&lt;/strong&gt; 具有&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;指令重排&lt;/strong&gt;的特性，执行顺序有可能变成 1-&gt;3-&gt;2。指令重排在单线程环境下不会出先问题，但是在多线程环境下会导致一个线程获得还没有初始化的实例。例如，线程 T1 执行了 1 和 3，此时 T2 调用 getUniqueInstance() 后发现 uniqueInstance 不为空，因此返回 uniqueInstance，但此时 uniqueInstance 还未被初始化。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;使用 volatile 可以禁止 JVM 的指令重排，保证在多线程环境下也能正常运行。&lt;/strong&gt;&lt;/p&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;2. synchronized 关键字底层原理总结&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;synchronized 关键字底层原理属于 JVM 层面。&lt;/strong&gt;&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.1 synchronized 同步语句块的情况&lt;/h4&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;SynchronizedDemo&lt;/span&gt; &lt;/span&gt;{
    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;method&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{ 
    &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;synchronized&lt;/span&gt; (&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;this&lt;/span&gt;) { 
        System.out.println(&lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;synchronized 代码块&quot;&lt;/span&gt;); 
         }
    } 
}
&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;通过 JDK 自带的 javap 命令查看 SynchronizedDemo 类的相关字节码信息：首先切换到类的对应目录执行 &lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;javac SynchronizedDemo.java&lt;/code&gt; 命令生成编译后的 .class 文件，然后执行&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;javap -c -s -v -l SynchronizedDemo.class&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/ea89d2d9-ebc9-4310-990b-067c26f54c8b/5ba730e3-347a-4014-a904-05ea59a1f88d.jpg&quot; /&gt;&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;synchronized 同步语句块的实现使用的是 monitorenter 和 monitorexit 指令&lt;/strong&gt;，其中 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;monitorenter 指令指向同步代码块的开始位置&lt;/strong&gt;，&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;monitorexit 指令则指明同步代码块的结束位置&lt;/strong&gt;。&lt;br/&gt;
当执行 monitorenter 指令时，线程试图获取锁也就是获取 monitor(monitor对象存在于每个Java对象的对象头中，synchronized 锁便是通过这种方式获取锁的，也是为什么Java中任意对象可以作为锁的原因) 的持有权.当计数器为0则可以成功获取，获取后将锁计数器设为1也就是加1。相应的在执行 monitorexit 指令后，将锁计数器设为0，表明锁被释放。如果获取对象锁失败，那当前线程就要阻塞等待，直到锁被另外一个线程释放为止。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.2 synchronized 修饰方法的的情况&lt;/h4&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;
&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;SynchronizedDemo2&lt;/span&gt; &lt;/span&gt;{ 
    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;synchronized&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;method&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{ 
        System.out.println(&lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;synchronized 方法&quot;&lt;/span&gt;); 
        } 
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/ea89d2d9-ebc9-4310-990b-067c26f54c8b/fadc424f-b564-447d-aeca-bc09411c32dc.jpg&quot; /&gt;&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;synchronized 修饰的方法&lt;/strong&gt;并没有 monitorenter 指令和 monitorexit 指令，取得代之的是 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;ACC_SYNCHRONIZED 标识&lt;/strong&gt;，该标识指明了该方法是一个同步方法，JVM 通过该 ACC_SYNCHRONIZED 访问标志来辨别一个方法是否声明为同步方法，从而执行相应的同步调用。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;3. JDK1.6 之后的底层优化&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.1 JDK1.6之前&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;在 Java 早期版本中，synchronized 属于重量级锁，效率低下，因为监视器锁（monitor）是依赖于底层的操作系统的 Mutex Lock 来实现的，Java 的线程是映射到操作系统的原生线程之上的。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;如果要挂起或者唤醒一个线程，都需要操作系统帮忙完成，而操作系统实现线程之间的切换时需要从用户态转换到内核态，这个状态之间的转换需要相对比较长的时间，时间成本相对较高，这也是为什么早期的 synchronized 效率低的原因。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;庆幸的是在 Java 6 之后 Java 官方对从 JVM 层面对synchronized 较大优化，所以现在的 synchronized 锁效率也优化得很不错了。JDK1.6对锁的实现引入了大量的优化，如自旋锁、适应性自旋锁、锁消除、锁粗化、偏向锁、轻量级锁等技术来减少锁操作的开销。&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.2 JDK1.6 之后&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;JDK1.6 对锁的实现引入了大量的优化，如偏向锁、轻量级锁、自旋锁、适应性自旋锁、锁消除、锁粗化等技术来减少锁操作的开销。&lt;/p&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;锁的状态&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;锁主要存在四中状态，依次是：无锁状态、偏向锁状态、轻量级锁状态、重量级锁状态，他们会随着竞争的激烈而逐渐升级。注意锁可以升级不可降级，这种策略是为了提高获得锁和释放锁的效率。&lt;/p&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;1. 偏向锁&lt;/h5&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;引入偏向锁的目的和引入轻量级锁的目的很像，他们都是&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;为了没有多线程竞争的前提下，减少传统的重量级锁使用操作系统互斥量产生的性能消耗&lt;/strong&gt;。&lt;br/&gt;
但是不同是：&lt;br/&gt;
轻量级锁在无竞争的情况下使用 CAS 操作去代替使用互斥量。&lt;br/&gt;
而偏向锁在无竞争的情况下会把整个同步都消除掉。&lt;/p&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;偏向锁的&quot;偏&quot;就是偏心的偏，它的意思是会偏向于第一个获得它的线程，如果在接下来的执行中，该锁没有被其他线程获取，那么持有偏向锁的线程就不需要进行同步！&lt;br/&gt;
关于偏向锁的原理可以查看《深入理解Java虚拟机：JVM高级特性与最佳实践》第二版的13章第三节锁优化。&lt;/p&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;但是对于锁竞争比较激烈的场合，偏向锁就失效了，因为这样场合极有可能每次申请锁的线程都是不相同的，因此这种场合下不应该使用偏向锁，否则会得不偿失，需要注意的是，&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;偏向锁失败后，并不会立即膨胀为重量级锁，而是先升级为轻量级锁&lt;/strong&gt;。&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;2. 轻量级锁&lt;/h5&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;倘若偏向锁失败，虚拟机并不会立即升级为重量级锁，它还会尝试使用一种称为轻量级锁的优化手段(1.6之后加入的)。轻量级锁不是为了代替重量级锁，它的本意是在没有多线程竞争的前提下，减少传统的重量级锁使用操作系统互斥量产生的性能消耗，因为&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;使用轻量级锁时，不需要申请互斥量&lt;/strong&gt;。另外，&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;轻量级锁的加锁和解锁都用到了CAS操作&lt;/strong&gt;。&lt;br/&gt;
关于轻量级锁的加锁和解锁的原理可以查看《深入理解Java虚拟机：JVM高级特性与最佳实践》第二版的13章第三节锁优化。&lt;/p&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;轻量级锁能够提升程序同步性能的依据是&quot;对于绝大部分锁，在整个同步周期内都是不存在竞争的&quot;，这是一个经验数据。&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;如果没有竞争，轻量级锁使用 CAS 操作避免了使用互斥操作的开销&lt;/strong&gt;。但如果存在锁竞争，除了互斥量开销外，还会额外发生CAS操作，因此在有锁竞争的情况下，轻量级锁比传统的重量级锁更慢！&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;如果锁竞争激烈，那么轻量级将很快膨胀为重量级锁&lt;/strong&gt;！&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;3. 自旋锁和自适应自旋&lt;/h5&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;轻量级锁失败后，虚拟机为了避免线程真实地在操作系统层面挂起，还会进行一项称为自旋锁的优化手段。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;互斥同步对性能最大的影响就是阻塞的实现，因为挂起线程/恢复线程的操作都需要转入内核态中完成（用户态转换到内核态会耗费时间）。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;一般线程持有锁的时间都不是太长，所以仅仅为了这一点时间去挂起线程/恢复线程是得不偿失的。 所以，虚拟机的开发团队就这样去考虑：&quot;我们能不能&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;让后面来的请求获取锁的线程等待一会而不被挂起&lt;/strong&gt;呢？看看持有锁的线程是否很快就会释放锁&quot;。&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;为了让一个线程等待，我们只需要让线程执行一个忙循环（自旋），这项技术就叫做自旋&lt;/strong&gt;。&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;何谓自旋锁？它是为实现保护共享资源而提出一种锁机制。其实，自旋锁与互斥锁比较类似，它们都是为了解决对某项资源的互斥使用。&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;无论是互斥锁，还是自旋锁，在任何时刻&lt;/strong&gt;，最多只能有一个保持者，也就说，在任何时刻&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;最多只能有一个执行单元获得锁&lt;/strong&gt;。但是&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;两者在调度机制上略有不同&lt;/strong&gt;。对于互斥锁，如果资源已经被占用，资源申请者只能进入睡眠状态。但是自旋锁不会引起调用者睡眠，如果自旋锁已经被别的执行单元保持，调用者就一直循环在那里看是否该自旋锁的保持者已经释放了锁，&quot;自旋&quot;一词就是因此而得名。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ol start=&quot;4&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;自旋锁在 JDK1.6 之前其实就已经引入了，不过是默认关闭的，需要通过--XX:+UseSpinning参数来开启。JDK1.6及1.6之后，就改为默认开启的了。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;需要注意的是：自旋等待不能完全替代阻塞，因为它还是要占用处理器时间。如果锁被占用的时间短，那么效果当然就很好了！反之，相反！自旋等待的时间必须要有限度。如果自旋超过了限定次数任然没有获得锁，就应该挂起线程。自旋次数的默认值是10次，用户可以修改--XX:PreBlockSpin来更改。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;另外,在 JDK1.6 中引入了自适应的自旋锁。&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;自适应的自旋锁&lt;/strong&gt;带来的改进就是：&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;自旋的时间不在固定了，而是和前一次同一个锁上的自旋时间以及锁的拥有者的状态来决定&lt;/strong&gt;，虚拟机变得越来越&quot;聪明&quot;了。&lt;/li&gt;
&lt;/ol&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4. 锁消除&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;锁消除理解起来很简单，它指的就是虚拟机即使编译器在运行时，如果检测到那些共享数据不可能存在竞争，那么就执行锁消除。锁消除可以节省毫无意义的请求锁的时间。&lt;/p&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;5. 锁粗化&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;原则上，我们编写代码的时候，总是推荐将同步快的作用范围限制得尽量小——只在共享数据的实际作用域才进行同步，这样是为了使得需要同步的操作数量尽可能变小，如果存在锁竞争，那等待线程也能尽快拿到锁。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;大部分情况下，上面的原则都是没有问题的，但是如果一系列的连续操作都对同一个对象反复加锁和解锁，那么会带来很多不必要的性能消耗。&lt;/p&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;4. Synchronized 和 ReenTrantLock 的对比&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;4.1  两者都是可重入锁&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;两者都是可重入锁。&quot;可重入锁&quot;概念是：自己可以再次获取自己的内部锁。比如一个线程获得了某个对象的锁，此时这个对象锁还没有释放，当其再次想要获取这个对象的锁的时候还是可以获取的，如果不可锁重入的话，就会造成死锁。同一个线程每次获取锁，锁的计数器都自增1，所以要等到锁的计数器下降为0时才能释放锁。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;4.2 synchronized 依赖于 JVM 而 ReenTrantLock 依赖于 API&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;synchronized 是依赖于 JVM 实现的，前面我们也讲到了 虚拟机团队在 JDK1.6 为 synchronized 关键字进行了很多优化，但是这些优化都是在虚拟机层面实现的，并没有直接暴露给我们。ReenTrantLock 是 JDK 层面实现的（也就是 API 层面，需要 lock() 和 unlock 方法配合 try/finally 语句块来完成），所以我们可以通过查看它的源代码，来看它是如何实现的。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;4.3 ReenTrantLock 比 synchronized 增加了一些高级功能&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;相比synchronized，ReenTrantLock增加了一些高级功能。主要来说主要有三点：①等待可中断；②可实现公平锁；③可实现选择性通知（锁可以绑定多个条件）&lt;/p&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;等待可中断&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;ReenTrantLock提供了一种能够中断等待锁的线程的机制，通过lock.lockInterruptibly()来实现这个机制。也就是说正在等待的线程可以选择放弃等待，改为处理其他事情。&lt;/p&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;可实现公平锁&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;ReenTrantLock可以指定是公平锁还是非公平锁。而synchronized只能是非公平锁。所谓的公平锁就是先等待的线程先获得锁。 ReenTrantLock默认情况是非公平的，可以通过 ReenTrantLock类的ReentrantLock(boolean fair)构造方法来制定是否是公平的。&lt;/p&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;可实现选择性通知&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;synchronized关键字与wait()和notify/notifyAll()方法相结合可以实现等待/通知机制，ReentrantLock类当然也可以实现，但是需要借助于Condition接口与newCondition() 方法。&lt;br/&gt;
Condition是JDK1.5之后才有的，它具有很好的灵活性，比如可以实现多路通知功能也就是&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;在一个Lock对象中可以创建多个Condition实例（即对象监视器），线程对象可以注册在指定的Condition中，从而可以有选择性的进行线程通知，在调度线程上更加灵活&lt;/strong&gt;。 在使用notify/notifyAll()方法进行通知时，被通知的线程是由 JVM 选择的，用ReentrantLock类结合Condition实例可以实现&quot;选择性通知&quot; ，这个功能非常重要，而且是Condition接口默认提供的。而synchronized关键字就相当于整个Lock对象中只有一个Condition实例，所有的线程都注册在它一个身上。如果执行notifyAll()方法的话就会通知所有处于等待状态的线程这样会造成很大的效率问题，而Condition实例的signalAll()方法 只会唤醒注册在该Condition实例中的所有等待线程。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;4.4 性能已不是选择标准&lt;/h4&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;在JDK1.6之前，synchronized 的性能是比 ReenTrantLock 差很多。具体表示为：synchronized 关键字吞吐量随线程数的增加，下降得非常严重。而ReenTrantLock 基本保持一个比较稳定的水平。我觉得这也侧面反映了， synchronized 关键字还有非常大的优化余地。后续的技术发展也证明了这一点，我们上面也讲了在 JDK1.6 之后 JVM 团队对 synchronized 关键字做了很多优化。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;JDK1.6 之后，synchronized 和 ReenTrantLock 的性能基本是持平了。所以网上那些说因为性能才选择 ReenTrantLock 的文章都是错的！JDK1.6之后，性能已经不是选择synchronized和ReenTrantLock的影响因素了！而且虚拟机在未来的性能改进中会更偏向于原生的synchronized，所以还是提倡在synchronized能满足你的需求的情况下，优先考虑使用synchronized关键字来进行同步！优化后的synchronized和ReenTrantLock一样，在很多地方都是用到了CAS操作。&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;&lt;center style=&quot;display:none !important;visibility:collapse !important;height:0 !important;white-space:nowrap;width:100%;overflow:hidden&quot;&gt;%5Btoc%5D%0A%23%23%20Synchronized%20%E5%85%B3%E9%94%AE%E5%AD%97%E4%BD%BF%E7%94%A8%E3%80%81%E5%BA%95%E5%B1%82%E5%8E%9F%E7%90%86%E3%80%81JDK1.6%20%E4%B9%8B%E5%90%8E%E7%9A%84%E5%BA%95%E5%B1%82%E4%BC%98%E5%8C%96%E4%BB%A5%E5%8F%8A%20%E5%92%8CReenTrantLock%20%E7%9A%84%E5%AF%B9%E6%AF%94%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/ea89d2d9-ebc9-4310-990b-067c26f54c8b/69efd701-83a6-4340-8219-98568ef4f91b.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F1091%3A1)%0A%0A%23%23%23%201.%20synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E6%9C%80%E4%B8%BB%E8%A6%81%E7%9A%84%E4%B8%89%E7%A7%8D%E4%BD%BF%E7%94%A8%E6%96%B9%E5%BC%8F%E7%9A%84%E6%80%BB%E7%BB%93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20static%20%E8%A1%A8%E6%98%8E%E8%BF%99%E6%98%AF%E8%AF%A5%E7%B1%BB%E7%9A%84%E4%B8%80%E4%B8%AA%E9%9D%99%E6%80%81%E8%B5%84%E6%BA%90%EF%BC%8C%E4%B8%8D%E7%AE%A1new%E4%BA%86%E5%A4%9A%E5%B0%91%E4%B8%AA%E5%AF%B9%E8%B1%A1%EF%BC%8C%E5%8F%AA%E6%9C%89%E4%B8%80%E4%BB%BD%EF%BC%8C%E6%89%80%E4%BB%A5%E5%AF%B9%E8%AF%A5%E7%B1%BB%E7%9A%84%E6%89%80%E6%9C%89%E5%AF%B9%E8%B1%A1%E9%83%BD%E5%8A%A0%E4%BA%86%E9%94%81%EF%BC%89%E3%80%82%E6%89%80%E4%BB%A5%E5%A6%82%E6%9E%9C%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8BA%E8%B0%83%E7%94%A8%E4%B8%80%E4%B8%AA%E5%AE%9E%E4%BE%8B%E5%AF%B9%E8%B1%A1%E7%9A%84%E9%9D%9E%E9%9D%99%E6%80%81%20synchronized%20%E6%96%B9%E6%B3%95%EF%BC%8C%E8%80%8C%E7%BA%BF%E7%A8%8BB%E9%9C%80%E8%A6%81%E8%B0%83%E7%94%A8%E8%BF%99%E4%B8%AA%E5%AE%9E%E4%BE%8B%E5%AF%B9%E8%B1%A1%E6%89%80%E5%B1%9E%E7%B1%BB%E7%9A%84%E9%9D%99%E6%80%81%20synchronized%20%E6%96%B9%E6%B3%95%EF%BC%8C%E6%98%AF%E5%85%81%E8%AE%B8%E7%9A%84%EF%BC%8C%E4%B8%8D%E4%BC%9A%E5%8F%91%E7%94%9F%E4%BA%92%E6%96%A5%E7%8E%B0%E8%B1%A1%EF%BC%8C%E5%9B%A0%E4%B8%BA%E8%AE%BF%E9%97%AE%E9%9D%99%E6%80%81%20synchronized%20%E6%96%B9%E6%B3%95%E5%8D%A0%E7%94%A8%E7%9A%84%E9%94%81%E6%98%AF%E5%BD%93%E5%89%8D%E7%B1%BB%E7%9A%84%E9%94%81%EF%BC%8C%E8%80%8C%E8%AE%BF%E9%97%AE%E9%9D%9E%E9%9D%99%E6%80%81%20synchronized%20%E6%96%B9%E6%B3%95%E5%8D%A0%E7%94%A8%E7%9A%84%E9%94%81%E6%98%AF%E5%BD%93%E5%89%8D%E5%AE%9E%E4%BE%8B%E5%AF%B9%E8%B1%A1%E9%94%81%E3%80%82%0A*%20**%E4%BF%AE%E9%A5%B0%E4%BB%A3%E7%A0%81%E5%9D%97%EF%BC%8C%E6%8C%87%E5%AE%9A%E5%8A%A0%E9%94%81%E5%AF%B9%E8%B1%A1%EF%BC%8C%E5%AF%B9%E7%BB%99%E5%AE%9A%E5%AF%B9%E8%B1%A1%E5%8A%A0%E9%94%81%EF%BC%8C%E8%BF%9B%E5%85%A5%E5%90%8C%E6%AD%A5%E4%BB%A3%E7%A0%81%E5%9D%97%E5%89%8D%E8%A6%81%E8%8E%B7%E5%BE%97%E7%BB%99%E5%AE%9A%E5%AF%B9%E8%B1%A1%E7%9A%84%E9%94%81**%E3%80%82%C2%A0%E5%92%8C%20synchronized%20%E6%96%B9%E6%B3%95%E4%B8%80%E6%A0%B7%EF%BC%8Csynchronized(this)%E4%BB%A3%E7%A0%81%E5%9D%97%E4%B9%9F%E6%98%AF%E9%94%81%E5%AE%9A%E5%BD%93%E5%89%8D%E5%AF%B9%E8%B1%A1%E7%9A%84%E3%80%82synchronized%20%E5%85%B3%E9%94%AE%E5%AD%97%E5%8A%A0%E5%88%B0%20static%20%E9%9D%99%E6%80%81%E6%96%B9%E6%B3%95%E5%92%8C%20synchronized(class)%E4%BB%A3%E7%A0%81%E5%9D%97%E4%B8%8A%E9%83%BD%E6%98%AF%E6%98%AF%E7%BB%99%20Class%20%E7%B1%BB%E4%B8%8A%E9%94%81%E3%80%82%0A*%20%E8%BF%99%E9%87%8C%E5%86%8D%E6%8F%90%E4%B8%80%E4%B8%8B%EF%BC%9Asynchronized%E5%85%B3%E9%94%AE%E5%AD%97%E5%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E5%AE%89%E5%85%A8%EF%BC%89%0A%60%60%60java%0Apublic%20class%20Singleton%20%7B%0A%0A%20%20%20%20private%20volatile%20static%20Singleton%20uniqueInstance%3B%0A%0A%20%20%20%20private%20Singleton()%20%7B%0A%20%20%20%20%7D%0A%0A%20%20%20%20public%20static%20Singleton%20getUniqueInstance()%20%7B%0A%20%20%20%20%20%20%20%2F%2F%E5%85%88%E5%88%A4%E6%96%AD%E5%AF%B9%E8%B1%A1%E6%98%AF%E5%90%A6%E5%B7%B2%E7%BB%8F%E5%AE%9E%E4%BE%8B%E8%BF%87%EF%BC%8C%E6%B2%A1%E6%9C%89%E5%AE%9E%E4%BE%8B%E5%8C%96%E8%BF%87%E6%89%8D%E8%BF%9B%E5%85%A5%E5%8A%A0%E9%94%81%E4%BB%A3%E7%A0%81%0A%20%20%20%20%20%20%20%20if%20(uniqueInstance%20%3D%3D%20null)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%E7%B1%BB%E5%AF%B9%E8%B1%A1%E5%8A%A0%E9%94%81%0A%20%20%20%20%20%20%20%20%20%20%20%20synchronized%20(Singleton.class)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20(uniqueInstance%20%3D%3D%20null)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20uniqueInstance%20%3D%20new%20Singleton()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20return%20uniqueInstance%3B%0A%20%20%20%20%7D%0A%7D%0A%60%60%60%0A%E9%9C%80%E8%A6%81%E6%B3%A8%E6%84%8F%20uniqueInstance%20%E9%87%87%E7%94%A8%20static%20%E5%85%B3%E9%94%AE%E5%AD%97%E4%BF%AE%E9%A5%B0%E4%B9%9F%E6%98%AF%E5%BE%88%E6%9C%89%E5%BF%85%E8%A6%81%E3%80%82%0AuniqueInstance%20%E9%87%87%E7%94%A8%20volatile%20%E5%85%B3%E9%94%AE%E5%AD%97%E4%BF%AE%E9%A5%B0%E4%B9%9F%E6%98%AF%E5%BE%88%E6%9C%89%E5%BF%85%E8%A6%81%E7%9A%84%EF%BC%8C%0AuniqueInstance%20%3D%20new%20Singleton()%3B%20%E8%BF%99%E6%AE%B5%E4%BB%A3%E7%A0%81%E5%85%B6%E5%AE%9E%E6%98%AF%E5%88%86%E4%B8%BA%E4%B8%89%E6%AD%A5%E6%89%A7%E8%A1%8C%EF%BC%9A%0A%3E1.%20%E4%B8%BA%20uniqueInstance%20%E5%88%86%E9%85%8D%E5%86%85%E5%AD%98%E7%A9%BA%E9%97%B4%0A%3E2.%20%E5%88%9D%E5%A7%8B%E5%8C%96%20uniqueInstance%0A%3E3.%20%E5%B0%86%20uniqueInstance%20%E6%8C%87%E5%90%91%E5%88%86%E9%85%8D%E7%9A%84%E5%86%85%E5%AD%98%E5%9C%B0%E5%9D%80%0A%0A%E4%BD%86%E6%98%AF%E7%94%B1%E4%BA%8E%20**JVM**%20%E5%85%B7%E6%9C%89**%E6%8C%87%E4%BB%A4%E9%87%8D%E6%8E%92**%E7%9A%84%E7%89%B9%E6%80%A7%EF%BC%8C%E6%89%A7%E8%A1%8C%E9%A1%BA%E5%BA%8F%E6%9C%89%E5%8F%AF%E8%83%BD%E5%8F%98%E6%88%90%201-%3E3-%3E2%E3%80%82%E6%8C%87%E4%BB%A4%E9%87%8D%E6%8E%92%E5%9C%A8%E5%8D%95%E7%BA%BF%E7%A8%8B%E7%8E%AF%E5%A2%83%E4%B8%8B%E4%B8%8D%E4%BC%9A%E5%87%BA%E5%85%88%E9%97%AE%E9%A2%98%EF%BC%8C%E4%BD%86%E6%98%AF%E5%9C%A8%E5%A4%9A%E7%BA%BF%E7%A8%8B%E7%8E%AF%E5%A2%83%E4%B8%8B%E4%BC%9A%E5%AF%BC%E8%87%B4%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%E8%8E%B7%E5%BE%97%E8%BF%98%E6%B2%A1%E6%9C%89%E5%88%9D%E5%A7%8B%E5%8C%96%E7%9A%84%E5%AE%9E%E4%BE%8B%E3%80%82%E4%BE%8B%E5%A6%82%EF%BC%8C%E7%BA%BF%E7%A8%8B%20T1%20%E6%89%A7%E8%A1%8C%E4%BA%86%201%20%E5%92%8C%203%EF%BC%8C%E6%AD%A4%E6%97%B6%20T2%20%E8%B0%83%E7%94%A8%20getUniqueInstance()%20%E5%90%8E%E5%8F%91%E7%8E%B0%20uniqueInstance%20%E4%B8%8D%E4%B8%BA%E7%A9%BA%EF%BC%8C%E5%9B%A0%E6%AD%A4%E8%BF%94%E5%9B%9E%20uniqueInstance%EF%BC%8C%E4%BD%86%E6%AD%A4%E6%97%B6%20uniqueInstance%20%E8%BF%98%E6%9C%AA%E8%A2%AB%E5%88%9D%E5%A7%8B%E5%8C%96%E3%80%82%0A%0A**%E4%BD%BF%E7%94%A8%20volatile%20%E5%8F%AF%E4%BB%A5%E7%A6%81%E6%AD%A2%20JVM%20%E7%9A%84%E6%8C%87%E4%BB%A4%E9%87%8D%E6%8E%92%EF%BC%8C%E4%BF%9D%E8%AF%81%E5%9C%A8%E5%A4%9A%E7%BA%BF%E7%A8%8B%E7%8E%AF%E5%A2%83%E4%B8%8B%E4%B9%9F%E8%83%BD%E6%AD%A3%E5%B8%B8%E8%BF%90%E8%A1%8C%E3%80%82**%0A%0A%23%23%23%202.%20synchronized%20%E5%85%B3%E9%94%AE%E5%AD%97%E5%BA%95%E5%B1%82%E5%8E%9F%E7%90%86%E6%80%BB%E7%BB%93%0A**synchronized%20%E5%85%B3%E9%94%AE%E5%AD%97%E5%BA%95%E5%B1%82%E5%8E%9F%E7%90%86%E5%B1%9E%E4%BA%8E%20JVM%20%E5%B1%82%E9%9D%A2%E3%80%82**%0A%0A%23%23%23%23%202.1%20synchronized%20%E5%90%8C%E6%AD%A5%E8%AF%AD%E5%8F%A5%E5%9D%97%E7%9A%84%E6%83%85%E5%86%B5%0A%60%60%60java%0Apublic%20class%20SynchronizedDemo%20%7B%0A%20%20%20%20public%20void%20method()%20%7B%20%0A%20%20%20%20synchronized%20(this)%20%7B%20%0A%20%20%20%20%20%20%20%20System.out.println(%22synchronized%20%E4%BB%A3%E7%A0%81%E5%9D%97%22)%3B%20%0A%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%20%0A%7D%0A%60%60%60%0A%3E%E9%80%9A%E8%BF%87%20JDK%20%E8%87%AA%E5%B8%A6%E7%9A%84%20javap%20%E5%91%BD%E4%BB%A4%E6%9F%A5%E7%9C%8B%20SynchronizedDemo%20%E7%B1%BB%E7%9A%84%E7%9B%B8%E5%85%B3%E5%AD%97%E8%8A%82%E7%A0%81%E4%BF%A1%E6%81%AF%EF%BC%9A%E9%A6%96%E5%85%88%E5%88%87%E6%8D%A2%E5%88%B0%E7%B1%BB%E7%9A%84%E5%AF%B9%E5%BA%94%E7%9B%AE%E5%BD%95%E6%89%A7%E8%A1%8C%20%60javac%20SynchronizedDemo.java%60%20%E5%91%BD%E4%BB%A4%E7%94%9F%E6%88%90%E7%BC%96%E8%AF%91%E5%90%8E%E7%9A%84%20.class%20%E6%96%87%E4%BB%B6%EF%BC%8C%E7%84%B6%E5%90%8E%E6%89%A7%E8%A1%8C%60javap%20-c%20-s%20-v%20-l%20SynchronizedDemo.class%60%20%0A%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/ea89d2d9-ebc9-4310-990b-067c26f54c8b/5ba730e3-347a-4014-a904-05ea59a1f88d.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F1093%3A1)%0A%3E**synchronized%20%E5%90%8C%E6%AD%A5%E8%AF%AD%E5%8F%A5%E5%9D%97%E7%9A%84%E5%AE%9E%E7%8E%B0%E4%BD%BF%E7%94%A8%E7%9A%84%E6%98%AF%20monitorenter%20%E5%92%8C%20monitorexit%20%E6%8C%87%E4%BB%A4**%EF%BC%8C%E5%85%B6%E4%B8%AD%20**monitorenter%20%E6%8C%87%E4%BB%A4%E6%8C%87%E5%90%91%E5%90%8C%E6%AD%A5%E4%BB%A3%E7%A0%81%E5%9D%97%E7%9A%84%E5%BC%80%E5%A7%8B%E4%BD%8D%E7%BD%AE**%EF%BC%8C**monitorexit%20%E6%8C%87%E4%BB%A4%E5%88%99%E6%8C%87%E6%98%8E%E5%90%8C%E6%AD%A5%E4%BB%A3%E7%A0%81%E5%9D%97%E7%9A%84%E7%BB%93%E6%9D%9F%E4%BD%8D%E7%BD%AE**%E3%80%82%20%0A%3E%E5%BD%93%E6%89%A7%E8%A1%8C%20monitorenter%20%E6%8C%87%E4%BB%A4%E6%97%B6%EF%BC%8C%E7%BA%BF%E7%A8%8B%E8%AF%95%E5%9B%BE%E8%8E%B7%E5%8F%96%E9%94%81%E4%B9%9F%E5%B0%B1%E6%98%AF%E8%8E%B7%E5%8F%96%20monitor(monitor%E5%AF%B9%E8%B1%A1%E5%AD%98%E5%9C%A8%E4%BA%8E%E6%AF%8F%E4%B8%AAJava%E5%AF%B9%E8%B1%A1%E7%9A%84%E5%AF%B9%E8%B1%A1%E5%A4%B4%E4%B8%AD%EF%BC%8Csynchronized%20%E9%94%81%E4%BE%BF%E6%98%AF%E9%80%9A%E8%BF%87%E8%BF%99%E7%A7%8D%E6%96%B9%E5%BC%8F%E8%8E%B7%E5%8F%96%E9%94%81%E7%9A%84%EF%BC%8C%E4%B9%9F%E6%98%AF%E4%B8%BA%E4%BB%80%E4%B9%88Java%E4%B8%AD%E4%BB%BB%E6%84%8F%E5%AF%B9%E8%B1%A1%E5%8F%AF%E4%BB%A5%E4%BD%9C%E4%B8%BA%E9%94%81%E7%9A%84%E5%8E%9F%E5%9B%A0)%20%E7%9A%84%E6%8C%81%E6%9C%89%E6%9D%83.%E5%BD%93%E8%AE%A1%E6%95%B0%E5%99%A8%E4%B8%BA0%E5%88%99%E5%8F%AF%E4%BB%A5%E6%88%90%E5%8A%9F%E8%8E%B7%E5%8F%96%EF%BC%8C%E8%8E%B7%E5%8F%96%E5%90%8E%E5%B0%86%E9%94%81%E8%AE%A1%E6%95%B0%E5%99%A8%E8%AE%BE%E4%B8%BA1%E4%B9%9F%E5%B0%B1%E6%98%AF%E5%8A%A01%E3%80%82%E7%9B%B8%E5%BA%94%E7%9A%84%E5%9C%A8%E6%89%A7%E8%A1%8C%20monitorexit%20%E6%8C%87%E4%BB%A4%E5%90%8E%EF%BC%8C%E5%B0%86%E9%94%81%E8%AE%A1%E6%95%B0%E5%99%A8%E8%AE%BE%E4%B8%BA0%EF%BC%8C%E8%A1%A8%E6%98%8E%E9%94%81%E8%A2%AB%E9%87%8A%E6%94%BE%E3%80%82%E5%A6%82%E6%9E%9C%E8%8E%B7%E5%8F%96%E5%AF%B9%E8%B1%A1%E9%94%81%E5%A4%B1%E8%B4%A5%EF%BC%8C%E9%82%A3%E5%BD%93%E5%89%8D%E7%BA%BF%E7%A8%8B%E5%B0%B1%E8%A6%81%E9%98%BB%E5%A1%9E%E7%AD%89%E5%BE%85%EF%BC%8C%E7%9B%B4%E5%88%B0%E9%94%81%E8%A2%AB%E5%8F%A6%E5%A4%96%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%E9%87%8A%E6%94%BE%E4%B8%BA%E6%AD%A2%E3%80%82%0A%0A%23%23%23%23%202.2%20synchronized%20%E4%BF%AE%E9%A5%B0%E6%96%B9%E6%B3%95%E7%9A%84%E7%9A%84%E6%83%85%E5%86%B5%0A%60%60%60java%0A%0Apublic%20class%20SynchronizedDemo2%20%7B%20%0A%20%20%20%20public%20synchronized%20void%20method()%20%7B%20%0A%20%20%20%20%20%20%20%20System.out.println(%22synchronized%20%E6%96%B9%E6%B3%95%22)%3B%20%0A%20%20%20%20%20%20%20%20%7D%20%0A%20%20%20%20%7D%0A%60%60%60%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/ea89d2d9-ebc9-4310-990b-067c26f54c8b/fadc424f-b564-447d-aeca-bc09411c32dc.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F1095%3A1)%0A%0A%3E**synchronized%20%E4%BF%AE%E9%A5%B0%E7%9A%84%E6%96%B9%E6%B3%95**%E5%B9%B6%E6%B2%A1%E6%9C%89%20monitorenter%20%E6%8C%87%E4%BB%A4%E5%92%8C%20monitorexit%20%E6%8C%87%E4%BB%A4%EF%BC%8C%E5%8F%96%E5%BE%97%E4%BB%A3%E4%B9%8B%E7%9A%84%E6%98%AF%20**ACC_SYNCHRONIZED%20%E6%A0%87%E8%AF%86**%EF%BC%8C%E8%AF%A5%E6%A0%87%E8%AF%86%E6%8C%87%E6%98%8E%E4%BA%86%E8%AF%A5%E6%96%B9%E6%B3%95%E6%98%AF%E4%B8%80%E4%B8%AA%E5%90%8C%E6%AD%A5%E6%96%B9%E6%B3%95%EF%BC%8CJVM%20%E9%80%9A%E8%BF%87%E8%AF%A5%20ACC_SYNCHRONIZED%20%E8%AE%BF%E9%97%AE%E6%A0%87%E5%BF%97%E6%9D%A5%E8%BE%A8%E5%88%AB%E4%B8%80%E4%B8%AA%E6%96%B9%E6%B3%95%E6%98%AF%E5%90%A6%E5%A3%B0%E6%98%8E%E4%B8%BA%E5%90%8C%E6%AD%A5%E6%96%B9%E6%B3%95%EF%BC%8C%E4%BB%8E%E8%80%8C%E6%89%A7%E8%A1%8C%E7%9B%B8%E5%BA%94%E7%9A%84%E5%90%8C%E6%AD%A5%E8%B0%83%E7%94%A8%E3%80%82%0A%0A%0A%23%23%23%203.%20JDK1.6%20%E4%B9%8B%E5%90%8E%E7%9A%84%E5%BA%95%E5%B1%82%E4%BC%98%E5%8C%96%0A%0A%23%23%23%23%203.1%20JDK1.6%E4%B9%8B%E5%89%8D%0A*%20%E5%9C%A8%20Java%20%E6%97%A9%E6%9C%9F%E7%89%88%E6%9C%AC%E4%B8%AD%EF%BC%8Csynchronized%20%E5%B1%9E%E4%BA%8E%E9%87%8D%E9%87%8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%E5%AF%B9%E6%AF%94%E8%BE%83%E9%95%BF%E7%9A%84%E6%97%B6%E9%97%B4%EF%BC%8C%E6%97%B6%E9%97%B4%E6%88%90%E6%9C%AC%E7%9B%B8%E5%AF%B9%E8%BE%83%E9%AB%98%EF%BC%8C%E8%BF%99%E4%B9%9F%E6%98%AF%E4%B8%BA%E4%BB%80%E4%B9%88%E6%97%A9%E6%9C%9F%E7%9A%84%20synchronized%20%E6%95%88%E7%8E%87%E4%BD%8E%E7%9A%84%E5%8E%9F%E5%9B%A0%E3%80%82%0A*%20%E5%BA%86%E5%B9%B8%E7%9A%84%E6%98%AF%E5%9C%A8%20Java%206%20%E4%B9%8B%E5%90%8E%20Java%20%E5%AE%98%E6%96%B9%E5%AF%B9%E4%BB%8E%20JVM%20%E5%B1%82%E9%9D%A2%E5%AF%B9synchronized%20%E8%BE%83%E5%A4%A7%E4%BC%98%E5%8C%96%EF%BC%8C%E6%89%80%E4%BB%A5%E7%8E%B0%E5%9C%A8%E7%9A%84%20synchronized%20%E9%94%81%E6%95%88%E7%8E%87%E4%B9%9F%E4%BC%98%E5%8C%96%E5%BE%97%E5%BE%88%E4%B8%8D%E9%94%99%E4%BA%86%E3%80%82JDK1.6%E5%AF%B9%E9%94%81%E7%9A%84%E5%AE%9E%E7%8E%B0%E5%BC%95%E5%85%A5%E4%BA%86%E5%A4%A7%E9%87%8F%E7%9A%84%E4%BC%98%E5%8C%96%EF%BC%8C%E5%A6%82%E8%87%AA%E6%97%8B%E9%94%81%E3%80%81%E9%80%82%E5%BA%94%E6%80%A7%E8%87%AA%E6%97%8B%E9%94%81%E3%80%81%E9%94%81%E6%B6%88%E9%99%A4%E3%80%81%E9%94%81%E7%B2%97%E5%8C%96%E3%80%81%E5%81%8F%E5%90%91%E9%94%81%E3%80%81%E8%BD%BB%E9%87%8F%E7%BA%A7%E9%94%81%E7%AD%89%E6%8A%80%E6%9C%AF%E6%9D%A5%E5%87%8F%E5%B0%91%E9%94%81%E6%93%8D%E4%BD%9C%E7%9A%84%E5%BC%80%E9%94%80%E3%80%82%0A%0A%23%23%23%23%203.2%20JDK1.6%20%E4%B9%8B%E5%90%8E%0AJDK1.6%20%E5%AF%B9%E9%94%81%E7%9A%84%E5%AE%9E%E7%8E%B0%E5%BC%95%E5%85%A5%E4%BA%86%E5%A4%A7%E9%87%8F%E7%9A%84%E4%BC%98%E5%8C%96%EF%BC%8C%E5%A6%82%E5%81%8F%E5%90%91%E9%94%81%E3%80%81%E8%BD%BB%E9%87%8F%E7%BA%A7%E9%94%81%E3%80%81%E8%87%AA%E6%97%8B%E9%94%81%E3%80%81%E9%80%82%E5%BA%94%E6%80%A7%E8%87%AA%E6%97%8B%E9%94%81%E3%80%81%E9%94%81%E6%B6%88%E9%99%A4%E3%80%81%E9%94%81%E7%B2%97%E5%8C%96%E7%AD%89%E6%8A%80%E6%9C%AF%E6%9D%A5%E5%87%8F%E5%B0%91%E9%94%81%E6%93%8D%E4%BD%9C%E7%9A%84%E5%BC%80%E9%94%80%E3%80%82%0A%0A%23%23%23%23%23%20%E9%94%81%E7%9A%84%E7%8A%B6%E6%80%81%0A%E9%94%81%E4%B8%BB%E8%A6%81%E5%AD%98%E5%9C%A8%E5%9B%9B%E4%B8%AD%E7%8A%B6%E6%80%81%EF%BC%8C%E4%BE%9D%E6%AC%A1%E6%98%AF%EF%BC%9A%E6%97%A0%E9%94%81%E7%8A%B6%E6%80%81%E3%80%81%E5%81%8F%E5%90%91%E9%94%81%E7%8A%B6%E6%80%81%E3%80%81%E8%BD%BB%E9%87%8F%E7%BA%A7%E9%94%81%E7%8A%B6%E6%80%81%E3%80%81%E9%87%8D%E9%87%8F%E7%BA%A7%E9%94%81%E7%8A%B6%E6%80%81%EF%BC%8C%E4%BB%96%E4%BB%AC%E4%BC%9A%E9%9A%8F%E7%9D%80%E7%AB%9E%E4%BA%89%E7%9A%84%E6%BF%80%E7%83%88%E8%80%8C%E9%80%90%E6%B8%90%E5%8D%87%E7%BA%A7%E3%80%82%E6%B3%A8%E6%84%8F%E9%94%81%E5%8F%AF%E4%BB%A5%E5%8D%87%E7%BA%A7%E4%B8%8D%E5%8F%AF%E9%99%8D%E7%BA%A7%EF%BC%8C%E8%BF%99%E7%A7%8D%E7%AD%96%E7%95%A5%E6%98%AF%E4%B8%BA%E4%BA%86%E6%8F%90%E9%AB%98%E8%8E%B7%E5%BE%97%E9%94%81%E5%92%8C%E9%87%8A%E6%94%BE%E9%94%81%E7%9A%84%E6%95%88%E7%8E%87%E3%80%82%0A%0A%23%23%23%23%23%201.%20%E5%81%8F%E5%90%91%E9%94%81%0A%0A1.%20%E5%BC%95%E5%85%A5%E5%81%8F%E5%90%91%E9%94%81%E7%9A%84%E7%9B%AE%E7%9A%84%E5%92%8C%E5%BC%95%E5%85%A5%E8%BD%BB%E9%87%8F%E7%BA%A7%E9%94%81%E7%9A%84%E7%9B%AE%E7%9A%84%E5%BE%88%E5%83%8F%EF%BC%8C%E4%BB%96%E4%BB%AC%E9%83%BD%E6%98%AF**%E4%B8%BA%E4%BA%86%E6%B2%A1%E6%9C%89%E5%A4%9A%E7%BA%BF%E7%A8%8B%E7%AB%9E%E4%BA%89%E7%9A%84%E5%89%8D%E6%8F%90%E4%B8%8B%EF%BC%8C%E5%87%8F%E5%B0%91%E4%BC%A0%E7%BB%9F%E7%9A%84%E9%87%8D%E9%87%8F%E7%BA%A7%E9%94%81%E4%BD%BF%E7%94%A8%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E4%BA%92%E6%96%A5%E9%87%8F%E4%BA%A7%E7%94%9F%E7%9A%84%E6%80%A7%E8%83%BD%E6%B6%88%E8%80%97**%E3%80%82%0A%E4%BD%86%E6%98%AF%E4%B8%8D%E5%90%8C%E6%98%AF%EF%BC%9A%0A%E8%BD%BB%E9%87%8F%E7%BA%A7%E9%94%81%E5%9C%A8%E6%97%A0%E7%AB%9E%E4%BA%89%E7%9A%84%E6%83%85%E5%86%B5%E4%B8%8B%E4%BD%BF%E7%94%A8%20C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A8%E6%97%B6%E9%97%B4%E3%80%82%E5%A6%82%E6%9E%9C%E9%94%81%E8%A2%AB%E5%8D%A0%E7%94%A8%E7%9A%84%E6%97%B6%E9%97%B4%E7%9F%AD%EF%BC%8C%E9%82%A3%E4%B9%88%E6%95%88%E6%9E%9C%E5%BD%93%E7%84%B6%E5%B0%B1%E5%BE%88%E5%A5%BD%E4%BA%86%EF%BC%81%E5%8F%8D%E4%B9%8B%EF%BC%8C%E7%9B%B8%E5%8F%8D%EF%BC%81%E8%87%AA%E6%97%8B%E7%AD%89%E5%BE%85%E7%9A%84%E6%97%B6%E9%97%B4%E5%BF%85%E9%A1%BB%E8%A6%81%E6%9C%89%E9%99%90%E5%BA%A6%E3%80%82%E5%A6%82%E6%9E%9C%E8%87%AA%E6%97%8B%E8%B6%85%E8%BF%87%E4%BA%86%E9%99%90%E5%AE%9A%E6%AC%A1%E6%95%B0%E4%BB%BB%E7%84%B6%E6%B2%A1%E6%9C%89%E8%8E%B7%E5%BE%97%E9%94%81%EF%BC%8C%E5%B0%B1%E5%BA%94%E8%AF%A5%E6%8C%82%E8%B5%B7%E7%BA%BF%E7%A8%8B%E3%80%82%E8%87%AA%E6%97%8B%E6%AC%A1%E6%95%B0%E7%9A%84%E9%BB%98%E8%AE%A4%E5%80%BC%E6%98%AF10%E6%AC%A1%EF%BC%8C%E7%94%A8%E6%88%B7%E5%8F%AF%E4%BB%A5%E4%BF%AE%E6%94%B9--XX%3APreBlockSpin%E6%9D%A5%E6%9B%B4%E6%94%B9%E3%80%82%0A6.%20%E5%8F%A6%E5%A4%96%2C%E5%9C%A8%20JDK1.6%20%E4%B8%AD%E5%BC%95%E5%85%A5%E4%BA%86%E8%87%AA%E9%80%82%E5%BA%94%E7%9A%84%E8%87%AA%E6%97%8B%E9%94%81%E3%80%82**%E8%87%AA%E9%80%82%E5%BA%94%E7%9A%84%E8%87%AA%E6%97%8B%E9%94%81**%E5%B8%A6%E6%9D%A5%E7%9A%84%E6%94%B9%E8%BF%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%86%B5%E4%B8%8B%EF%BC%8C%E4%B8%8A%E9%9D%A2%E7%9A%84%E5%8E%9F%E5%88%99%E9%83%BD%E6%98%AF%E6%B2%A1%E6%9C%89%E9%97%AE%E9%A2%98%E7%9A%84%EF%BC%8C%E4%BD%86%E6%98%AF%E5%A6%82%E6%9E%9C%E4%B8%80%E7%B3%BB%E5%88%97%E7%9A%84%E8%BF%9E%E7%BB%AD%E6%93%8D%E4%BD%9C%E9%83%BD%E5%AF%B9%E5%90%8C%E4%B8%80%E4%B8%AA%E5%AF%B9%E8%B1%A1%E5%8F%8D%E5%A4%8D%E5%8A%A0%E9%94%81%E5%92%8C%E8%A7%A3%E9%94%81%EF%BC%8C%E9%82%A3%E4%B9%88%E4%BC%9A%E5%B8%A6%E6%9D%A5%E5%BE%88%E5%A4%9A%E4%B8%8D%E5%BF%85%E8%A6%81%E7%9A%84%E6%80%A7%E8%83%BD%E6%B6%88%E8%80%97%E3%80%82%0A%0A%23%23%23%204.%20Synchronized%20%E5%92%8C%20ReenTrantLock%20%E7%9A%84%E5%AF%B9%E6%AF%94%0A%23%23%23%23%204.1%20%C2%A0%E4%B8%A4%E8%80%85%E9%83%BD%E6%98%AF%E5%8F%AF%E9%87%8D%E5%85%A5%E9%94%81%0A%E4%B8%A4%E8%80%85%E9%83%BD%E6%98%AF%E5%8F%AF%E9%87%8D%E5%85%A5%E9%94%81%E3%80%82%E2%80%9C%E5%8F%AF%E9%87%8D%E5%85%A5%E9%94%81%E2%80%9D%E6%A6%82%E5%BF%B5%E6%98%AF%EF%BC%9A%E8%87%AA%E5%B7%B1%E5%8F%AF%E4%BB%A5%E5%86%8D%E6%AC%A1%E8%8E%B7%E5%8F%96%E8%87%AA%E5%B7%B1%E7%9A%84%E5%86%85%E9%83%A8%E9%94%81%E3%80%82%E6%AF%94%E5%A6%82%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%E8%8E%B7%E5%BE%97%E4%BA%86%E6%9F%90%E4%B8%AA%E5%AF%B9%E8%B1%A1%E7%9A%84%E9%94%81%EF%BC%8C%E6%AD%A4%E6%97%B6%E8%BF%99%E4%B8%AA%E5%AF%B9%E8%B1%A1%E9%94%81%E8%BF%98%E6%B2%A1%E6%9C%89%E9%87%8A%E6%94%BE%EF%BC%8C%E5%BD%93%E5%85%B6%E5%86%8D%E6%AC%A1%E6%83%B3%E8%A6%81%E8%8E%B7%E5%8F%96%E8%BF%99%E4%B8%AA%E5%AF%B9%E8%B1%A1%E7%9A%84%E9%94%81%E7%9A%84%E6%97%B6%E5%80%99%E8%BF%98%E6%98%AF%E5%8F%AF%E4%BB%A5%E8%8E%B7%E5%8F%96%E7%9A%84%EF%BC%8C%E5%A6%82%E6%9E%9C%E4%B8%8D%E5%8F%AF%E9%94%81%E9%87%8D%E5%85%A5%E7%9A%84%E8%AF%9D%EF%BC%8C%E5%B0%B1%E4%BC%9A%E9%80%A0%E6%88%90%E6%AD%BB%E9%94%81%E3%80%82%E5%90%8C%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%E6%AF%8F%E6%AC%A1%E8%8E%B7%E5%8F%96%E9%94%81%EF%BC%8C%E9%94%81%E7%9A%84%E8%AE%A1%E6%95%B0%E5%99%A8%E9%83%BD%E8%87%AA%E5%A2%9E1%EF%BC%8C%E6%89%80%E4%BB%A5%E8%A6%81%E7%AD%89%E5%88%B0%E9%94%81%E7%9A%84%E8%AE%A1%E6%95%B0%E5%99%A8%E4%B8%8B%E9%99%8D%E4%B8%BA0%E6%97%B6%E6%89%8D%E8%83%BD%E9%87%8A%E6%94%BE%E9%94%81%E3%80%82%0A%0A%23%23%23%23%204.2%20synchronized%20%E4%BE%9D%E8%B5%96%E4%BA%8E%20JVM%20%E8%80%8C%20ReenTrantLock%20%E4%BE%9D%E8%B5%96%E4%BA%8E%20API%0Asynchronized%20%E6%98%AF%E4%BE%9D%E8%B5%96%E4%BA%8E%20JVM%20%E5%AE%9E%E7%8E%B0%E7%9A%84%EF%BC%8C%E5%89%8D%E9%9D%A2%E6%88%91%E4%BB%AC%E4%B9%9F%E8%AE%B2%E5%88%B0%E4%BA%86%20%E8%99%9A%E6%8B%9F%E6%9C%BA%E5%9B%A2%E9%98%9F%E5%9C%A8%20JDK1.6%20%E4%B8%BA%20synchronized%20%E5%85%B3%E9%94%AE%E5%AD%97%E8%BF%9B%E8%A1%8C%E4%BA%86%E5%BE%88%E5%A4%9A%E4%BC%98%E5%8C%96%EF%BC%8C%E4%BD%86%E6%98%AF%E8%BF%99%E4%BA%9B%E4%BC%98%E5%8C%96%E9%83%BD%E6%98%AF%E5%9C%A8%E8%99%9A%E6%8B%9F%E6%9C%BA%E5%B1%82%E9%9D%A2%E5%AE%9E%E7%8E%B0%E7%9A%84%EF%BC%8C%E5%B9%B6%E6%B2%A1%E6%9C%89%E7%9B%B4%E6%8E%A5%E6%9A%B4%E9%9C%B2%E7%BB%99%E6%88%91%E4%BB%AC%E3%80%82ReenTrantLock%20%E6%98%AF%20JDK%20%E5%B1%82%E9%9D%A2%E5%AE%9E%E7%8E%B0%E7%9A%84%EF%BC%88%E4%B9%9F%E5%B0%B1%E6%98%AF%20API%20%E5%B1%82%E9%9D%A2%EF%BC%8C%E9%9C%80%E8%A6%81%20lock()%20%E5%92%8C%20unlock%20%E6%96%B9%E6%B3%95%E9%85%8D%E5%90%88%20try%2Ffinally%20%E8%AF%AD%E5%8F%A5%E5%9D%97%E6%9D%A5%E5%AE%8C%E6%88%90%EF%BC%89%EF%BC%8C%E6%89%80%E4%BB%A5%E6%88%91%E4%BB%AC%E5%8F%AF%E4%BB%A5%E9%80%9A%E8%BF%87%E6%9F%A5%E7%9C%8B%E5%AE%83%E7%9A%84%E6%BA%90%E4%BB%A3%E7%A0%81%EF%BC%8C%E6%9D%A5%E7%9C%8B%E5%AE%83%E6%98%AF%E5%A6%82%E4%BD%95%E5%AE%9E%E7%8E%B0%E7%9A%84%E3%80%82%0A%0A%23%23%23%23%204.3%20ReenTrantLock%20%E6%AF%94%20synchronized%20%E5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%80%89%E6%8B%A9%E6%94%BE%E5%BC%83%E7%AD%89%E5%BE%85%EF%BC%8C%E6%94%B9%E4%B8%BA%E5%A4%84%E7%90%86%E5%85%B6%E4%BB%96%E4%BA%8B%E6%83%85%E3%80%82%0A%0A%23%23%23%23%23%20%E5%8F%AF%E5%AE%9E%E7%8E%B0%E5%85%AC%E5%B9%B3%E9%94%81%0AReenTrantLock%E5%8F%AF%E4%BB%A5%E6%8C%87%E5%AE%9A%E6%98%AF%E5%85%AC%E5%B9%B3%E9%94%81%E8%BF%98%E6%98%AF%E9%9D%9E%E5%85%AC%E5%B9%B3%E9%94%81%E3%80%82%E8%80%8Csynchronized%E5%8F%AA%E8%83%BD%E6%98%AF%E9%9D%9E%E5%85%AC%E5%B9%B3%E9%94%81%E3%80%82%E6%89%80%E8%B0%93%E7%9A%84%E5%85%AC%E5%B9%B3%E9%94%81%E5%B0%B1%E6%98%AF%E5%85%88%E7%AD%89%E5%BE%85%E7%9A%84%E7%BA%BF%E7%A8%8B%E5%85%88%E8%8E%B7%E5%BE%97%E9%94%81%E3%80%82%20ReenTrantLock%E9%BB%98%E8%AE%A4%E6%83%85%E5%86%B5%E6%98%AF%E9%9D%9E%E5%85%AC%E5%B9%B3%E7%9A%84%EF%BC%8C%E5%8F%AF%E4%BB%A5%E9%80%9A%E8%BF%87%20ReenTrantLock%E7%B1%BB%E7%9A%84ReentrantLock(boolean%20fair)%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95%E6%9D%A5%E5%88%B6%E5%AE%9A%E6%98%AF%E5%90%A6%E6%98%AF%E5%85%AC%E5%B9%B3%E7%9A%84%E3%80%82%0A%0A%23%23%23%23%23%20%E5%8F%AF%E5%AE%9E%E7%8E%B0%E9%80%89%E6%8B%A9%E6%80%A7%E9%80%9A%E7%9F%A5%0Asynchronized%E5%85%B3%E9%94%AE%E5%AD%97%E4%B8%8Ewait()%E5%92%8Cnotify%2FnotifyAll()%E6%96%B9%E6%B3%95%E7%9B%B8%E7%BB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BF%E7%A8%8B%E9%80%9A%E7%9F%A5%EF%BC%8C%E5%9C%A8%E8%B0%83%E5%BA%A6%E7%BA%BF%E7%A8%8B%E4%B8%8A%E6%9B%B4%E5%8A%A0%E7%81%B5%E6%B4%BB**%E3%80%82%20%E5%9C%A8%E4%BD%BF%E7%94%A8notify%2FnotifyAll()%E6%96%B9%E6%B3%95%E8%BF%9B%E8%A1%8C%E9%80%9A%E7%9F%A5%E6%97%B6%EF%BC%8C%E8%A2%AB%E9%80%9A%E7%9F%A5%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%98%AF%E7%94%B1%20JVM%20%E9%80%89%E6%8B%A9%E7%9A%84%EF%BC%8C%E7%94%A8ReentrantLock%E7%B1%BB%E7%BB%93%E5%90%88Condition%E5%AE%9E%E4%BE%8B%E5%8F%AF%E4%BB%A5%E5%AE%9E%E7%8E%B0%E2%80%9C%E9%80%89%E6%8B%A9%E6%80%A7%E9%80%9A%E7%9F%A5%E2%80%9D%20%EF%BC%8C%E8%BF%99%E4%B8%AA%E5%8A%9F%E8%83%BD%E9%9D%9E%E5%B8%B8%E9%87%8D%E8%A6%81%EF%BC%8C%E8%80%8C%E4%B8%94%E6%98%AFCondition%E6%8E%A5%E5%8F%A3%E9%BB%98%E8%AE%A4%E6%8F%90%E4%BE%9B%E7%9A%84%E3%80%82%E8%80%8Csynchronized%E5%85%B3%E9%94%AE%E5%AD%97%E5%B0%B1%E7%9B%B8%E5%BD%93%E4%BA%8E%E6%95%B4%E4%B8%AALock%E5%AF%B9%E8%B1%A1%E4%B8%AD%E5%8F%AA%E6%9C%89%E4%B8%80%E4%B8%AACondition%E5%AE%9E%E4%BE%8B%EF%BC%8C%E6%89%80%E6%9C%89%E7%9A%84%E7%BA%BF%E7%A8%8B%E9%83%BD%E6%B3%A8%E5%86%8C%E5%9C%A8%E5%AE%83%E4%B8%80%E4%B8%AA%E8%BA%AB%E4%B8%8A%E3%80%82%E5%A6%82%E6%9E%9C%E6%89%A7%E8%A1%8CnotifyAll()%E6%96%B9%E6%B3%95%E7%9A%84%E8%AF%9D%E5%B0%B1%E4%BC%9A%E9%80%9A%E7%9F%A5%E6%89%80%E6%9C%89%E5%A4%84%E4%BA%8E%E7%AD%89%E5%BE%85%E7%8A%B6%E6%80%81%E7%9A%84%E7%BA%BF%E7%A8%8B%E8%BF%99%E6%A0%B7%E4%BC%9A%E9%80%A0%E6%88%90%E5%BE%88%E5%A4%A7%E7%9A%84%E6%95%88%E7%8E%87%E9%97%AE%E9%A2%98%EF%BC%8C%E8%80%8CCondition%E5%AE%9E%E4%BE%8B%E7%9A%84signalAll()%E6%96%B9%E6%B3%95%20%E5%8F%AA%E4%BC%9A%E5%94%A4%E9%86%92%E6%B3%A8%E5%86%8C%E5%9C%A8%E8%AF%A5Condition%E5%AE%9E%E4%BE%8B%E4%B8%AD%E7%9A%84%E6%89%80%E6%9C%89%E7%AD%89%E5%BE%85%E7%BA%BF%E7%A8%8B%E3%80%82%0A%0A%23%23%23%23%204.4%20%E6%80%A7%E8%83%BD%E5%B7%B2%E4%B8%8D%E6%98%AF%E9%80%89%E6%8B%A9%E6%A0%87%E5%87%86%0A1.%20%E5%9C%A8JDK1.6%E4%B9%8B%E5%89%8D%EF%BC%8Csynchronized%20%E7%9A%84%E6%80%A7%E8%83%BD%E6%98%AF%E6%AF%94%20ReenTrantLock%20%E5%B7%AE%E5%BE%88%E5%A4%9A%E3%80%82%E5%85%B7%E4%BD%93%E8%A1%A8%E7%A4%BA%E4%B8%BA%EF%BC%9Asynchronized%20%E5%85%B3%E9%94%AE%E5%AD%97%E5%90%9E%E5%90%90%E9%87%8F%E9%9A%8F%E7%BA%BF%E7%A8%8B%E6%95%B0%E7%9A%84%E5%A2%9E%E5%8A%A0%EF%BC%8C%E4%B8%8B%E9%99%8D%E5%BE%97%E9%9D%9E%E5%B8%B8%E4%B8%A5%E9%87%8D%E3%80%82%E8%80%8CReenTrantLock%20%E5%9F%BA%E6%9C%AC%E4%BF%9D%E6%8C%81%E4%B8%80%E4%B8%AA%E6%AF%94%E8%BE%83%E7%A8%B3%E5%AE%9A%E7%9A%84%E6%B0%B4%E5%B9%B3%E3%80%82%E6%88%91%E8%A7%89%E5%BE%97%E8%BF%99%E4%B9%9F%E4%BE%A7%E9%9D%A2%E5%8F%8D%E6%98%A0%E4%BA%86%EF%BC%8C%20synchronized%20%E5%85%B3%E9%94%AE%E5%AD%97%E8%BF%98%E6%9C%89%E9%9D%9E%E5%B8%B8%E5%A4%A7%E7%9A%84%E4%BC%98%E5%8C%96%E4%BD%99%E5%9C%B0%E3%80%82%E5%90%8E%E7%BB%AD%E7%9A%84%E6%8A%80%E6%9C%AF%E5%8F%91%E5%B1%95%E4%B9%9F%E8%AF%81%E6%98%8E%E4%BA%86%E8%BF%99%E4%B8%80%E7%82%B9%EF%BC%8C%E6%88%91%E4%BB%AC%E4%B8%8A%E9%9D%A2%E4%B9%9F%E8%AE%B2%E4%BA%86%E5%9C%A8%20JDK1.6%20%E4%B9%8B%E5%90%8E%20JVM%20%E5%9B%A2%E9%98%9F%E5%AF%B9%20synchronized%20%E5%85%B3%E9%94%AE%E5%AD%97%E5%81%9A%E4%BA%86%E5%BE%88%E5%A4%9A%E4%BC%98%E5%8C%96%E3%80%82%0A2.%20JDK1.6%20%E4%B9%8B%E5%90%8E%EF%BC%8Csynchronized%20%E5%92%8C%20ReenTrantLock%20%E7%9A%84%E6%80%A7%E8%83%BD%E5%9F%BA%E6%9C%AC%E6%98%AF%E6%8C%81%E5%B9%B3%E4%BA%86%E3%80%82%E6%89%80%E4%BB%A5%E7%BD%91%E4%B8%8A%E9%82%A3%E4%BA%9B%E8%AF%B4%E5%9B%A0%E4%B8%BA%E6%80%A7%E8%83%BD%E6%89%8D%E9%80%89%E6%8B%A9%20ReenTrantLock%20%E7%9A%84%E6%96%87%E7%AB%A0%E9%83%BD%E6%98%AF%E9%94%99%E7%9A%84%EF%BC%81JDK1.6%E4%B9%8B%E5%90%8E%EF%BC%8C%E6%80%A7%E8%83%BD%E5%B7%B2%E7%BB%8F%E4%B8%8D%E6%98%AF%E9%80%89%E6%8B%A9synchronized%E5%92%8CReenTrantLock%E7%9A%84%E5%BD%B1%E5%93%8D%E5%9B%A0%E7%B4%A0%E4%BA%86%EF%BC%81%E8%80%8C%E4%B8%94%E8%99%9A%E6%8B%9F%E6%9C%BA%E5%9C%A8%E6%9C%AA%E6%9D%A5%E7%9A%84%E6%80%A7%E8%83%BD%E6%94%B9%E8%BF%9B%E4%B8%AD%E4%BC%9A%E6%9B%B4%E5%81%8F%E5%90%91%E4%BA%8E%E5%8E%9F%E7%94%9F%E7%9A%84synchronized%EF%BC%8C%E6%89%80%E4%BB%A5%E8%BF%98%E6%98%AF%E6%8F%90%E5%80%A1%E5%9C%A8synchronized%E8%83%BD%E6%BB%A1%E8%B6%B3%E4%BD%A0%E7%9A%84%E9%9C%80%E6%B1%82%E7%9A%84%E6%83%85%E5%86%B5%E4%B8%8B%EF%BC%8C%E4%BC%98%E5%85%88%E8%80%83%E8%99%91%E4%BD%BF%E7%94%A8synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E6%9D%A5%E8%BF%9B%E8%A1%8C%E5%90%8C%E6%AD%A5%EF%BC%81%E4%BC%98%E5%8C%96%E5%90%8E%E7%9A%84synchronized%E5%92%8CReenTrantLock%E4%B8%80%E6%A0%B7%EF%BC%8C%E5%9C%A8%E5%BE%88%E5%A4%9A%E5%9C%B0%E6%96%B9%E9%83%BD%E6%98%AF%E7%94%A8%E5%88%B0%E4%BA%86CAS%E6%93%8D%E4%BD%9C%E3%80%82%0A%0A%0A&lt;/center&gt;&lt;/div&gt;
</content>
  </entry>
  <entry xml:base="http://linzhiteng.postach.io/feed.xml">
    <title type="text">一. 线程入门</title>
    <id>https://linzhiteng.postach.io/post/yi-xian-cheng-ru-men</id>
    <updated>2019-06-09T13:07:38.587000Z</updated>
    <published>2019-03-12T14:24:34Z</published>
    <link href="https://linzhiteng.postach.io/post/yi-xian-cheng-ru-men" />
    <author>
      <name>linzhi teng</name>
    </author>
    <category term="xian-cheng" />
    <content type="html">&lt;div&gt;&lt;div style=&quot;font-size: 14px; margin: 0; padding: 0; width: 100%;&quot;&gt;&lt;div style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;一. 线程入门
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1. 进程和多线程简介
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.1 何为进程？
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.2 何为线程？
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.3 线程和进程的关系
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.4 线程有哪些基本状态？这些状态是如何定义的?
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.5 线程的优先级
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.6 何为多线程？
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.7 为什么多线程是必要的？
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.8 为什么提倡多线程而不是多进程？
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2. 几个重要的概念
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.1 同步和异步
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.2 并发(Concurrency)和并行(Parallelism)
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.3 高并发
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.4 临界区
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.5 阻塞和非阻塞
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3. 多线程
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1 使用多线程常见的三种方式
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.2 Java多线程分类
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.3 如何设置守护线程？
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4. 一些常用方法
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.1 currentThread()
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.2 getId()
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.3 getName()
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.4 getPriority()
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.5 isAlive()
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.6 sleep(long millis)
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.7 interrupt()
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.8 interrupted() 和isInterrupted()
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.9 setName(String name)
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.10 isDaemon()
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.11 setDaemon(boolean on)
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.12 join()
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.13 yield()
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.14 setPriority(int newPriority)
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;一. 线程入门&lt;/h2&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;1. 进程和多线程简介&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.1 何为进程？&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;进程是程序的一次执行过程，是系统运行程序的基本单位，因此进程是动态的。系统运行一个程序即是一个进程从创建，运行到消亡的过程。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;一个进程就是一个执行中的程序，它在计算机中一个指令接着一个指令地执行着，同时，每个进程还占有某些系统资源如CPU时间，内存空间，文件，文件，输入输出设备的使用权等等。换句话说，当程序在执行时，将会被操作系统载入内存中。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;进程属于操作系统的范畴，主要是同一段时间内，可以同时执行一个以上的程序&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.2 何为线程？&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;线程与进程相似，但线程是一个比进程更小的执行单位。一个进程在其执行的过程中可以产生多个线程。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;与进程不同的是&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;同类的多个线程共享同一块内存空间和一组系统资源&lt;/strong&gt;，所以系统在产生一个线程，或是在各个线程之间作切换工作时，负担要比进程小得多，也正因为如此，线程也被称为轻量级进程。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;线程是在同一程序内几乎同时执行一个以上的程序段。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.3 线程和进程的关系&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;基本上各进程是独立的，而各线程则不一定，因为同一进程中的线程极有可能会相互影响。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;从另一角度来说，&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;进程属于操作系统的范畴&lt;/strong&gt;，主要是同一段时间内，可以同时执行一个以上的程序，而&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;线程&lt;/strong&gt;则是在同一程序内几乎同时执行一个以上的&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;程序段&lt;/strong&gt;。&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;线程上下文的切换比进程上下文切换要快很多&lt;/li&gt;
&lt;/ul&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;进程切换时，涉及到当前进程的CPU环境的保存和新被调度运行进程的CPU环境的设置。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;线程切换仅需要保存和设置少量的寄存器内容，不涉及存储管理方面的操作。&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.4 线程有哪些基本状态？这些状态是如何定义的?&lt;/h4&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;新建(new)：新创建了一个线程对象。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;可运行(runnable)：线程对象创建后，其他线程(比如main线程）调用了该对象的start()方法。该状态的线程位于可运行线程池中，等待被线程调度选中，获 取cpu的使用权。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;运行(running)：可运行状态(runnable)的线程获得了cpu时间片（timeslice），执行程序代码。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;阻塞(block)：阻塞状态是指线程因为某种原因放弃了cpu使用权，也即让出了cpu timeslice（时间片），暂时停止运行。直到线程进入可运行(runnable)状态，才有 机会再次获得cpu timeslice转到运行(running)状态。阻塞的情况分三种：&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;(一). 等待阻塞：运行(running)的线程执行o.wait()方法，JVM会把该线程放 入等待队列(waiting queue)中。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;(二). 同步阻塞：运行(running)的线程在获取对象的同步锁时，若该同步 锁 被别的线程占用，则JVM会把该线程放入锁池(lock pool)中。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;(三). 其他阻塞: 运行(running)的线程执行Thread.sleep(long ms)或t.join()方法，或者发出了I/O请求时，JVM会把该线程置为阻塞状态。当sleep()状态超时join()等待线程终止或者超时、或者I/O处理完毕时，线程重新转入可运行(runnable)状态。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;ol start=&quot;5&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;死亡(dead)：线程run()、main()方法执行结束，或者因异常退出了run()方法，则该线程结束生命周期。死亡的线程不可再次复生。&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/84f15188-1d71-4592-9417-c67e4a90da27/76320db7-6318-4292-b3a8-faafb6b6eb49.jpg&quot; /&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.5 线程的优先级&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;每个线程都具有各自的优先级，线程的优先级可以在程序中表明该线程的重要性，如果有很多线程处于就绪状态，系统会根据优先级来决定首先使哪个线程进入运行状态。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;线程优先级具有继承特性比如A线程启动B线程，则B线程的优先级和A是一样的。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;线程优先级具有随机性也就是说线程优先级高的不一定每一次都先执行完。&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;Thread类中包含的成员变量代表了线程的某些优先级。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;如Thread.MIN_PRIORITY（常数1），Thread.NORM_PRIORITY（常数5）,&lt;br/&gt;
Thread.MAX_PRIORITY（常数10）。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;其中每个线程的优先级都在Thread.MIN_PRIORITY（常数1） 到Thread.MAX_PRIORITY（常数10） 之间。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;在默认情况下优先级都是Thread.NORM_PRIORITY（常数5）。&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.6 何为多线程？&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;多线程就是多个线程同时运行或交替运行。单核CPU的话是顺序执行，也就是交替运行。多核CPU的话，因为每个CPU有自己的运算器，所以在多个CPU中可以同时运行。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.7 为什么多线程是必要的？&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;开发高并发系统的基础，利用好多线程机制可以大大提高系统整体的并发能力以及性能&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.8 为什么提倡多线程而不是多进程？&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;线程就是轻量级进程，是程序执行的最小单位。使用多线程而不是用多进程去进行并发程序的设计，是因为线程间的切换和调度的成本远远小于进程。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;2. 几个重要的概念&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.1 同步和异步&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;同步和异步通常用来形容一次&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;方法调用&lt;/strong&gt;。&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;同步方法调用一旦开始，调用者必须等到方法调用返回后，才能继续后续的行为。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;异步方法调用更像一个消息传递，一旦开始，方法调用就会立即返回，调用者可以继续后续的操作。&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.2 并发(Concurrency)和并行(Parallelism)&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;它们都可以表示两个或者多个任务一起执行，但是偏重点有些不同。&lt;br/&gt;
并发偏重于多个任务交替执行，而多个任务之间有可能还是串行的。&lt;br/&gt;
而并行是真正意义上的&quot;同时执行&quot;。&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;多线程在单核CPU的话是顺序执行，也就是&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;交替运行（并发）&lt;/strong&gt;。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;多核CPU的话，因为每个CPU有自己的运算器，所以在多个CPU中可以&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;同时运行（并行）&lt;/strong&gt;。&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.3 高并发&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;高并发（High Concurrency）是互联网分布式系统架构设计中必须考虑的因素之一，它通常是指，通过设计保证系统能够同时并行处理很多请求。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;高并发相关常用的一些指标有响应时间（Response Time），吞吐量（Throughput），每秒查询率QPS（Query Per Second），并发用户数等。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.4 临界区&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;临界区用来表示一种公共资源或者说是&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;共享数据&lt;/strong&gt;，可以&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;被多个线程使用&lt;/strong&gt;。&lt;br/&gt;
但是每一次，只能有一个线程使用它，一旦临界区资源被占用，其他线程要想使用这个资源，就必须&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;等待&lt;/strong&gt;。在并行程序中，临界区资源是保护的对象。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.5 阻塞和非阻塞&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;非阻塞指在不能立刻得到结果之前，该函数不会阻塞当前线程，而会立刻返回，而阻塞与之相反。&lt;/p&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;3. 多线程&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.1 使用多线程常见的三种方式&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;继承Thread类&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;实现Runnable接口&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;使用线程池&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.2 Java多线程分类&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;用户线程&lt;/strong&gt;：运行在前台，执行具体的任务，如程序的主线程、连接网络的子线程等都是用户线程&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;守护线程&lt;/strong&gt;：运行在后台，为其他前台线程服务.也可以说守护线程是JVM中非守护线程的 &quot;佣人&quot;。&lt;br/&gt;
特点：一旦所有用户线程都结束运行，守护线程会随JVM一起结束工作&lt;br/&gt;
应用：数据库连接池中的检测线程，JVM虚拟机启动后的检测线程&lt;br/&gt;
最常见的守护线程：垃圾回收线程&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.3 如何设置守护线程？&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;通过调用Thead类的setDaemon(true)方法设置当前的线程为守护线程&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;1. setDaemon(true)必须在start()方法前执行，否则会抛出IllegalThreadStateException异常 
2.  在守护线程中产生的新线程也是守护线程 
3.  不是所有的任务都可以分配给守护线程来执行，比如读写操作或者计算逻辑
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;4. 一些常用方法&lt;/h4&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.1 currentThread()&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;返回对当前正在执行的线程对象的引用。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.2 getId()&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;返回此线程的标识符&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.3 getName()&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;返回此线程的名称&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.4 getPriority()&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;返回此线程的优先级&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.5 isAlive()&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;测试这个线程是否还处于活动状态。&lt;br/&gt;
什么是活动状态呢？&lt;br/&gt;
活动状态就是线程已经启动且尚未终止。线程处于正在运行或准备运行的状态。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.6 sleep(long millis)&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;使当前正在执行的线程以指定的毫秒数&quot;休眠&quot;（暂时停止执行），具体取决于系统定时器和调度程序的精度和准确性。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.7 interrupt()&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;中断这个线程。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.8 interrupted() 和isInterrupted()&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;interrupted()：测试当前线程是否已经是中断状态，执行后具有将状态标志清除为false的功能&lt;br/&gt;
isInterrupted()： 测试线程Thread对相关是否已经是中断状态，但部清楚状态标志&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.9 setName(String name)&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;将此线程的名称更改为等于参数 name 。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.10 isDaemon()&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;测试这个线程是否是守护线程。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.11 setDaemon(boolean on)&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;将此线程标记为 daemon线程或用户线程。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.12 join()&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;在很多情况下，主线程生成并起动了子线程，如果子线程里要进行大量的耗时的运算，主线程往往将于子线程之前结束，但是如果主线程处理完其他的事务后，需要用到子线程的处理结果，也就是&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;主线程需要等待子线程执行完成之后再结束&lt;/strong&gt;，这个时候就要用到join()方法了。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;join()的作用是：&quot;等待该线程终止&quot;，这里需要理解的就是该线程是指的主线程等待子线程的终止。也就是在子线程调用了join()方法后面的代码，只有等到子线程结束了才能执行&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.13 yield()&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;yield()方法的作用是放弃当前的CPU资源，将它让给其他的任务去占用CPU时间。注意：放弃的时间不确定，可能一会就会重新获得CPU时间片。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.14 setPriority(int newPriority)&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;更改此线程的优先级&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/div&gt;&lt;center style='display:none !important;visibility:collapse !important;height:0 !important;white-space:nowrap;width:100%;overflow:hidden'&gt;%5Btoc%5D%0A%23%23%20%E4%B8%80.%20%E7%BA%BF%E7%A8%8B%E5%85%A5%E9%97%A8%0A%23%23%23%201.%20%E8%BF%9B%E7%A8%8B%E5%92%8C%E5%A4%9A%E7%BA%BF%E7%A8%8B%E7%AE%80%E4%BB%8B%0A%23%23%23%23%201.1%20%E4%BD%95%E4%B8%BA%E8%BF%9B%E7%A8%8B%EF%BC%9F%0A%3E*%20%E8%BF%9B%E7%A8%8B%E6%98%AF%E7%A8%8B%E5%BA%8F%E7%9A%84%E4%B8%80%E6%AC%A1%E6%89%A7%E8%A1%8C%E8%BF%87%E7%A8%8B%EF%BC%8C%E6%98%AF%E7%B3%BB%E7%BB%9F%E8%BF%90%E8%A1%8C%E7%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%A0%E6%94%BE%E5%BC%83%E4%BA%86cpu%E4%BD%BF%E7%94%A8%E6%9D%83%EF%BC%8C%E4%B9%9F%E5%8D%B3%E8%AE%A9%E5%87%BA%E4%BA%86cpu%20timeslice%EF%BC%88%E6%97%B6%E9%97%B4%E7%89%87%EF%BC%89%EF%BC%8C%E6%9A%82%E6%97%B6%E5%81%9C%E6%AD%A2%E8%BF%90%E8%A1%8C%E3%80%82%E7%9B%B4%E5%88%B0%E7%BA%BF%E7%A8%8B%E8%BF%9B%E5%85%A5%E5%8F%AF%E8%BF%90%E8%A1%8C(runnable)%E7%8A%B6%E6%80%81%EF%BC%8C%E6%89%8D%E6%9C%89%20%E6%9C%BA%E4%BC%9A%E5%86%8D%E6%AC%A1%E8%8E%B7%E5%BE%97cpu%20timeslice%E8%BD%AC%E5%88%B0%E8%BF%90%E8%A1%8C(running)%E7%8A%B6%E6%80%81%E3%80%82%E9%98%BB%E5%A1%9E%E7%9A%84%E6%83%85%E5%86%B5%E5%88%86%E4%B8%89%E7%A7%8D%EF%BC%9A%0A%3E*%20(%E4%B8%80).%20%E7%AD%89%E5%BE%85%E9%98%BB%E5%A1%9E%EF%BC%9A%E8%BF%90%E8%A1%8C(running)%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%89%A7%E8%A1%8Co.wait()%E6%96%B9%E6%B3%95%EF%BC%8CJVM%E4%BC%9A%E6%8A%8A%E8%AF%A5%E7%BA%BF%E7%A8%8B%E6%94%BE%20%E5%85%A5%E7%AD%89%E5%BE%85%E9%98%9F%E5%88%97(waiting%20queue)%E4%B8%AD%E3%80%82%0A%3E*%20(%E4%BA%8C).%20%E5%90%8C%E6%AD%A5%E9%98%BB%E5%A1%9E%EF%BC%9A%E8%BF%90%E8%A1%8C(running)%E7%9A%84%E7%BA%BF%E7%A8%8B%E5%9C%A8%E8%8E%B7%E5%8F%96%E5%AF%B9%E8%B1%A1%E7%9A%84%E5%90%8C%E6%AD%A5%E9%94%81%E6%97%B6%EF%BC%8C%E8%8B%A5%E8%AF%A5%E5%90%8C%E6%AD%A5%20%E9%94%81%20%E8%A2%AB%E5%88%AB%E7%9A%84%E7%BA%BF%E7%A8%8B%E5%8D%A0%E7%94%A8%EF%BC%8C%E5%88%99JVM%E4%BC%9A%E6%8A%8A%E8%AF%A5%E7%BA%BF%E7%A8%8B%E6%94%BE%E5%85%A5%E9%94%81%E6%B1%A0(lock%20pool)%E4%B8%AD%E3%80%82%0A%3E*%20(%E4%B8%89).%20%E5%85%B6%E4%BB%96%E9%98%BB%E5%A1%9E%3A%20%E8%BF%90%E8%A1%8C(running)%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%89%A7%E8%A1%8CThread.sleep(long%20ms)%E6%88%96t.join()%E6%96%B9%E6%B3%95%EF%BC%8C%E6%88%96%E8%80%85%E5%8F%91%E5%87%BA%E4%BA%86I%2FO%E8%AF%B7%E6%B1%82%E6%97%B6%EF%BC%8CJVM%E4%BC%9A%E6%8A%8A%E8%AF%A5%E7%BA%BF%E7%A8%8B%E7%BD%AE%E4%B8%BA%E9%98%BB%E5%A1%9E%E7%8A%B6%E6%80%81%E3%80%82%E5%BD%93sleep()%E7%8A%B6%E6%80%81%E8%B6%85%E6%97%B6join()%E7%AD%89%E5%BE%85%E7%BA%BF%E7%A8%8B%E7%BB%88%E6%AD%A2%E6%88%96%E8%80%85%E8%B6%85%E6%97%B6%E3%80%81%E6%88%96%E8%80%85I%2FO%E5%A4%84%E7%90%86%E5%AE%8C%E6%AF%95%E6%97%B6%EF%BC%8C%E7%BA%BF%E7%A8%8B%E9%87%8D%E6%96%B0%E8%BD%AC%E5%85%A5%E5%8F%AF%E8%BF%90%E8%A1%8C(runnable)%E7%8A%B6%E6%80%81%E3%80%82%0A5.%20%E6%AD%BB%E4%BA%A1(dead)%EF%BC%9A%E7%BA%BF%E7%A8%8Brun()%E3%80%81main()%E6%96%B9%E6%B3%95%E6%89%A7%E8%A1%8C%E7%BB%93%E6%9D%9F%EF%BC%8C%E6%88%96%E8%80%85%E5%9B%A0%E5%BC%82%E5%B8%B8%E9%80%80%E5%87%BA%E4%BA%86run()%E6%96%B9%E6%B3%95%EF%BC%8C%E5%88%99%E8%AF%A5%E7%BA%BF%E7%A8%8B%E7%BB%93%E6%9D%9F%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E3%80%82%E6%AD%BB%E4%BA%A1%E7%9A%84%E7%BA%BF%E7%A8%8B%E4%B8%8D%E5%8F%AF%E5%86%8D%E6%AC%A1%E5%A4%8D%E7%94%9F%E3%80%82%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/84f15188-1d71-4592-9417-c67e4a90da27/76320db7-6318-4292-b3a8-faafb6b6eb49.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F606%3A1)%0A%0A%23%23%23%23%201.5%20%E7%BA%BF%E7%A8%8B%E7%9A%84%E4%BC%98%E5%85%88%E7%BA%A7%0A%3E%E6%AF%8F%E4%B8%AA%E7%BA%BF%E7%A8%8B%E9%83%BD%E5%85%B7%E6%9C%89%E5%90%84%E8%87%AA%E7%9A%84%E4%BC%98%E5%85%88%E7%BA%A7%EF%BC%8C%E7%BA%BF%E7%A8%8B%E7%9A%84%E4%BC%98%E5%85%88%E7%BA%A7%E5%8F%AF%E4%BB%A5%E5%9C%A8%E7%A8%8B%E5%BA%8F%E4%B8%AD%E8%A1%A8%E6%98%8E%E8%AF%A5%E7%BA%BF%E7%A8%8B%E7%9A%84%E9%87%8D%E8%A6%81%E6%80%A7%EF%BC%8C%E5%A6%82%E6%9E%9C%E6%9C%89%E5%BE%88%E5%A4%9A%E7%BA%BF%E7%A8%8B%E5%A4%84%E4%BA%8E%E5%B0%B1%E7%BB%AA%E7%8A%B6%E6%80%81%EF%BC%8C%E7%B3%BB%E7%BB%9F%E4%BC%9A%E6%A0%B9%E6%8D%AE%E4%BC%98%E5%85%88%E7%BA%A7%E6%9D%A5%E5%86%B3%E5%AE%9A%E9%A6%96%E5%85%88%E4%BD%BF%E5%93%AA%E4%B8%AA%E7%BA%BF%E7%A8%8B%E8%BF%9B%E5%85%A5%E8%BF%90%E8%A1%8C%E7%8A%B6%E6%80%81%E3%80%82%0A*%20%E7%BA%BF%E7%A8%8B%E4%BC%98%E5%85%88%E7%BA%A7%E5%85%B7%E6%9C%89%E7%BB%A7%E6%89%BF%E7%89%B9%E6%80%A7%E6%AF%94%E5%A6%82A%E7%BA%BF%E7%A8%8B%E5%90%AF%E5%8A%A8B%E7%BA%BF%E7%A8%8B%EF%BC%8C%E5%88%99B%E7%BA%BF%E7%A8%8B%E7%9A%84%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8CA%E6%98%AF%E4%B8%80%E6%A0%B7%E7%9A%84%E3%80%82%0A*%20%E7%BA%BF%E7%A8%8B%E4%BC%98%E5%85%88%E7%BA%A7%E5%85%B7%E6%9C%89%E9%9A%8F%E6%9C%BA%E6%80%A7%E4%B9%9F%E5%B0%B1%E6%98%AF%E8%AF%B4%E7%BA%BF%E7%A8%8B%E4%BC%98%E5%85%88%E7%BA%A7%E9%AB%98%E7%9A%84%E4%B8%8D%E4%B8%80%E5%AE%9A%E6%AF%8F%E4%B8%80%E6%AC%A1%E9%83%BD%E5%85%88%E6%89%A7%E8%A1%8C%E5%AE%8C%E3%80%82%0A%3EThread%E7%B1%BB%E4%B8%AD%E5%8C%85%E5%90%AB%E7%9A%84%E6%88%90%E5%91%98%E5%8F%98%E9%87%8F%E4%BB%A3%E8%A1%A8%E4%BA%86%E7%BA%BF%E7%A8%8B%E7%9A%84%E6%9F%90%E4%BA%9B%E4%BC%98%E5%85%88%E7%BA%A7%E3%80%82%0A*%20%E5%A6%82Thread.MIN_PRIORITY%EF%BC%88%E5%B8%B8%E6%95%B01%EF%BC%89%EF%BC%8CThread.NORM_PRIORITY%EF%BC%88%E5%B8%B8%E6%95%B05%EF%BC%89%2C%0AThread.MAX_PRIORITY%EF%BC%88%E5%B8%B8%E6%95%B010%EF%BC%89%E3%80%82%0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BC%88Response%20Time%EF%BC%89%EF%BC%8C%E5%90%9E%E5%90%90%E9%87%8F%EF%BC%88Throughput%EF%BC%89%EF%BC%8C%E6%AF%8F%E7%A7%92%E6%9F%A5%E8%AF%A2%E7%8E%87QPS%EF%BC%88Query%20Per%20Second%EF%BC%89%EF%BC%8C%E5%B9%B6%E5%8F%91%E7%94%A8%E6%88%B7%E6%95%B0%E7%AD%89%E3%80%82%0A%0A%23%23%23%23%202.4%20%E4%B8%B4%E7%95%8C%E5%8C%BA%0A%E4%B8%B4%E7%95%8C%E5%8C%BA%E7%94%A8%E6%9D%A5%E8%A1%A8%E7%A4%BA%E4%B8%80%E7%A7%8D%E5%85%AC%E5%85%B1%E8%B5%84%E6%BA%90%E6%88%96%E8%80%85%E8%AF%B4%E6%98%AF**%E5%85%B1%E4%BA%AB%E6%95%B0%E6%8D%AE**%EF%BC%8C%E5%8F%AF%E4%BB%A5**%E8%A2%AB%E5%A4%9A%E4%B8%AA%E7%BA%BF%E7%A8%8B%E4%BD%BF%E7%94%A8**%E3%80%82%0A%E4%BD%86%E6%98%AF%E6%AF%8F%E4%B8%80%E6%AC%A1%EF%BC%8C%E5%8F%AA%E8%83%BD%E6%9C%89%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%E4%BD%BF%E7%94%A8%E5%AE%83%EF%BC%8C%E4%B8%80%E6%97%A6%E4%B8%B4%E7%95%8C%E5%8C%BA%E8%B5%84%E6%BA%90%E8%A2%AB%E5%8D%A0%E7%94%A8%EF%BC%8C%E5%85%B6%E4%BB%96%E7%BA%BF%E7%A8%8B%E8%A6%81%E6%83%B3%E4%BD%BF%E7%94%A8%E8%BF%99%E4%B8%AA%E8%B5%84%E6%BA%90%EF%BC%8C%E5%B0%B1%E5%BF%85%E9%A1%BB**%E7%AD%89%E5%BE%85**%E3%80%82%E5%9C%A8%E5%B9%B6%E8%A1%8C%E7%A8%8B%E5%BA%8F%E4%B8%AD%EF%BC%8C%E4%B8%B4%E7%95%8C%E5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%8CJVM%E8%99%9A%E6%8B%9F%E6%9C%BA%E5%90%AF%E5%8A%A8%E5%90%8E%E7%9A%84%E6%A3%80%E6%B5%8B%E7%BA%BF%E7%A8%8B%0A%E6%9C%80%E5%B8%B8%E8%A7%81%E7%9A%84%E5%AE%88%E6%8A%A4%E7%BA%BF%E7%A8%8B%EF%BC%9A%E5%9E%83%E5%9C%BE%E5%9B%9E%E6%94%B6%E7%BA%BF%E7%A8%8B%0A%0A%23%23%23%23%203.3%20%E5%A6%82%E4%BD%95%E8%AE%BE%E7%BD%AE%E5%AE%88%E6%8A%A4%E7%BA%BF%E7%A8%8B%EF%BC%9F%0A%3E*%20%E9%80%9A%E8%BF%87%E8%B0%83%E7%94%A8Thead%E7%B1%BB%E7%9A%84setDaemon(true)%E6%96%B9%E6%B3%95%E8%AE%BE%E7%BD%AE%E5%BD%93%E5%89%8D%E7%9A%84%E7%BA%BF%E7%A8%8B%E4%B8%BA%E5%AE%88%E6%8A%A4%E7%BA%BF%E7%A8%8B%0A%60%60%60%0A1.%20setDaemon(true)%E5%BF%85%E9%A1%BB%E5%9C%A8start()%E6%96%B9%E6%B3%95%E5%89%8D%E6%89%A7%E8%A1%8C%EF%BC%8C%E5%90%A6%E5%88%99%E4%BC%9A%E6%8A%9B%E5%87%BAIllegalThreadStateException%E5%BC%82%E5%B8%B8%20%0A2.%20%20%E5%9C%A8%E5%AE%88%E6%8A%A4%E7%BA%BF%E7%A8%8B%E4%B8%AD%E4%BA%A7%E7%94%9F%E7%9A%84%E6%96%B0%E7%BA%BF%E7%A8%8B%E4%B9%9F%E6%98%AF%E5%AE%88%E6%8A%A4%E7%BA%BF%E7%A8%8B%20%0A3.%20%20%E4%B8%8D%E6%98%AF%E6%89%80%E6%9C%89%E7%9A%84%E4%BB%BB%E5%8A%A1%E9%83%BD%E5%8F%AF%E4%BB%A5%E5%88%86%E9%85%8D%E7%BB%99%E5%AE%88%E6%8A%A4%E7%BA%BF%E7%A8%8B%E6%9D%A5%E6%89%A7%E8%A1%8C%EF%BC%8C%E6%AF%94%E5%A6%82%E8%AF%BB%E5%86%99%E6%93%8D%E4%BD%9C%E6%88%96%E8%80%85%E8%AE%A1%E7%AE%97%E9%80%BB%E8%BE%91%0A%60%60%60%0A%0A%23%23%23%23%204.%20%E4%B8%80%E4%BA%9B%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%95%0A%23%23%23%23%23%204.1%20currentThread()%0A%3E%20%E8%BF%94%E5%9B%9E%E5%AF%B9%E5%BD%93%E5%89%8D%E6%AD%A3%E5%9C%A8%E6%89%A7%E8%A1%8C%E7%9A%84%E7%BA%BF%E7%A8%8B%E5%AF%B9%E8%B1%A1%E7%9A%84%E5%BC%95%E7%94%A8%E3%80%82%0A%0A%23%23%23%23%23%204.2%20getId()%0A%3E%E8%BF%94%E5%9B%9E%E6%AD%A4%E7%BA%BF%E7%A8%8B%E7%9A%84%E6%A0%87%E8%AF%86%E7%AC%A6%0A%0A%23%23%23%23%23%204.3%20getName()%0A%3E%E8%BF%94%E5%9B%9E%E6%AD%A4%E7%BA%BF%E7%A8%8B%E7%9A%84%E5%90%8D%E7%A7%B0%0A%0A%23%23%23%23%23%204.4%20getPriority()%0A%3E%E8%BF%94%E5%9B%9E%E6%AD%A4%E7%BA%BF%E7%A8%8B%E7%9A%84%E4%BC%98%E5%85%88%E7%BA%A7%0A%0A%23%23%23%23%23%204.5%20isAlive()%0A%3E%E6%B5%8B%E8%AF%95%E8%BF%99%E4%B8%AA%E7%BA%BF%E7%A8%8B%E6%98%AF%E5%90%A6%E8%BF%98%E5%A4%84%E4%BA%8E%E6%B4%BB%E5%8A%A8%E7%8A%B6%E6%80%81%E3%80%82%0A%E4%BB%80%E4%B9%88%E6%98%AF%E6%B4%BB%E5%8A%A8%E7%8A%B6%E6%80%81%E5%91%A2%EF%BC%9F%0A%E6%B4%BB%E5%8A%A8%E7%8A%B6%E6%80%81%E5%B0%B1%E6%98%AF%E7%BA%BF%E7%A8%8B%E5%B7%B2%E7%BB%8F%E5%90%AF%E5%8A%A8%E4%B8%94%E5%B0%9A%E6%9C%AA%E7%BB%88%E6%AD%A2%E3%80%82%E7%BA%BF%E7%A8%8B%E5%A4%84%E4%BA%8E%E6%AD%A3%E5%9C%A8%E8%BF%90%E8%A1%8C%E6%88%96%E5%87%86%E5%A4%87%E8%BF%90%E8%A1%8C%E7%9A%84%E7%8A%B6%E6%80%81%E3%80%82%0A%0A%23%23%23%23%23%204.6%20sleep(long%20millis)%0A%3E%E4%BD%BF%E5%BD%93%E5%89%8D%E6%AD%A3%E5%9C%A8%E6%89%A7%E8%A1%8C%E7%9A%84%E7%BA%BF%E7%A8%8B%E4%BB%A5%E6%8C%87%E5%AE%9A%E7%9A%84%E6%AF%AB%E7%A7%92%E6%95%B0%E2%80%9C%E4%BC%91%E7%9C%A0%E2%80%9D%EF%BC%88%E6%9A%82%E6%97%B6%E5%81%9C%E6%AD%A2%E6%89%A7%E8%A1%8C%EF%BC%89%EF%BC%8C%E5%85%B7%E4%BD%93%E5%8F%96%E5%86%B3%E4%BA%8E%E7%B3%BB%E7%BB%9F%E5%AE%9A%E6%97%B6%E5%99%A8%E5%92%8C%E8%B0%83%E5%BA%A6%E7%A8%8B%E5%BA%8F%E7%9A%84%E7%B2%BE%E5%BA%A6%E5%92%8C%E5%87%86%E7%A1%AE%E6%80%A7%E3%80%82%0A%0A%23%23%23%23%23%204.7%20interrupt()%0A%3E%E4%B8%AD%E6%96%AD%E8%BF%99%E4%B8%AA%E7%BA%BF%E7%A8%8B%E3%80%82%0A%0A%23%23%23%23%23%204.8%20interrupted()%20%E5%92%8CisInterrupted()%0A%3Einterrupted()%EF%BC%9A%E6%B5%8B%E8%AF%95%E5%BD%93%E5%89%8D%E7%BA%BF%E7%A8%8B%E6%98%AF%E5%90%A6%E5%B7%B2%E7%BB%8F%E6%98%AF%E4%B8%AD%E6%96%AD%E7%8A%B6%E6%80%81%EF%BC%8C%E6%89%A7%E8%A1%8C%E5%90%8E%E5%85%B7%E6%9C%89%E5%B0%86%E7%8A%B6%E6%80%81%E6%A0%87%E5%BF%97%E6%B8%85%E9%99%A4%E4%B8%BAfalse%E7%9A%84%E5%8A%9F%E8%83%BD%0AisInterrupted()%EF%BC%9A%20%E6%B5%8B%E8%AF%95%E7%BA%BF%E7%A8%8BThread%E5%AF%B9%E7%9B%B8%E5%85%B3%E6%98%AF%E5%90%A6%E5%B7%B2%E7%BB%8F%E6%98%AF%E4%B8%AD%E6%96%AD%E7%8A%B6%E6%80%81%EF%BC%8C%E4%BD%86%E9%83%A8%E6%B8%85%E6%A5%9A%E7%8A%B6%E6%80%81%E6%A0%87%E5%BF%97%0A%0A%23%23%23%23%23%204.9%20setName(String%20name)%0A%3E%E5%B0%86%E6%AD%A4%E7%BA%BF%E7%A8%8B%E7%9A%84%E5%90%8D%E7%A7%B0%E6%9B%B4%E6%94%B9%E4%B8%BA%E7%AD%89%E4%BA%8E%E5%8F%82%E6%95%B0%20name%20%E3%80%82%0A%0A%23%23%23%23%23%204.10%20isDaemon()%0A%3E%E6%B5%8B%E8%AF%95%E8%BF%99%E4%B8%AA%E7%BA%BF%E7%A8%8B%E6%98%AF%E5%90%A6%E6%98%AF%E5%AE%88%E6%8A%A4%E7%BA%BF%E7%A8%8B%E3%80%82%0A%0A%23%23%23%23%23%204.11%20setDaemon(boolean%20on)%0A%3E%E5%B0%86%E6%AD%A4%E7%BA%BF%E7%A8%8B%E6%A0%87%E8%AE%B0%E4%B8%BA%20daemon%E7%BA%BF%E7%A8%8B%E6%88%96%E7%94%A8%E6%88%B7%E7%BA%BF%E7%A8%8B%E3%80%82%0A%0A%23%23%23%23%23%204.12%20join()%0A%3E%E5%9C%A8%E5%BE%88%E5%A4%9A%E6%83%85%E5%86%B5%E4%B8%8B%EF%BC%8C%E4%B8%BB%E7%BA%BF%E7%A8%8B%E7%94%9F%E6%88%90%E5%B9%B6%E8%B5%B7%E5%8A%A8%E4%BA%86%E5%AD%90%E7%BA%BF%E7%A8%8B%EF%BC%8C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%B0%B1%E6%98%AF%E8%AF%A5%E7%BA%BF%E7%A8%8B%E6%98%AF%E6%8C%87%E7%9A%84%E4%B8%BB%E7%BA%BF%E7%A8%8B%E7%AD%89%E5%BE%85%E5%AD%90%E7%BA%BF%E7%A8%8B%E7%9A%84%E7%BB%88%E6%AD%A2%E3%80%82%E4%B9%9F%E5%B0%B1%E6%98%AF%E5%9C%A8%E5%AD%90%E7%BA%BF%E7%A8%8B%E8%B0%83%E7%94%A8%E4%BA%86join()%E6%96%B9%E6%B3%95%E5%90%8E%E9%9D%A2%E7%9A%84%E4%BB%A3%E7%A0%81%EF%BC%8C%E5%8F%AA%E6%9C%89%E7%AD%89%E5%88%B0%E5%AD%90%E7%BA%BF%E7%A8%8B%E7%BB%93%E6%9D%9F%E4%BA%86%E6%89%8D%E8%83%BD%E6%89%A7%E8%A1%8C%0A%0A%23%23%23%23%23%204.13%20yield()%0A%3Eyield()%E6%96%B9%E6%B3%95%E7%9A%84%E4%BD%9C%E7%94%A8%E6%98%AF%E6%94%BE%E5%BC%83%E5%BD%93%E5%89%8D%E7%9A%84CPU%E8%B5%84%E6%BA%90%EF%BC%8C%E5%B0%86%E5%AE%83%E8%AE%A9%E7%BB%99%E5%85%B6%E4%BB%96%E7%9A%84%E4%BB%BB%E5%8A%A1%E5%8E%BB%E5%8D%A0%E7%94%A8CPU%E6%97%B6%E9%97%B4%E3%80%82%E6%B3%A8%E6%84%8F%EF%BC%9A%E6%94%BE%E5%BC%83%E7%9A%84%E6%97%B6%E9%97%B4%E4%B8%8D%E7%A1%AE%E5%AE%9A%EF%BC%8C%E5%8F%AF%E8%83%BD%E4%B8%80%E4%BC%9A%E5%B0%B1%E4%BC%9A%E9%87%8D%E6%96%B0%E8%8E%B7%E5%BE%97CPU%E6%97%B6%E9%97%B4%E7%89%87%E3%80%82%0A%0A%23%23%23%23%23%204.14%20setPriority(int%20newPriority)%0A%3E%E6%9B%B4%E6%94%B9%E6%AD%A4%E7%BA%BF%E7%A8%8B%E7%9A%84%E4%BC%98%E5%85%88%E7%BA%A7%0A&lt;/center&gt;&lt;/div&gt;
</content>
  </entry>
  <entry xml:base="http://linzhiteng.postach.io/feed.xml">
    <title type="text">六. 线程池与Executor 框架</title>
    <id>https://linzhiteng.postach.io/post/liu-xian-cheng-chi-yu-executor-kuang-jia</id>
    <updated>2019-06-09T13:07:46.989000Z</updated>
    <published>2019-03-12T14:22:28Z</published>
    <link href="https://linzhiteng.postach.io/post/liu-xian-cheng-chi-yu-executor-kuang-jia" />
    <author>
      <name>linzhi teng</name>
    </author>
    <category term="xian-cheng" />
    <content type="html">&lt;div&gt;&lt;div style=&quot;font-size: 14px; margin: 0; padding: 0; width: 100%;&quot;&gt;&lt;div style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;六. 线程池与Executor 框架
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1. 使用线程池的好处
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2. Executor 框架
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.1 Executor 简介
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.2 Executor 框架结构(主要由三大部分组成)
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1 任务
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2 任务的执行
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3 异步计算的结果
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.3 Executor 框架的使用示意图
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3. ThreadPoolExecutor详解
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1 ThreadPoolExecutor类的四个比较重要的属性
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.2 ThreadPoolExecutor类中提供的四个构造方法
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.3 如何创建ThreadPoolExecutor
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.4 FixedThreadPool详解
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;FixedThreadPool被称为可重用固定线程数的线程池。
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;FixedThreadPool的execute()方法运行示意图
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;FixedThreadPool使用无界队列 LinkedBlockingQueue（队列的容量为Intger.MAX_VALUE）作为线程池的工作队列会对线程池带来如下影响：
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.5 SingleThreadExecutor详解
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;SingleThreadExecutor是使用单个worker线程的Executor。
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;SingleThreadExecutor的运行示意图
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.6 CachedThreadPool详解
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;CachedThreadPool的execute()方法的执行示意图
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.7 ThreadPoolExecutor使用示例
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4. ScheduledThreadPoolExecutor详解
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.1 ScheduledThreadPoolExecutor简介
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.2 ScheduledThreadPoolExecutor运行机制
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.3 ScheduledThreadPoolExecutor执行周期任务的步骤
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.4 ScheduledThreadPoolExecutor使用示例
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.4.1 ScheduledExecutorService scheduleAtFixedRate(Runnable command,long initialDelay,long period,TimeUnit unit)方法
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.4.2 ScheduledExecutorService scheduleWithFixedDelay(Runnable command,long initialDelay,long delay,TimeUnit unit)方法
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.4.3 scheduleWithFixedDelay() vs scheduleAtFixedRate()
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;5. 各种线程池的适用场景介绍
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;六. 线程池与Executor 框架&lt;/h2&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/6eac2176-4ff7-4ad8-a71c-77eeb40102ca/2872db5e-71ff-4e7a-9f64-dd92fa940a08.jpg&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;a href=&quot;https://blog.csdn.net/qq_34337272/article/details/79959271&quot; style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;线程池与Executor框架&lt;/a&gt;&lt;/p&gt;
&lt;hr style=&quot;line-height: 160%; box-sizing: content-box; border-top: 1px solid #eee; margin: 16px 0;&quot;/&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;1. 使用线程池的好处&lt;/h3&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;线程池提供了一种限制和管理资源（包括执行一个任务）。 每个线程池还维护一些基本统计信息&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0;&quot;&gt;使用线程池的好处&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;降低资源消耗。通过重复利用已创建的线程降低线程创建和销毁造成的消耗。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;提高响应速度。当任务到达时，任务可以不需要的等到线程创建就能立即执行。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;提高线程的可管理性。线程是稀缺资源，如果无限制的创建，不仅会消耗系统资源，还会降低系统的稳定性，使用线程池可以进行统一的分配，调优和监控。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;2. Executor 框架&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.1 Executor 简介&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;Executor 框架是Java5之后引进的，在Java 5之后，通过 Executor 来启动线程比使用 Thread 的 start 方法更好，除了更易管理，效率更好（用线程池实现，节约开销）外，还有关键的一点：有助于避免 this 逃逸问题。&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;this逃逸是指在构造函数返回之前其他线程就持有该对象的引用. 调用尚未构造完全的对象的方法可能引发令人疑惑的错误。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.2 Executor 框架结构(主要由三大部分组成)&lt;/h4&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;1 任务&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;执行任务需要实现的Runnable接口或Callable接口。&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;Runnable接口或Callable接口实现类&lt;/strong&gt;都可以被ThreadPoolExecutor或ScheduledThreadPoolExecutor执行。&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;两者的区别&lt;/strong&gt;：&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;Runnable接口不会返回结果,但是Callable接口可以返回结果。后面介绍Executors类的一些方法的时候会介绍到两者的相互转换。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;2 任务的执行&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/6eac2176-4ff7-4ad8-a71c-77eeb40102ca/5e7ece2e-b9d3-4d60-99c5-9224193c61eb.jpg&quot; /&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;包括任务执行机制的核心接口Executor ，以及继承自Executor 接口的ExecutorService接口。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;ScheduledThreadPoolExecutor和ThreadPoolExecutor这两个关键类实现了ExecutorService接口。&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;3 异步计算的结果&lt;/h5&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;Future接口以及Future接口的实现类FutureTask类。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;当我们把Runnable接口或Callable接口的实现类提交（调用submit方法）给ThreadPoolExecutor或ScheduledThreadPoolExecutor时，会返回一个FutureTask对象。&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.3 Executor 框架的使用示意图&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/6eac2176-4ff7-4ad8-a71c-77eeb40102ca/73ff0fc3-4e73-45f8-9232-c07ebfed79d1.jpg&quot; /&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;主线程首先要&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;创建实现Runnable或者Callable接口的任务对象&lt;/strong&gt;。&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;备注： 工具类Executors可以实现Runnable对象和Callable对象之间的相互转换。（Executors.callable（Runnable task）或Executors.callable（Runnable task，Object resule））&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;然后可以把创建完成的&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;Runnable对象直接交给ExecutorService执行&lt;/strong&gt;（ExecutorService.execute（Runnable command））；或者也可以把Runnable对象或Callable对象提交给ExecutorService执行（ExecutorService.submit（Runnable task）或ExecutorService.submit（Callable task））&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;执行execute()方法和submit()方法的区别是什么呢？&lt;/strong&gt;&lt;br/&gt;
1)execute()方法用于提交不需要返回值的任务，所以无法判断任务是否被线程池执行成功与否；&lt;br/&gt;
2)submit()方法用于提交需要返回值的任务。线程池会返回一个future类型的对象，通过这个future对象可以判断任务是否执行成功，并且可以通过future的get()方法来获取返回值，get()方法会阻塞当前线程直到任务完成，而使用get（long timeout，TimeUnit unit）方法则会阻塞当前线程一段时间后立即返回，这时候有可能任务没有执行完&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;如果&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;执行ExecutorService.submit&lt;/strong&gt;（…），ExecutorService将&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;返回一个实现Future接口的对象&lt;/strong&gt;（我们刚刚也提到过了执行execute()方法和submit()方法的区别，到目前为止的JDK中，返回的是FutureTask对象）。由于FutureTask实现了Runnable，程序员也可以创建FutureTask，然后直接交给ExecutorService执行。&lt;/p&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;最后，主线程可以&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;执行FutureTask.get()方法来等待任务执行完成&lt;/strong&gt;。主线程也可以执行FutureTask.cancel（boolean mayInterruptIfRunning）来取消此任务的执行。&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;3. ThreadPoolExecutor详解&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;线程池实现类ThreadPoolExecutor是Executor 框架最核心的类&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.1 ThreadPoolExecutor类的四个比较重要的属性&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/6eac2176-4ff7-4ad8-a71c-77eeb40102ca/f27509ee-8953-44da-b78f-ffcb895622b6.jpg&quot; /&gt;&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.2 ThreadPoolExecutor类中提供的四个构造方法&lt;/h4&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt; &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;/**
     * 用给定的初始参数创建一个新的ThreadPoolExecutor。
     
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@param&lt;/span&gt; corePoolSize 核心线程池大小
     
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@param&lt;/span&gt; maximumPoolSize 最大线程池的大小
     
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@param&lt;/span&gt; keepAliveTime 当线程池中的线程数量大于corePoolSize的时候，如果这时没有新的任务提交，
     *核心线程外的线程不会立即销毁，而是会等待，直到等待的时间超过了keepAliveTime；
     
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@param&lt;/span&gt; unit  keepAliveTime参数的时间单位
     
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@param&lt;/span&gt; workQueue 等待队列，当任务提交时，如果线程池中的线程数量大于等于corePoolSize的时候，把该任务封装成一个Worker对象放入等待队列；
     * 
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@param&lt;/span&gt; threadFactory 执行者创建新线程时使用的工厂
     
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@param&lt;/span&gt; handler RejectedExecutionHandler类型的变量，表示线程池的饱和策略。
     * 如果阻塞队列满了并且没有空闲的线程，这时如果继续提交任务，就需要采取一种策略处理该任务。
     * 线程池提供了4种策略：
        1.AbortPolicy：直接抛出异常，这是默认策略；
        2.CallerRunsPolicy：用调用者所在的线程来执行任务；
        3.DiscardOldestPolicy：丢弃阻塞队列中靠最前的任务，并执行当前任务；
        4.DiscardPolicy：直接丢弃任务；
     */&lt;/span&gt;
    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;ThreadPoolExecutor&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; corePoolSize,
                              &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; maximumPoolSize,
                              &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;long&lt;/span&gt; keepAliveTime,
                              TimeUnit unit,
                              BlockingQueue&lt;Runnable&gt; workQueue,
                              ThreadFactory threadFactory,
                              RejectedExecutionHandler handler)&lt;/span&gt; &lt;/span&gt;{
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;if&lt;/span&gt; (corePoolSize &lt; &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0&lt;/span&gt; ||
            maximumPoolSize &lt;= &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0&lt;/span&gt; ||
            maximumPoolSize &lt; corePoolSize ||
            keepAliveTime &lt; &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0&lt;/span&gt;)
            &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;throw&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; IllegalArgumentException();
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;if&lt;/span&gt; (workQueue == &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;null&lt;/span&gt; || threadFactory == &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;null&lt;/span&gt; || handler == &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;null&lt;/span&gt;)
            &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;throw&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; NullPointerException();
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;this&lt;/span&gt;.corePoolSize = corePoolSize;
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;this&lt;/span&gt;.maximumPoolSize = maximumPoolSize;
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;this&lt;/span&gt;.workQueue = workQueue;
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;this&lt;/span&gt;.keepAliveTime = unit.toNanos(keepAliveTime);
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;this&lt;/span&gt;.threadFactory = threadFactory;
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;this&lt;/span&gt;.handler = handler;
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.3 如何创建ThreadPoolExecutor&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;在《阿里巴巴Java开发手册》&quot;并发处理&quot;这一章节，明确指出线程资源必须通过线程池提供，不允许在应用中自行显示创建线程。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;为什么呢？&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;使用线程池的好处是减少在创建和销毁线程上所消耗的时间以及系统资源开销，解决资源不足的问题。如果不使用线程池，有可能会造成系统创建大量同类线程而导致消耗完内存或者&quot;过度切换&quot;的问题。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;另外《阿里巴巴Java开发手册》中&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;强制线程池不允许使用 Executors 去创建，而是通过 ThreadPoolExecutor 的方式&lt;/strong&gt;，这样的处理方式让写的同学更加明确线程池的运行规则，规避资源耗尽的风险&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;Executors 返回线程池对象的弊端如下：&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;FixedThreadPool 和 SingleThreadExecutor ： 允许请求的队列长度为 Integer.MAX_VALUE,可能堆积大量的请求，从而导致OOM。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;CachedThreadPool 和 ScheduledThreadPool ： 允许创建的线程数量为 Integer.MAX_VALUE ，可能会创建大量线程，从而导致OOM。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;方式一：通过构造方法实现&lt;/strong&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;方式二：通过Executor 框架的工具类Executors来实现&lt;/strong&gt;&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;我们可以创建三种类型的ThreadPoolExecutor：
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; color: #333; margin-top: 0; margin-bottom: 0; margin: 0;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;FixedThreadPool&lt;/strong&gt;&lt;br/&gt;
&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;SingleThreadExecutor&lt;/strong&gt;&lt;br/&gt;
&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;CachedThreadPool&lt;/strong&gt;&lt;br/&gt;
底层都是调用的ThreadPoolExecutor的构造方法&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.4 FixedThreadPool详解&lt;/h4&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;FixedThreadPool被称为可重用固定线程数的线程池。&lt;/h5&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt; &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;/**
     * 创建一个可重用固定数量线程的线程池
	 *在任何时候至多有n个线程处于活动状态
	 *如果在所有线程处于活动状态时提交其他任务，则它们将在队列中等待，
	 *直到线程可用。 如果任何线程在关闭之前的执行期间由于失败而终止，
	 *如果需要执行后续任务，则一个新的线程将取代它。池中的线程将一直存在
	 *知道调用shutdown方法
     
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@param&lt;/span&gt; nThreads 线程池中的线程数
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@param&lt;/span&gt; threadFactory 创建新线程时使用的factory
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@return&lt;/span&gt; 新创建的线程池
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@throws&lt;/span&gt; NullPointerException 如果threadFactory为null
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@throws&lt;/span&gt; IllegalArgumentException if {&lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@code&lt;/span&gt; nThreads &lt;= 0}
     */&lt;/span&gt;
    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;static&lt;/span&gt; ExecutorService &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;newFixedThreadPool&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; nThreads, ThreadFactory threadFactory)&lt;/span&gt; &lt;/span&gt;{
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; ThreadPoolExecutor(nThreads, nThreads,
                                      &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0L&lt;/span&gt;, TimeUnit.MILLISECONDS,
                                      &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; LinkedBlockingQueue&lt;Runnable&gt;(),
                                      threadFactory);
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;static&lt;/span&gt; ExecutorService &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;newFixedThreadPool&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; nThreads)&lt;/span&gt; &lt;/span&gt;{
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; ThreadPoolExecutor(nThreads, nThreads,
                                      &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0L&lt;/span&gt;, TimeUnit.MILLISECONDS,
                                      &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; LinkedBlockingQueue&lt;Runnable&gt;());
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;新创建的FixedThreadPool的corePoolSize和maximumPoolSize都被设置为nThreads。&lt;/strong&gt;&lt;/p&gt;
&lt;hr style=&quot;line-height: 160%; box-sizing: content-box; border-top: 1px solid #eee; margin: 16px 0;&quot;/&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;FixedThreadPool的execute()方法运行示意图&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/6eac2176-4ff7-4ad8-a71c-77eeb40102ca/fb0c8afd-747f-441a-b98e-3aeec9d5c714.jpg&quot; /&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;上图说明：&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;如果当前运行的线程数小于corePoolSize，则创建新的线程来执行任务；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;当前运行的线程数等于corePoolSize后，将任务加入LinkedBlockingQueue；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;线程执行完1中的任务后，会在循环中反复从LinkedBlockingQueue中获取任务来执行；&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;FixedThreadPool使用无界队列 LinkedBlockingQueue（队列的容量为Intger.MAX_VALUE）作为线程池的工作队列会对线程池带来如下影响：&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;当线程池中的线程数达到corePoolSize后，新任务将在无界队列中等待，因此线程池中的线程数不会超过corePoolSize；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;由于1，使用无界队列时maximumPoolSize将是一个无效参数；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;由于1和2，使用无界队列时keepAliveTime将是一个无效参数；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;运行中的FixedThreadPool（未执行shutdown()或shutdownNow()方法）不会拒绝任务&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.5 SingleThreadExecutor详解&lt;/h4&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;SingleThreadExecutor是使用单个worker线程的Executor。&lt;/h5&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;/**
     *创建使用单个worker线程运行无界队列的Executor
	 *并使用提供的ThreadFactory在需要时创建新线程
     *
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@param&lt;/span&gt; threadFactory 创建新线程时使用的factory
     *
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@return&lt;/span&gt; 新创建的单线程Executor
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@throws&lt;/span&gt; NullPointerException 如果ThreadFactory为空
     */&lt;/span&gt;
    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;static&lt;/span&gt; ExecutorService &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;newSingleThreadExecutor&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(ThreadFactory threadFactory)&lt;/span&gt; &lt;/span&gt;{
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; FinalizableDelegatedExecutorService
            (&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; ThreadPoolExecutor(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1&lt;/span&gt;,
                                    &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0L&lt;/span&gt;, TimeUnit.MILLISECONDS,
                                    &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; LinkedBlockingQueue&lt;Runnable&gt;(),
                                    threadFactory));
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;static&lt;/span&gt; ExecutorService &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;newSingleThreadExecutor&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; FinalizableDelegatedExecutorService
            (&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; ThreadPoolExecutor(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1&lt;/span&gt;,
                                    &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0L&lt;/span&gt;, TimeUnit.MILLISECONDS,
                                    &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; LinkedBlockingQueue&lt;Runnable&gt;()));
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;新创建的SingleThreadExecutor的corePoolSize和maximumPoolSize都被设置为1.&lt;br/&gt;
其他参数和FixedThreadPool相同。SingleThreadExecutor使用无界队列LinkedBlockingQueue作为线程池的工作队列（队列的容量为Intger.MAX_VALUE）&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;SingleThreadExecutor使用无界队列作为线程池的工作队列会对线程池带来的影响与FixedThreadPool相同。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;SingleThreadExecutor的运行示意图&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/6eac2176-4ff7-4ad8-a71c-77eeb40102ca/c8a80e3c-199d-41ef-9f8c-6a8a4704080c.jpg&quot; /&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;上图说明:&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;如果当前运行的线程数少于corePoolSize，则创建一个新的线程执行任务；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;当前线程池中有一个运行的线程后，将任务加入LinkedBlockingQueue&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;线程执行完1中的任务后，会在循环中反复从LinkedBlockingQueue中获取任务来执行；&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.6 CachedThreadPool详解&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;CachedThreadPool是一个会根据需要创建新线程的线程池。&lt;/p&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;/**
     * 创建一个线程池，根据需要创建新线程，但会在先前构建的线程可用时重用它，
	 *并在需要时使用提供的ThreadFactory创建新线程。
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@param&lt;/span&gt; threadFactory 创建新线程使用的factory
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@return&lt;/span&gt; 新创建的线程池
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@throws&lt;/span&gt; NullPointerException 如果threadFactory为空
     */&lt;/span&gt;
    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;static&lt;/span&gt; ExecutorService &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;newCachedThreadPool&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(ThreadFactory threadFactory)&lt;/span&gt; &lt;/span&gt;{
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; ThreadPoolExecutor(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0&lt;/span&gt;, Integer.MAX_VALUE,
                                      &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;60L&lt;/span&gt;, TimeUnit.SECONDS,
                                      &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; SynchronousQueue&lt;Runnable&gt;(),
                                      threadFactory);
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;static&lt;/span&gt; ExecutorService &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;newCachedThreadPool&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; ThreadPoolExecutor(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0&lt;/span&gt;, Integer.MAX_VALUE,
                                      &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;60L&lt;/span&gt;, TimeUnit.SECONDS,
                                      &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; SynchronousQueue&lt;Runnable&gt;());
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;CachedThreadPool的corePoolSize被设置为空（0），maximumPoolSize被设置为Integer.MAX.VALUE，即它是无界的，这也就意味着如果主线程提交任务的速度高于maximumPool中线程处理任务的速度时，CachedThreadPool会不断创建新的线程&lt;/strong&gt;&lt;br/&gt;
极端情况下，这样会导致耗尽cpu和内存资源。&lt;/p&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;CachedThreadPool的execute()方法的执行示意图&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/6eac2176-4ff7-4ad8-a71c-77eeb40102ca/cb47d533-7df7-4b44-94ff-11070c0b6165.jpg&quot; /&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;上图说明：&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;首先执行SynchronousQueue.offer(Runnable task)。如果当前maximumPool中有闲线程正在执行SynchronousQueue.poll(keepAliveTime,TimeUnit.NANOSECONDS)，那么主线程执行offer操作与空闲线程执行的poll操作配对成功，主线程把任务交给空闲线程执行，execute()方法执行完成，否则执行下面的步骤2；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;当初始maximumPool为空，或者maximumPool中没有空闲线程时，将没有线程执行SynchronousQueue.poll(keepAliveTime,TimeUnit.NANOSECONDS)。这种情况下，步骤1将失败，此时CachedThreadPool会创建新线程执行任务，execute方法执行完成；&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.7 ThreadPoolExecutor使用示例&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;首先创建一个Runnable接口的实现类WorkerThread&lt;/p&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;ThreadPoolExecutorDemo&lt;/span&gt; &lt;/span&gt;{

   &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;main&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(String[] args)&lt;/span&gt; &lt;/span&gt;{
       &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//创建一个FixedThreadPool对象&lt;/span&gt;
       ExecutorService executor = Executors.newFixedThreadPool(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;5&lt;/span&gt;);
       &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; i = &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0&lt;/span&gt;; i &lt; &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;10&lt;/span&gt;; i++) {
           &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//创建WorkerThread对象（WorkerThread类实现了Runnable 接口）&lt;/span&gt;
           Runnable worker = &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; WorkerThread(&lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;&quot;&lt;/span&gt; + i);
           &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//执行Runnable&lt;/span&gt;
           executor.execute(worker);
       }
       &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//终止线程池&lt;/span&gt;
       executor.shutdown();
       &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;while&lt;/span&gt; (!executor.isTerminated()) {
       }
       System.out.println(&lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;Finished all threads&quot;&lt;/span&gt;);
   }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;hr style=&quot;line-height: 160%; box-sizing: content-box; border-top: 1px solid #eee; margin: 16px 0;&quot;/&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;shutdown（）VS shutdownNow（）&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;shutdown（）方法表明关闭已在Executor上调用，因此不会再向DelayedPool添加任何其他任务（由ScheduledThreadPoolExecutor类在内部使用）, 但是，已经在队列中提交的任务将被允许完成。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;shutdownNow（）方法试图终止当前正在运行的任务，并停止处理排队的任务并返回正在等待执行的List。&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;isTerminated() Vs isShutdown()&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;isShutDown当调用shutdown()方法后返回为true。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;isTerminated当调用shutdown()方法后，并且所有提交的任务完成后返回为true&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;4. ScheduledThreadPoolExecutor详解&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;4.1 ScheduledThreadPoolExecutor简介&lt;/h4&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;ScheduledThreadPoolExecutor主要用来在给定的&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;延迟后运行任务&lt;/strong&gt;，或者&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;定期执行&lt;/strong&gt;任务。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;ScheduledThreadPoolExecutor使用的&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;任务队列DelayQueue封装了一个PriorityQueue&lt;/strong&gt;，PriorityQueue会对队列中的任务进行排序，执行所需时间短的放在前面先被执行(ScheduledFutureTask的time变量小的先执行)，如果执行所需时间相同则先提交的任务将被先执行(ScheduledFutureTask的squenceNumber变量小的先执行)。&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;4.2 ScheduledThreadPoolExecutor运行机制&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/6eac2176-4ff7-4ad8-a71c-77eeb40102ca/858ca70a-6944-4f29-9766-c07d61201b59.jpg&quot; /&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;ScheduledThreadPoolExecutor的执行主要分为两大部分：&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;当调用ScheduledThreadPoolExecutor的 scheduleAtFixedRate() 方法或者scheduleWirhFixedDelay() 方法时，会向ScheduledThreadPoolExecutor的 DelayQueue 添加一个实现了 RunnableScheduledFutur 接口的 ScheduledFutureTask 。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;线程池中的线程从DelayQueue中获取ScheduledFutureTask，然后执行任务。&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;ScheduledThreadPoolExecutor为了实现周期性的执行任务，对ThreadPoolExecutor做了如下修改：&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;使用 DelayQueue 作为任务队列；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;获取任务的方不同&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;执行周期任务后，增加了额外的处理&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;4.3 ScheduledThreadPoolExecutor执行周期任务的步骤&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/6eac2176-4ff7-4ad8-a71c-77eeb40102ca/78c094de-0e1c-47d7-84ba-c92bc3523d71.jpg&quot; /&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;线程1从DelayQueue中获取已到期的ScheduledFutureTask（DelayQueue.take()）。到期任务是指ScheduledFutureTask的time大于等于当前系统的时间；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;线程1执行这个ScheduledFutureTask；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;线程1修改ScheduledFutureTask的time变量为下次将要被执行的时间；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;线程1把这个修改time之后的ScheduledFutureTask放回DelayQueue中（DelayQueue.add())。&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;4.4 ScheduledThreadPoolExecutor使用示例&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;创建一个简单的实现Runnable接口的类&lt;br/&gt;
测试程序使用ScheduledExecutorService和Executors.newScheduledThreadPool实现的java调度&lt;/p&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.4.1 ScheduledExecutorService scheduleAtFixedRate(Runnable command,long initialDelay,long period,TimeUnit unit)方法&lt;/h5&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//可以使用ScheduledExecutorService scheduleAtFixedRate方法来安排任务在初始延迟后运行，然后在给定的时间段内运行。&lt;/span&gt;

scheduledThreadPool.scheduleAtFixedRate(worker, &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;10&lt;/span&gt;, TimeUnit.SECONDS);
&lt;/code&gt;&lt;/pre&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.4.2 ScheduledExecutorService scheduleWithFixedDelay(Runnable command,long initialDelay,long delay,TimeUnit unit)方法&lt;/h5&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//ScheduledExecutorService scheduleWithFixedDelay方法可用于以初始延迟启动周期性执行，然后以给定延迟执行。 延迟时间是线程完成执行的时间。&lt;/span&gt;

scheduledThreadPool.scheduleWithFixedDelay(worker, &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1&lt;/span&gt;, TimeUnit.SECONDS);
&lt;/code&gt;&lt;/pre&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.4.3 scheduleWithFixedDelay() vs scheduleAtFixedRate()&lt;/h5&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;scheduleAtFixedRate&lt;/strong&gt;（…）将延迟视为两个任务&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;开始之间的差异&lt;/strong&gt;（即定期调用）&lt;br/&gt;
不管是否执行完&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;scheduleWithFixedDelay&lt;/strong&gt;（…）将延迟视为&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;一个任务结束与下一个任务开始&lt;/strong&gt;之间的差异，执行完才开始下一个。&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;scheduleAtFixedRate()&lt;/strong&gt;: 在给定的初始延迟之后创建并执行，随后以给定的时间段首先启用的周期性动作; 那就是执行将在initialDelay之后开始，然后initialDelay+period ，然后是initialDelay + 2 * period ，等等。 如果任务的执行遇到异常，则后续的执行被抑制。 否则，任务将仅通过取消或终止执行人终止。 如果任务执行时间比其周期长，则后续执行可能会迟到，但不会同时执行。&lt;br/&gt;
&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;scheduleWithFixedDelay()&lt;/strong&gt; : 在给定的初始延迟之后创建并执行，首先启用的定期动作，随后在一个执行的终止和下一个执行的开始之间给定的延迟。 如果任务的执行遇到异常，则后续的执行被抑制。 否则，任务将仅通过取消或终止执行终止。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;5. 各种线程池的适用场景介绍&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;FixedThreadPool&lt;/strong&gt;： 适用于为了满足资源管理需求，而需要限制当前线程数量的应用场景。它适用于负载比较重的服务器；&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;SingleThreadExecutor&lt;/strong&gt;： 适用于需要保证顺序地执行各个任务并且在任意时间点，不会有多个线程是活动的应用场景。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;CachedThreadPool&lt;/strong&gt;： 适用于执行很多的短期异步任务的小程序，或者是负载较轻的服务器；&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;ScheduledThreadPoolExecutor&lt;/strong&gt;： 适用于需要多个后台执行周期任务，同时为了满足资源管理需求而需要限制后台线程的数量的应用场景，&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;SingleThreadScheduledExecutor&lt;/strong&gt;： 适用于需要单个后台线程执行周期任务，同时保证顺序地执行各个任务的应用场景。&lt;/p&gt;
&lt;/div&gt;&lt;center style='display:none !important;visibility:collapse !important;height:0 !important;white-space:nowrap;width:100%;overflow:hidden'&gt;%5Btoc%5D%0A%23%23%20%E5%85%AD.%20%E7%BA%BF%E7%A8%8B%E6%B1%A0%E4%B8%8EExecutor%20%E6%A1%86%E6%9E%B6%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/6eac2176-4ff7-4ad8-a71c-77eeb40102ca/2872db5e-71ff-4e7a-9f64-dd92fa940a08.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F595%3A1)%0A%0A%5B%E7%BA%BF%E7%A8%8B%E6%B1%A0%E4%B8%8EExecutor%E6%A1%86%E6%9E%B6%5D(https%3A%2F%2Fblog.csdn.net%2Fqq_34337272%2Farticle%2Fdetails%2F79959271)%0A-%20-%20-%20%0A%23%23%23%201.%20%E4%BD%BF%E7%94%A8%E7%BA%BF%E7%A8%8B%E6%B1%A0%E7%9A%84%E5%A5%BD%E5%A4%84%0A*%20%E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80%82%0A%3E%20*%20%20%E6%8F%90%E9%AB%98%E7%BA%BF%E7%A8%8B%E7%9A%84%E5%8F%AF%E7%AE%A1%E7%90%86%E6%80%A7%E3%80%82%E7%BA%BF%E7%A8%8B%E6%98%AF%E7%A8%80%E7%BC%BA%E8%B5%84%E6%BA%90%EF%BC%8C%E5%A6%82%E6%9E%9C%E6%97%A0%E9%99%90%E5%88%B6%E7%9A%84%E5%88%9B%E5%BB%BA%EF%BC%8C%E4%B8%8D%E4%BB%85%E4%BC%9A%E6%B6%88%E8%80%97%E7%B3%BB%E7%BB%9F%E8%B5%84%E6%BA%90%EF%BC%8C%E8%BF%98%E4%BC%9A%E9%99%8D%E4%BD%8E%E7%B3%BB%E7%BB%9F%E7%9A%84%E7%A8%B3%E5%AE%9A%E6%80%A7%EF%BC%8C%E4%BD%BF%E7%94%A8%E7%BA%BF%E7%A8%8B%E6%B1%A0%E5%8F%AF%E4%BB%A5%E8%BF%9B%E8%A1%8C%E7%BB%9F%E4%B8%80%E7%9A%84%E5%88%86%E9%85%8D%EF%BC%8C%E8%B0%83%E4%BC%98%E5%92%8C%E7%9B%91%E6%8E%A7%E3%80%82%0A%0A%23%23%23%202.%20Executor%20%E6%A1%86%E6%9E%B6%0A%23%23%23%23%202.1%20Executor%20%E7%AE%80%E4%BB%8B%0AExecutor%20%E6%A1%86%E6%9E%B6%E6%98%AFJava5%E4%B9%8B%E5%90%8E%E5%BC%95%E8%BF%9B%E7%9A%84%EF%BC%8C%E5%9C%A8Java%205%E4%B9%8B%E5%90%8E%EF%BC%8C%E9%80%9A%E8%BF%87%20Executor%20%E6%9D%A5%E5%90%AF%E5%8A%A8%E7%BA%BF%E7%A8%8B%E6%AF%94%E4%BD%BF%E7%94%A8%20Thread%20%E7%9A%84%20start%20%E6%96%B9%E6%B3%95%E6%9B%B4%E5%A5%BD%EF%BC%8C%E9%99%A4%E4%BA%86%E6%9B%B4%E6%98%93%E7%AE%A1%E7%90%86%EF%BC%8C%E6%95%88%E7%8E%87%E6%9B%B4%E5%A5%BD%EF%BC%88%E7%94%A8%E7%BA%BF%E7%A8%8B%E6%B1%A0%E5%AE%9E%E7%8E%B0%EF%BC%8C%E8%8A%82%E7%BA%A6%E5%BC%80%E9%94%80%EF%BC%89%E5%A4%96%EF%BC%8C%E8%BF%98%E6%9C%89%E5%85%B3%E9%94%AE%E7%9A%84%E4%B8%80%E7%82%B9%EF%BC%9A%E6%9C%89%E5%8A%A9%E4%BA%8E%E9%81%BF%E5%85%8D%20this%20%E9%80%83%E9%80%B8%E9%97%AE%E9%A2%98%E3%80%82%0A%3Ethis%E9%80%83%E9%80%B8%E6%98%AF%E6%8C%87%E5%9C%A8%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%E8%BF%94%E5%9B%9E%E4%B9%8B%E5%89%8D%E5%85%B6%E4%BB%96%E7%BA%BF%E7%A8%8B%E5%B0%B1%E6%8C%81%E6%9C%89%E8%AF%A5%E5%AF%B9%E8%B1%A1%E7%9A%84%E5%BC%95%E7%94%A8.%20%E8%B0%83%E7%94%A8%E5%B0%9A%E6%9C%AA%E6%9E%84%E9%80%A0%E5%AE%8C%E5%85%A8%E7%9A%84%E5%AF%B9%E8%B1%A1%E7%9A%84%E6%96%B9%E6%B3%95%E5%8F%AF%E8%83%BD%E5%BC%95%E5%8F%91%E4%BB%A4%E4%BA%BA%E7%96%91%E6%83%91%E7%9A%84%E9%94%99%E8%AF%AF%E3%80%82%0A%0A%23%23%23%23%202.2%20Executor%20%E6%A1%86%E6%9E%B6%E7%BB%93%E6%9E%84(%E4%B8%BB%E8%A6%81%E7%94%B1%E4%B8%89%E5%A4%A7%E9%83%A8%E5%88%86%E7%BB%84%E6%88%90)%0A%0A%23%23%23%23%23%201%20%E4%BB%BB%E5%8A%A1%0A%E6%89%A7%E8%A1%8C%E4%BB%BB%E5%8A%A1%E9%9C%80%E8%A6%81%E5%AE%9E%E7%8E%B0%E7%9A%84Runnable%E6%8E%A5%E5%8F%A3%E6%88%96Callable%E6%8E%A5%E5%8F%A3%E3%80%82**Runnable%E6%8E%A5%E5%8F%A3%E6%88%96Callable%E6%8E%A5%E5%8F%A3%E5%AE%9E%E7%8E%B0%E7%B1%BB**%E9%83%BD%E5%8F%AF%E4%BB%A5%E8%A2%ABThreadPoolExecutor%E6%88%96ScheduledThreadPoolExecutor%E6%89%A7%E8%A1%8C%E3%80%82%0A%0A%3E**%E4%B8%A4%E8%80%85%E7%9A%84%E5%8C%BA%E5%88%AB**%EF%BC%9A%0A%3E*%20Runnable%E6%8E%A5%E5%8F%A3%E4%B8%8D%E4%BC%9A%E8%BF%94%E5%9B%9E%E7%BB%93%E6%9E%9C%2C%E4%BD%86%E6%98%AFCallable%E6%8E%A5%E5%8F%A3%E5%8F%AF%E4%BB%A5%E8%BF%94%E5%9B%9E%E7%BB%93%E6%9E%9C%E3%80%82%E5%90%8E%E9%9D%A2%E4%BB%8B%E7%BB%8DExecutors%E7%B1%BB%E7%9A%84%E4%B8%80%E4%BA%9B%E6%96%B9%E6%B3%95%E7%9A%84%E6%97%B6%E5%80%99%E4%BC%9A%E4%BB%8B%E7%BB%8D%E5%88%B0%E4%B8%A4%E8%80%85%E7%9A%84%E7%9B%B8%E4%BA%92%E8%BD%AC%E6%8D%A2%E3%80%82%0A%0A%23%23%23%23%23%202%20%E4%BB%BB%E5%8A%A1%E7%9A%84%E6%89%A7%E8%A1%8C%0A%3E!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/6eac2176-4ff7-4ad8-a71c-77eeb40102ca/5e7ece2e-b9d3-4d60-99c5-9224193c61eb.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F598%3A1)%0A*%20%E5%8C%85%E6%8B%AC%E4%BB%BB%E5%8A%A1%E6%89%A7%E8%A1%8C%E6%9C%BA%E5%88%B6%E7%9A%84%E6%A0%B8%E5%BF%83%E6%8E%A5%E5%8F%A3Executor%C2%A0%EF%BC%8C%E4%BB%A5%E5%8F%8A%E7%BB%A7%E6%89%BF%E8%87%AAExecutor%20%E6%8E%A5%E5%8F%A3%E7%9A%84ExecutorService%E6%8E%A5%E5%8F%A3%E3%80%82%0A*%20ScheduledThreadPoolExecutor%E5%92%8CThreadPoolExecutor%E8%BF%99%E4%B8%A4%E4%B8%AA%E5%85%B3%E9%94%AE%E7%B1%BB%E5%AE%9E%E7%8E%B0%E4%BA%86ExecutorService%E6%8E%A5%E5%8F%A3%E3%80%82%0A%23%23%23%23%23%203%20%E5%BC%82%E6%AD%A5%E8%AE%A1%E7%AE%97%E7%9A%84%E7%BB%93%E6%9E%9C%0A*%20Future%E6%8E%A5%E5%8F%A3%E4%BB%A5%E5%8F%8AFuture%E6%8E%A5%E5%8F%A3%E7%9A%84%E5%AE%9E%E7%8E%B0%E7%B1%BBFutureTask%E7%B1%BB%E3%80%82%0A*%20%E5%BD%93%E6%88%91%E4%BB%AC%E6%8A%8ARunnable%E6%8E%A5%E5%8F%A3%E6%88%96Callable%E6%8E%A5%E5%8F%A3%E7%9A%84%E5%AE%9E%E7%8E%B0%E7%B1%BB%E6%8F%90%E4%BA%A4%EF%BC%88%E8%B0%83%E7%94%A8submit%E6%96%B9%E6%B3%95%EF%BC%89%E7%BB%99ThreadPoolExecutor%E6%88%96ScheduledThreadPoolExecutor%E6%97%B6%EF%BC%8C%E4%BC%9A%E8%BF%94%E5%9B%9E%E4%B8%80%E4%B8%AAFutureTask%E5%AF%B9%E8%B1%A1%E3%80%82%0A%23%23%23%23%202.3%20Executor%20%E6%A1%86%E6%9E%B6%E7%9A%84%E4%BD%BF%E7%94%A8%E7%A4%BA%E6%84%8F%E5%9B%BE%0A%3E!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/6eac2176-4ff7-4ad8-a71c-77eeb40102ca/73ff0fc3-4e73-45f8-9232-c07ebfed79d1.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F594%3A1)%0A%0A1.%20%E4%B8%BB%E7%BA%BF%E7%A8%8B%E9%A6%96%E5%85%88%E8%A6%81**%E5%88%9B%E5%BB%BA%E5%AE%9E%E7%8E%B0Runnable%E6%88%96%E8%80%85Callable%E6%8E%A5%E5%8F%A3%E7%9A%84%E4%BB%BB%E5%8A%A1%E5%AF%B9%E8%B1%A1**%E3%80%82%0A%20%20%20%20%3E%E5%A4%87%E6%B3%A8%EF%BC%9A%C2%A0%E5%B7%A5%E5%85%B7%E7%B1%BBExecutors%E5%8F%AF%E4%BB%A5%E5%AE%9E%E7%8E%B0Runnable%E5%AF%B9%E8%B1%A1%E5%92%8CCallable%E5%AF%B9%E8%B1%A1%E4%B9%8B%E9%97%B4%E7%9A%84%E7%9B%B8%E4%BA%92%E8%BD%AC%E6%8D%A2%E3%80%82%EF%BC%88Executors.callable%EF%BC%88Runnable%20task%EF%BC%89%E6%88%96Executors.callable%EF%BC%88Runnable%20task%EF%BC%8CObject%20resule%EF%BC%89%EF%BC%89%0A%0A2.%20%E7%84%B6%E5%90%8E%E5%8F%AF%E4%BB%A5%E6%8A%8A%E5%88%9B%E5%BB%BA%E5%AE%8C%E6%88%90%E7%9A%84**Runnable%E5%AF%B9%E8%B1%A1%E7%9B%B4%E6%8E%A5%E4%BA%A4%E7%BB%99ExecutorService%E6%89%A7%E8%A1%8C**%EF%BC%88ExecutorService.execute%EF%BC%88Runnable%20command%EF%BC%89%EF%BC%89%EF%BC%9B%E6%88%96%E8%80%85%E4%B9%9F%E5%8F%AF%E4%BB%A5%E6%8A%8ARunnable%E5%AF%B9%E8%B1%A1%E6%88%96Callable%E5%AF%B9%E8%B1%A1%E6%8F%90%E4%BA%A4%E7%BB%99ExecutorService%E6%89%A7%E8%A1%8C%EF%BC%88ExecutorService.submit%EF%BC%88Runnable%20task%EF%BC%89%E6%88%96ExecutorService.submit%EF%BC%88Callable%20task%EF%BC%89%EF%BC%89%0A%20%20%20%20%3E**%E6%89%A7%E8%A1%8Cexecute()%E6%96%B9%E6%B3%95%E5%92%8Csubmit()%E6%96%B9%E6%B3%95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8B%E7%9B%B4%E5%88%B0%E4%BB%BB%E5%8A%A1%E5%AE%8C%E6%88%90%EF%BC%8C%E8%80%8C%E4%BD%BF%E7%94%A8get%EF%BC%88long%20timeout%EF%BC%8CTimeUnit%20unit%EF%BC%89%E6%96%B9%E6%B3%95%E5%88%99%E4%BC%9A%E9%98%BB%E5%A1%9E%E5%BD%93%E5%89%8D%E7%BA%BF%E7%A8%8B%E4%B8%80%E6%AE%B5%E6%97%B6%E9%97%B4%E5%90%8E%E7%AB%8B%E5%8D%B3%E8%BF%94%E5%9B%9E%EF%BC%8C%E8%BF%99%E6%97%B6%E5%80%99%E6%9C%89%E5%8F%AF%E8%83%BD%E4%BB%BB%E5%8A%A1%E6%B2%A1%E6%9C%89%E6%89%A7%E8%A1%8C%E5%AE%8C%0A%0A3.%20%E5%A6%82%E6%9E%9C**%E6%89%A7%E8%A1%8CExecutorService.submit**%EF%BC%88%E2%80%A6%EF%BC%89%EF%BC%8CExecutorService%E5%B0%86**%E8%BF%94%E5%9B%9E%E4%B8%80%E4%B8%AA%E5%AE%9E%E7%8E%B0Future%E6%8E%A5%E5%8F%A3%E7%9A%84%E5%AF%B9%E8%B1%A1**%EF%BC%88%E6%88%91%E4%BB%AC%E5%88%9A%E5%88%9A%E4%B9%9F%E6%8F%90%E5%88%B0%E8%BF%87%E4%BA%86%E6%89%A7%E8%A1%8Cexecute()%E6%96%B9%E6%B3%95%E5%92%8Csubmit()%E6%96%B9%E6%B3%95%E7%9A%84%E5%8C%BA%E5%88%AB%EF%BC%8C%E5%88%B0%E7%9B%AE%E5%89%8D%E4%B8%BA%E6%AD%A2%E7%9A%84JDK%E4%B8%AD%EF%BC%8C%E8%BF%94%E5%9B%9E%E7%9A%84%E6%98%AFFutureTask%E5%AF%B9%E8%B1%A1%EF%BC%89%E3%80%82%E7%94%B1%E4%BA%8EFutureTask%E5%AE%9E%E7%8E%B0%E4%BA%86Runnable%EF%BC%8C%E7%A8%8B%E5%BA%8F%E5%91%98%E4%B9%9F%E5%8F%AF%E4%BB%A5%E5%88%9B%E5%BB%BAFutureTask%EF%BC%8C%E7%84%B6%E5%90%8E%E7%9B%B4%E6%8E%A5%E4%BA%A4%E7%BB%99ExecutorService%E6%89%A7%E8%A1%8C%E3%80%82%0A4.%20%E6%9C%80%E5%90%8E%EF%BC%8C%E4%B8%BB%E7%BA%BF%E7%A8%8B%E5%8F%AF%E4%BB%A5**%E6%89%A7%E8%A1%8CFutureTask.get()%E6%96%B9%E6%B3%95%E6%9D%A5%E7%AD%89%E5%BE%85%E4%BB%BB%E5%8A%A1%E6%89%A7%E8%A1%8C%E5%AE%8C%E6%88%90**%E3%80%82%E4%B8%BB%E7%BA%BF%E7%A8%8B%E4%B9%9F%E5%8F%AF%E4%BB%A5%E6%89%A7%E8%A1%8CFutureTask.cancel%EF%BC%88boolean%20mayInterruptIfRunning%EF%BC%89%E6%9D%A5%E5%8F%96%E6%B6%88%E6%AD%A4%E4%BB%BB%E5%8A%A1%E7%9A%84%E6%89%A7%E8%A1%8C%E3%80%82%0A%0A%23%23%23%203.%20ThreadPoolExecutor%E8%AF%A6%E8%A7%A3%0A%E7%BA%BF%E7%A8%8B%E6%B1%A0%E5%AE%9E%E7%8E%B0%E7%B1%BBThreadPoolExecutor%E6%98%AFExecutor%20%E6%A1%86%E6%9E%B6%E6%9C%80%E6%A0%B8%E5%BF%83%E7%9A%84%E7%B1%BB%0A%23%23%23%23%203.1%20ThreadPoolExecutor%E7%B1%BB%E7%9A%84%E5%9B%9B%E4%B8%AA%E6%AF%94%E8%BE%83%E9%87%8D%E8%A6%81%E7%9A%84%E5%B1%9E%E6%80%A7%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/6eac2176-4ff7-4ad8-a71c-77eeb40102ca/f27509ee-8953-44da-b78f-ffcb895622b6.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F599%3A1)%0A%0A%23%23%23%23%203.2%20ThreadPoolExecutor%E7%B1%BB%E4%B8%AD%E6%8F%90%E4%BE%9B%E7%9A%84%E5%9B%9B%E4%B8%AA%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95%0A%60%60%60java%0A%20%2F**%0A%20%20%20%20%20*%20%E7%94%A8%E7%BB%99%E5%AE%9A%E7%9A%84%E5%88%9D%E5%A7%8B%E5%8F%82%E6%95%B0%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E6%96%B0%E7%9A%84ThreadPoolExecutor%E3%80%82%0A%20%20%20%20%20%0A%20%20%20%20%20*%20%40param%20corePoolSize%20%E6%A0%B8%E5%BF%83%E7%BA%BF%E7%A8%8B%E6%B1%A0%E5%A4%A7%E5%B0%8F%0A%20%20%20%20%20%0A%20%20%20%20%20*%20%40param%20maximumPoolSize%20%E6%9C%80%E5%A4%A7%E7%BA%BF%E7%A8%8B%E6%B1%A0%E7%9A%84%E5%A4%A7%E5%B0%8F%0A%20%20%20%20%20%0A%20%20%20%20%20*%20%40param%20keepAliveTime%20%E5%BD%93%E7%BA%BF%E7%A8%8B%E6%B1%A0%E4%B8%AD%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%95%B0%E9%87%8F%E5%A4%A7%E4%BA%8EcorePoolSize%E7%9A%84%E6%97%B6%E5%80%99%EF%BC%8C%E5%A6%82%E6%9E%9C%E8%BF%99%E6%97%B6%E6%B2%A1%E6%9C%89%E6%96%B0%E7%9A%84%E4%BB%BB%E5%8A%A1%E6%8F%90%E4%BA%A4%EF%BC%8C%0A%20%20%20%20%20*%E6%A0%B8%E5%BF%83%E7%BA%BF%E7%A8%8B%E5%A4%96%E7%9A%84%E7%BA%BF%E7%A8%8B%E4%B8%8D%E4%BC%9A%E7%AB%8B%E5%8D%B3%E9%94%80%E6%AF%81%EF%BC%8C%E8%80%8C%E6%98%AF%E4%BC%9A%E7%AD%89%E5%BE%85%EF%BC%8C%E7%9B%B4%E5%88%B0%E7%AD%89%E5%BE%85%E7%9A%84%E6%97%B6%E9%97%B4%E8%B6%85%E8%BF%87%E4%BA%86keepAliveTime%EF%BC%9B%0A%20%20%20%20%20%0A%20%20%20%20%20*%20%40param%20unit%20%20keepAliveTime%E5%8F%82%E6%95%B0%E7%9A%84%E6%97%B6%E9%97%B4%E5%8D%95%E4%BD%8D%0A%20%20%20%20%20%0A%20%20%20%20%20*%20%40param%20workQueue%20%E7%AD%89%E5%BE%85%E9%98%9F%E5%88%97%EF%BC%8C%E5%BD%93%E4%BB%BB%E5%8A%A1%E6%8F%90%E4%BA%A4%E6%97%B6%EF%BC%8C%E5%A6%82%E6%9E%9C%E7%BA%BF%E7%A8%8B%E6%B1%A0%E4%B8%AD%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%95%B0%E9%87%8F%E5%A4%A7%E4%BA%8E%E7%AD%89%E4%BA%8EcorePoolSize%E7%9A%84%E6%97%B6%E5%80%99%EF%BC%8C%E6%8A%8A%E8%AF%A5%E4%BB%BB%E5%8A%A1%E5%B0%81%E8%A3%85%E6%88%90%E4%B8%80%E4%B8%AAWorker%E5%AF%B9%E8%B1%A1%E6%94%BE%E5%85%A5%E7%AD%89%E5%BE%85%E9%98%9F%E5%88%97%EF%BC%9B%0A%20%20%20%20%20*%20%0A%20%20%20%20%20*%20%40param%20threadFactory%20%E6%89%A7%E8%A1%8C%E8%80%85%E5%88%9B%E5%BB%BA%E6%96%B0%E7%BA%BF%E7%A8%8B%E6%97%B6%E4%BD%BF%E7%94%A8%E7%9A%84%E5%B7%A5%E5%8E%82%0A%20%20%20%20%20%0A%20%20%20%20%20*%20%40param%20handler%20RejectedExecutionHandler%E7%B1%BB%E5%9E%8B%E7%9A%84%E5%8F%98%E9%87%8F%EF%BC%8C%E8%A1%A8%E7%A4%BA%E7%BA%BF%E7%A8%8B%E6%B1%A0%E7%9A%84%E9%A5%B1%E5%92%8C%E7%AD%96%E7%95%A5%E3%80%82%0A%20%20%20%20%20*%20%E5%A6%82%E6%9E%9C%E9%98%BB%E5%A1%9E%E9%98%9F%E5%88%97%E6%BB%A1%E4%BA%86%E5%B9%B6%E4%B8%94%E6%B2%A1%E6%9C%89%E7%A9%BA%E9%97%B2%E7%9A%84%E7%BA%BF%E7%A8%8B%EF%BC%8C%E8%BF%99%E6%97%B6%E5%A6%82%E6%9E%9C%E7%BB%A7%E7%BB%AD%E6%8F%90%E4%BA%A4%E4%BB%BB%E5%8A%A1%EF%BC%8C%E5%B0%B1%E9%9C%80%E8%A6%81%E9%87%87%E5%8F%96%E4%B8%80%E7%A7%8D%E7%AD%96%E7%95%A5%E5%A4%84%E7%90%86%E8%AF%A5%E4%BB%BB%E5%8A%A1%E3%80%82%0A%20%20%20%20%20*%20%E7%BA%BF%E7%A8%8B%E6%B1%A0%E6%8F%90%E4%BE%9B%E4%BA%864%E7%A7%8D%E7%AD%96%E7%95%A5%EF%BC%9A%0A%20%20%20%20%20%20%20%201.AbortPolicy%EF%BC%9A%E7%9B%B4%E6%8E%A5%E6%8A%9B%E5%87%BA%E5%BC%82%E5%B8%B8%EF%BC%8C%E8%BF%99%E6%98%AF%E9%BB%98%E8%AE%A4%E7%AD%96%E7%95%A5%EF%BC%9B%0A%20%20%20%20%20%20%20%202.CallerRunsPolicy%EF%BC%9A%E7%94%A8%E8%B0%83%E7%94%A8%E8%80%85%E6%89%80%E5%9C%A8%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%9D%A5%E6%89%A7%E8%A1%8C%E4%BB%BB%E5%8A%A1%EF%BC%9B%0A%20%20%20%20%20%20%20%203.DiscardOldestPolicy%EF%BC%9A%E4%B8%A2%E5%BC%83%E9%98%BB%E5%A1%9E%E9%98%9F%E5%88%97%E4%B8%AD%E9%9D%A0%E6%9C%80%E5%89%8D%E7%9A%84%E4%BB%BB%E5%8A%A1%EF%BC%8C%E5%B9%B6%E6%89%A7%E8%A1%8C%E5%BD%93%E5%89%8D%E4%BB%BB%E5%8A%A1%EF%BC%9B%0A%20%20%20%20%20%20%20%204.DiscardPolicy%EF%BC%9A%E7%9B%B4%E6%8E%A5%E4%B8%A2%E5%BC%83%E4%BB%BB%E5%8A%A1%EF%BC%9B%0A%20%20%20%20%20*%2F%0A%20%20%20%20public%20ThreadPoolExecutor(int%20corePoolSize%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20int%20maximumPoolSize%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20long%20keepAliveTime%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20TimeUnit%20unit%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20BlockingQueue%3CRunnable%3E%20workQueue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20ThreadFactory%20threadFactory%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20RejectedExecutionHandler%20handler)%20%7B%0A%20%20%20%20%20%20%20%20if%20(corePoolSize%20%3C%200%20%7C%7C%0A%20%20%20%20%20%20%20%20%20%20%20%20maximumPoolSize%20%3C%3D%200%20%7C%7C%0A%20%20%20%20%20%20%20%20%20%20%20%20maximumPoolSize%20%3C%20corePoolSize%20%7C%7C%0A%20%20%20%20%20%20%20%20%20%20%20%20keepAliveTime%20%3C%200)%0A%20%20%20%20%20%20%20%20%20%20%20%20throw%20new%20IllegalArgumentException()%3B%0A%20%20%20%20%20%20%20%20if%20(workQueue%20%3D%3D%20null%20%7C%7C%20threadFactory%20%3D%3D%20null%20%7C%7C%20handler%20%3D%3D%20null)%0A%20%20%20%20%20%20%20%20%20%20%20%20throw%20new%20NullPointerException()%3B%0A%20%20%20%20%20%20%20%20this.corePoolSize%20%3D%20corePoolSize%3B%0A%20%20%20%20%20%20%20%20this.maximumPoolSize%20%3D%20maximumPoolSize%3B%0A%20%20%20%20%20%20%20%20this.workQueue%20%3D%20workQueue%3B%0A%20%20%20%20%20%20%20%20this.keepAliveTime%20%3D%20unit.toNanos(keepAliveTime)%3B%0A%20%20%20%20%20%20%20%20this.threadFactory%20%3D%20threadFactory%3B%0A%20%20%20%20%20%20%20%20this.handler%20%3D%20handler%3B%0A%20%20%20%20%7D%0A%60%60%60%0A%0A%23%23%23%23%203.3%20%E5%A6%82%E4%BD%95%E5%88%9B%E5%BB%BAThreadPoolExecutor%0A%E5%9C%A8%E3%80%8A%E9%98%BF%E9%87%8C%E5%B7%B4%E5%B7%B4Java%E5%BC%80%E5%8F%91%E6%89%8B%E5%86%8C%E3%80%8B%E2%80%9C%E5%B9%B6%E5%8F%91%E5%A4%84%E7%90%86%E2%80%9D%E8%BF%99%E4%B8%80%E7%AB%A0%E8%8A%82%EF%BC%8C%E6%98%8E%E7%A1%AE%E6%8C%87%E5%87%BA%E7%BA%BF%E7%A8%8B%E8%B5%84%E6%BA%90%E5%BF%85%E9%A1%BB%E9%80%9A%E8%BF%87%E7%BA%BF%E7%A8%8B%E6%B1%A0%E6%8F%90%E4%BE%9B%EF%BC%8C%E4%B8%8D%E5%85%81%E8%AE%B8%E5%9C%A8%E5%BA%94%E7%94%A8%E4%B8%AD%E8%87%AA%E8%A1%8C%E6%98%BE%E7%A4%BA%E5%88%9B%E5%BB%BA%E7%BA%BF%E7%A8%8B%E3%80%82%0A%0A**%E4%B8%BA%E4%BB%80%E4%B9%88%E5%91%A2%EF%BC%9F**%0A%3E%E4%BD%BF%E7%94%A8%E7%BA%BF%E7%A8%8B%E6%B1%A0%E7%9A%84%E5%A5%BD%E5%A4%84%E6%98%AF%E5%87%8F%E5%B0%91%E5%9C%A8%E5%88%9B%E5%BB%BA%E5%92%8C%E9%94%80%E6%AF%81%E7%BA%BF%E7%A8%8B%E4%B8%8A%E6%89%80%E6%B6%88%E8%80%97%E7%9A%84%E6%97%B6%E9%97%B4%E4%BB%A5%E5%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%A1%8C%E8%A7%84%E5%88%99%EF%BC%8C%E8%A7%84%E9%81%BF%E8%B5%84%E6%BA%90%E8%80%97%E5%B0%BD%E7%9A%84%E9%A3%8E%E9%99%A9%0A%0A%3EExecutors%20%E8%BF%94%E5%9B%9E%E7%BA%BF%E7%A8%8B%E6%B1%A0%E5%AF%B9%E8%B1%A1%E7%9A%84%E5%BC%8A%E7%AB%AF%E5%A6%82%E4%B8%8B%EF%BC%9A%0A%0A%3E*%20FixedThreadPool%20%E5%92%8C%20SingleThreadExecutor%20%EF%BC%9A%20%E5%85%81%E8%AE%B8%E8%AF%B7%E6%B1%82%E7%9A%84%E9%98%9F%E5%88%97%E9%95%BF%E5%BA%A6%E4%B8%BA%20Integer.MAX_VALUE%2C%E5%8F%AF%E8%83%BD%E5%A0%86%E7%A7%AF%E5%A4%A7%E9%87%8F%E7%9A%84%E8%AF%B7%E6%B1%82%EF%BC%8C%E4%BB%8E%E8%80%8C%E5%AF%BC%E8%87%B4OOM%E3%80%82%0A%3E*%20CachedThreadPool%20%E5%92%8C%20ScheduledThreadPool%20%EF%BC%9A%20%E5%85%81%E8%AE%B8%E5%88%9B%E5%BB%BA%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%95%B0%E9%87%8F%E4%B8%BA%20Integer.MAX_VALUE%20%EF%BC%8C%E5%8F%AF%E8%83%BD%E4%BC%9A%E5%88%9B%E5%BB%BA%E5%A4%A7%E9%87%8F%E7%BA%BF%E7%A8%8B%EF%BC%8C%E4%BB%8E%E8%80%8C%E5%AF%BC%E8%87%B4OOM%E3%80%82%0A%0A**%E6%96%B9%E5%BC%8F%E4%B8%80%EF%BC%9A%E9%80%9A%E8%BF%87%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95%E5%AE%9E%E7%8E%B0**%0A%0A**%E6%96%B9%E5%BC%8F%E4%BA%8C%EF%BC%9A%E9%80%9A%E8%BF%87Executor%20%E6%A1%86%E6%9E%B6%E7%9A%84%E5%B7%A5%E5%85%B7%E7%B1%BBExecutors%E6%9D%A5%E5%AE%9E%E7%8E%B0**%0A*%20%E6%88%91%E4%BB%AC%E5%8F%AF%E4%BB%A5%E5%88%9B%E5%BB%BA%E4%B8%89%E7%A7%8D%E7%B1%BB%E5%9E%8B%E7%9A%84ThreadPoolExecutor%EF%BC%9A%0A%20%20%20%20%3E**FixedThreadPool**%0A%20%20%20%20%3E**SingleThreadExecutor**%0A%20%20%20%20%3E**CachedThreadPool**%0A%20%20%20%20%E5%BA%95%E5%B1%82%E9%83%BD%E6%98%AF%E8%B0%83%E7%94%A8%E7%9A%84ThreadPoolExecutor%E7%9A%84%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95%0A%20%20%20%20%0A%23%23%23%23%203.4%20FixedThreadPool%E8%AF%A6%E8%A7%A3%0A%23%23%23%23%23%20FixedThreadPool%E8%A2%AB%E7%A7%B0%E4%B8%BA%E5%8F%AF%E9%87%8D%E7%94%A8%E5%9B%BA%E5%AE%9A%E7%BA%BF%E7%A8%8B%E6%95%B0%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%B1%A0%E3%80%82%0A%60%60%60java%0A%20%2F**%0A%20%20%20%20%20*%20%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E5%8F%AF%E9%87%8D%E7%94%A8%E5%9B%BA%E5%AE%9A%E6%95%B0%E9%87%8F%E7%BA%BF%E7%A8%8B%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%B1%A0%0A%09%20*%E5%9C%A8%E4%BB%BB%E4%BD%95%E6%97%B6%E5%80%99%E8%87%B3%E5%A4%9A%E6%9C%89n%E4%B8%AA%E7%BA%BF%E7%A8%8B%E5%A4%84%E4%BA%8E%E6%B4%BB%E5%8A%A8%E7%8A%B6%E6%80%81%0A%09%20*%E5%A6%82%E6%9E%9C%E5%9C%A8%E6%89%80%E6%9C%89%E7%BA%BF%E7%A8%8B%E5%A4%84%E4%BA%8E%E6%B4%BB%E5%8A%A8%E7%8A%B6%E6%80%81%E6%97%B6%E6%8F%90%E4%BA%A4%E5%85%B6%E4%BB%96%E4%BB%BB%E5%8A%A1%EF%BC%8C%E5%88%99%E5%AE%83%E4%BB%AC%E5%B0%86%E5%9C%A8%E9%98%9F%E5%88%97%E4%B8%AD%E7%AD%89%E5%BE%85%EF%BC%8C%0A%09%20*%E7%9B%B4%E5%88%B0%E7%BA%BF%E7%A8%8B%E5%8F%AF%E7%94%A8%E3%80%82%20%E5%A6%82%E6%9E%9C%E4%BB%BB%E4%BD%95%E7%BA%BF%E7%A8%8B%E5%9C%A8%E5%85%B3%E9%97%AD%E4%B9%8B%E5%89%8D%E7%9A%84%E6%89%A7%E8%A1%8C%E6%9C%9F%E9%97%B4%E7%94%B1%E4%BA%8E%E5%A4%B1%E8%B4%A5%E8%80%8C%E7%BB%88%E6%AD%A2%EF%BC%8C%0A%09%20*%E5%A6%82%E6%9E%9C%E9%9C%80%E8%A6%81%E6%89%A7%E8%A1%8C%E5%90%8E%E7%BB%AD%E4%BB%BB%E5%8A%A1%EF%BC%8C%E5%88%99%E4%B8%80%E4%B8%AA%E6%96%B0%E7%9A%84%E7%BA%BF%E7%A8%8B%E5%B0%86%E5%8F%96%E4%BB%A3%E5%AE%83%E3%80%82%E6%B1%A0%E4%B8%AD%E7%9A%84%E7%BA%BF%E7%A8%8B%E5%B0%86%E4%B8%80%E7%9B%B4%E5%AD%98%E5%9C%A8%0A%09%20*%E7%9F%A5%E9%81%93%E8%B0%83%E7%94%A8shutdown%E6%96%B9%E6%B3%95%0A%20%20%20%20%20%0A%20%20%20%20%20*%20%40param%20nThreads%20%E7%BA%BF%E7%A8%8B%E6%B1%A0%E4%B8%AD%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%95%B0%0A%20%20%20%20%20*%20%40param%20threadFactory%20%E5%88%9B%E5%BB%BA%E6%96%B0%E7%BA%BF%E7%A8%8B%E6%97%B6%E4%BD%BF%E7%94%A8%E7%9A%84factory%0A%20%20%20%20%20*%20%40return%20%E6%96%B0%E5%88%9B%E5%BB%BA%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%B1%A0%0A%20%20%20%20%20*%20%40throws%20NullPointerException%20%E5%A6%82%E6%9E%9CthreadFactory%E4%B8%BAnull%0A%20%20%20%20%20*%20%40throws%20IllegalArgumentException%20if%20%7B%40code%20nThreads%20%3C%3D%200%7D%0A%20%20%20%20%20*%2F%0A%20%20%20%20public%20static%20ExecutorService%20newFixedThreadPool(int%20nThreads%2C%20ThreadFactory%20threadFactory)%20%7B%0A%20%20%20%20%20%20%20%20return%20new%20ThreadPoolExecutor(nThreads%2C%20nThreads%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%200L%2C%20TimeUnit.MILLISECONDS%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20new%20LinkedBlockingQueue%3CRunnable%3E()%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20threadFactory)%3B%0A%20%20%20%20%7D%0A%60%60%60%0A%0A%60%60%60java%0A%20public%20static%20ExecutorService%20newFixedThreadPool(int%20nThreads)%20%7B%0A%20%20%20%20%20%20%20%20return%20new%20ThreadPoolExecutor(nThreads%2C%20nThreads%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%200L%2C%20TimeUnit.MILLISECONDS%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20new%20LinkedBlockingQueue%3CRunnable%3E())%3B%0A%20%20%20%20%7D%0A%60%60%60%0A**%E6%96%B0%E5%88%9B%E5%BB%BA%E7%9A%84FixedThreadPool%E7%9A%84corePoolSize%E5%92%8CmaximumPoolSize%E9%83%BD%E8%A2%AB%E8%AE%BE%E7%BD%AE%E4%B8%BAnThreads%E3%80%82**%0A-%20-%20-%0A%23%23%23%23%23%20FixedThreadPool%E7%9A%84execute()%E6%96%B9%E6%B3%95%E8%BF%90%E8%A1%8C%E7%A4%BA%E6%84%8F%E5%9B%BE%0A%0A%3E!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/6eac2176-4ff7-4ad8-a71c-77eeb40102ca/fb0c8afd-747f-441a-b98e-3aeec9d5c714.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F597%3A1)%0A%0A%E4%B8%8A%E5%9B%BE%E8%AF%B4%E6%98%8E%EF%BC%9A%0A%3E1.%20%E5%A6%82%E6%9E%9C%E5%BD%93%E5%89%8D%E8%BF%90%E8%A1%8C%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%95%B0%E5%B0%8F%E4%BA%8EcorePoolSize%EF%BC%8C%E5%88%99%E5%88%9B%E5%BB%BA%E6%96%B0%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%9D%A5%E6%89%A7%E8%A1%8C%E4%BB%BB%E5%8A%A1%EF%BC%9B%0A%3E2.%20%E5%BD%93%E5%89%8D%E8%BF%90%E8%A1%8C%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%95%B0%E7%AD%89%E4%BA%8EcorePoolSize%E5%90%8E%EF%BC%8C%E5%B0%86%E4%BB%BB%E5%8A%A1%E5%8A%A0%E5%85%A5LinkedBlockingQueue%EF%BC%9B%0A%3E3.%20%E7%BA%BF%E7%A8%8B%E6%89%A7%E8%A1%8C%E5%AE%8C1%E4%B8%AD%E7%9A%84%E4%BB%BB%E5%8A%A1%E5%90%8E%EF%BC%8C%E4%BC%9A%E5%9C%A8%E5%BE%AA%E7%8E%AF%E4%B8%AD%E5%8F%8D%E5%A4%8D%E4%BB%8ELinkedBlockingQueue%E4%B8%AD%E8%8E%B7%E5%8F%96%E4%BB%BB%E5%8A%A1%E6%9D%A5%E6%89%A7%E8%A1%8C%EF%BC%9B%0A%0A%23%23%23%23%23%20FixedThreadPool%E4%BD%BF%E7%94%A8%E6%97%A0%E7%95%8C%E9%98%9F%E5%88%97%20LinkedBlockingQueue%EF%BC%88%E9%98%9F%E5%88%97%E7%9A%84%E5%AE%B9%E9%87%8F%E4%B8%BAIntger.MAX_VALUE%EF%BC%89%E4%BD%9C%E4%B8%BA%E7%BA%BF%E7%A8%8B%E6%B1%A0%E7%9A%84%E5%B7%A5%E4%BD%9C%E9%98%9F%E5%88%97%E4%BC%9A%E5%AF%B9%E7%BA%BF%E7%A8%8B%E6%B1%A0%E5%B8%A6%E6%9D%A5%E5%A6%82%E4%B8%8B%E5%BD%B1%E5%93%8D%EF%BC%9A%0A%3E1.%20%E5%BD%93%E7%BA%BF%E7%A8%8B%E6%B1%A0%E4%B8%AD%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%95%B0%E8%BE%BE%E5%88%B0corePoolSize%E5%90%8E%EF%BC%8C%E6%96%B0%E4%BB%BB%E5%8A%A1%E5%B0%86%E5%9C%A8%E6%97%A0%E7%95%8C%E9%98%9F%E5%88%97%E4%B8%AD%E7%AD%89%E5%BE%85%EF%BC%8C%E5%9B%A0%E6%AD%A4%E7%BA%BF%E7%A8%8B%E6%B1%A0%E4%B8%AD%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%95%B0%E4%B8%8D%E4%BC%9A%E8%B6%85%E8%BF%87corePoolSize%EF%BC%9B%0A%3E2.%20%E7%94%B1%E4%BA%8E1%EF%BC%8C%E4%BD%BF%E7%94%A8%E6%97%A0%E7%95%8C%E9%98%9F%E5%88%97%E6%97%B6maximumPoolSize%E5%B0%86%E6%98%AF%E4%B8%80%E4%B8%AA%E6%97%A0%E6%95%88%E5%8F%82%E6%95%B0%EF%BC%9B%0A%3E3.%20%E7%94%B1%E4%BA%8E1%E5%92%8C2%EF%BC%8C%E4%BD%BF%E7%94%A8%E6%97%A0%E7%95%8C%E9%98%9F%E5%88%97%E6%97%B6keepAliveTime%E5%B0%86%E6%98%AF%E4%B8%80%E4%B8%AA%E6%97%A0%E6%95%88%E5%8F%82%E6%95%B0%EF%BC%9B%0A%3E4.%20%E8%BF%90%E8%A1%8C%E4%B8%AD%E7%9A%84FixedThreadPool%EF%BC%88%E6%9C%AA%E6%89%A7%E8%A1%8Cshutdown()%E6%88%96shutdownNow()%E6%96%B9%E6%B3%95%EF%BC%89%E4%B8%8D%E4%BC%9A%E6%8B%92%E7%BB%9D%E4%BB%BB%E5%8A%A1%0A%0A%23%23%23%23%203.5%20SingleThreadExecutor%E8%AF%A6%E8%A7%A3%0A%23%23%23%23%23%20SingleThreadExecutor%E6%98%AF%E4%BD%BF%E7%94%A8%E5%8D%95%E4%B8%AAworker%E7%BA%BF%E7%A8%8B%E7%9A%84Executor%E3%80%82%0A%60%60%60java%0A%2F**%0A%20%20%20%20%20*%E5%88%9B%E5%BB%BA%E4%BD%BF%E7%94%A8%E5%8D%95%E4%B8%AAworker%E7%BA%BF%E7%A8%8B%E8%BF%90%E8%A1%8C%E6%97%A0%E7%95%8C%E9%98%9F%E5%88%97%E7%9A%84Executor%0A%09%20*%E5%B9%B6%E4%BD%BF%E7%94%A8%E6%8F%90%E4%BE%9B%E7%9A%84ThreadFactory%E5%9C%A8%E9%9C%80%E8%A6%81%E6%97%B6%E5%88%9B%E5%BB%BA%E6%96%B0%E7%BA%BF%E7%A8%8B%0A%20%20%20%20%20*%0A%20%20%20%20%20*%20%40param%20threadFactory%20%E5%88%9B%E5%BB%BA%E6%96%B0%E7%BA%BF%E7%A8%8B%E6%97%B6%E4%BD%BF%E7%94%A8%E7%9A%84factory%0A%20%20%20%20%20*%0A%20%20%20%20%20*%20%40return%20%E6%96%B0%E5%88%9B%E5%BB%BA%E7%9A%84%E5%8D%95%E7%BA%BF%E7%A8%8BExecutor%0A%20%20%20%20%20*%20%40throws%20NullPointerException%20%E5%A6%82%E6%9E%9CThreadFactory%E4%B8%BA%E7%A9%BA%0A%20%20%20%20%20*%2F%0A%20%20%20%20public%20static%20ExecutorService%20newSingleThreadExecutor(ThreadFactory%20threadFactory)%20%7B%0A%20%20%20%20%20%20%20%20return%20new%20FinalizableDelegatedExecutorService%0A%20%20%20%20%20%20%20%20%20%20%20%20(new%20ThreadPoolExecutor(1%2C%201%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%200L%2C%20TimeUnit.MILLISECONDS%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20new%20LinkedBlockingQueue%3CRunnable%3E()%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20threadFactory))%3B%0A%20%20%20%20%7D%0A%60%60%60%0A%0A%60%60%60java%0Apublic%20static%20ExecutorService%20newSingleThreadExecutor()%20%7B%0A%20%20%20%20%20%20%20%20return%20new%20FinalizableDelegatedExecutorService%0A%20%20%20%20%20%20%20%20%20%20%20%20(new%20ThreadPoolExecutor(1%2C%201%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%200L%2C%20TimeUnit.MILLISECONDS%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20new%20LinkedBlockingQueue%3CRunnable%3E()))%3B%0A%20%20%20%20%7D%0A%60%60%60%0A**%E6%96%B0%E5%88%9B%E5%BB%BA%E7%9A%84SingleThreadExecutor%E7%9A%84corePoolSize%E5%92%8CmaximumPoolSize%E9%83%BD%E8%A2%AB%E8%AE%BE%E7%BD%AE%E4%B8%BA1.%0A%E5%85%B6%E4%BB%96%E5%8F%82%E6%95%B0%E5%92%8CFixedThreadPool%E7%9B%B8%E5%90%8C%E3%80%82SingleThreadExecutor%E4%BD%BF%E7%94%A8%E6%97%A0%E7%95%8C%E9%98%9F%E5%88%97LinkedBlockingQueue%E4%BD%9C%E4%B8%BA%E7%BA%BF%E7%A8%8B%E6%B1%A0%E7%9A%84%E5%B7%A5%E4%BD%9C%E9%98%9F%E5%88%97%EF%BC%88%E9%98%9F%E5%88%97%E7%9A%84%E5%AE%B9%E9%87%8F%E4%B8%BAIntger.MAX_VALUE%EF%BC%89**%0A%3ESingleThreadExecutor%E4%BD%BF%E7%94%A8%E6%97%A0%E7%95%8C%E9%98%9F%E5%88%97%E4%BD%9C%E4%B8%BA%E7%BA%BF%E7%A8%8B%E6%B1%A0%E7%9A%84%E5%B7%A5%E4%BD%9C%E9%98%9F%E5%88%97%E4%BC%9A%E5%AF%B9%E7%BA%BF%E7%A8%8B%E6%B1%A0%E5%B8%A6%E6%9D%A5%E7%9A%84%E5%BD%B1%E5%93%8D%E4%B8%8EFixedThreadPool%E7%9B%B8%E5%90%8C%E3%80%82%0A%0A%23%23%23%23%23%20%20SingleThreadExecutor%E7%9A%84%E8%BF%90%E8%A1%8C%E7%A4%BA%E6%84%8F%E5%9B%BE%0A%3E!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/6eac2176-4ff7-4ad8-a71c-77eeb40102ca/c8a80e3c-199d-41ef-9f8c-6a8a4704080c.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F602%3A1)%0A%0A%E4%B8%8A%E5%9B%BE%E8%AF%B4%E6%98%8E%3A%0A%3E1.%20%E5%A6%82%E6%9E%9C%E5%BD%93%E5%89%8D%E8%BF%90%E8%A1%8C%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%95%B0%E5%B0%91%E4%BA%8EcorePoolSize%EF%BC%8C%E5%88%99%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E6%96%B0%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%89%A7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7%94%A8%E5%AE%83%EF%BC%8C%0A%09%20*%E5%B9%B6%E5%9C%A8%E9%9C%80%E8%A6%81%E6%97%B6%E4%BD%BF%E7%94%A8%E6%8F%90%E4%BE%9B%E7%9A%84ThreadFactory%E5%88%9B%E5%BB%BA%E6%96%B0%E7%BA%BF%E7%A8%8B%E3%80%82%0A%20%20%20%20%20*%20%40param%20threadFactory%20%E5%88%9B%E5%BB%BA%E6%96%B0%E7%BA%BF%E7%A8%8B%E4%BD%BF%E7%94%A8%E7%9A%84factory%0A%20%20%20%20%20*%20%40return%20%E6%96%B0%E5%88%9B%E5%BB%BA%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%B1%A0%0A%20%20%20%20%20*%20%40throws%20NullPointerException%20%E5%A6%82%E6%9E%9CthreadFactory%E4%B8%BA%E7%A9%BA%0A%20%20%20%20%20*%2F%0A%20%20%20%20public%20static%20ExecutorService%20newCachedThreadPool(ThreadFactory%20threadFactory)%20%7B%0A%20%20%20%20%20%20%20%20return%20new%20ThreadPoolExecutor(0%2C%20Integer.MAX_VALUE%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2060L%2C%20TimeUnit.SECONDS%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20new%20SynchronousQueue%3CRunnable%3E()%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20threadFactory)%3B%0A%20%20%20%20%7D%0A%60%60%60%0A%0A%60%60%60java%0Apublic%20static%20ExecutorService%20newCachedThreadPool()%20%7B%0A%20%20%20%20%20%20%20%20return%20new%20ThreadPoolExecutor(0%2C%20Integer.MAX_VALUE%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2060L%2C%20TimeUnit.SECONDS%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20new%20SynchronousQueue%3CRunnable%3E())%3B%0A%20%20%20%20%7D%0A%60%60%60%0A**CachedThreadPool%E7%9A%84corePoolSize%E8%A2%AB%E8%AE%BE%E7%BD%AE%E4%B8%BA%E7%A9%BA%EF%BC%880%EF%BC%89%EF%BC%8CmaximumPoolSize%E8%A2%AB%E8%AE%BE%E7%BD%AE%E4%B8%BAInteger.MAX.VALUE%EF%BC%8C%E5%8D%B3%E5%AE%83%E6%98%AF%E6%97%A0%E7%95%8C%E7%9A%84%EF%BC%8C%E8%BF%99%E4%B9%9F%E5%B0%B1%E6%84%8F%E5%91%B3%E7%9D%80%E5%A6%82%E6%9E%9C%E4%B8%BB%E7%BA%BF%E7%A8%8B%E6%8F%90%E4%BA%A4%E4%BB%BB%E5%8A%A1%E7%9A%84%E9%80%9F%E5%BA%A6%E9%AB%98%E4%BA%8EmaximumPool%E4%B8%AD%E7%BA%BF%E7%A8%8B%E5%A4%84%E7%90%86%E4%BB%BB%E5%8A%A1%E7%9A%84%E9%80%9F%E5%BA%A6%E6%97%B6%EF%BC%8CCachedThreadPool%E4%BC%9A%E4%B8%8D%E6%96%AD%E5%88%9B%E5%BB%BA%E6%96%B0%E7%9A%84%E7%BA%BF%E7%A8%8B**%0A%E6%9E%81%E7%AB%AF%E6%83%85%E5%86%B5%E4%B8%8B%EF%BC%8C%E8%BF%99%E6%A0%B7%E4%BC%9A%E5%AF%BC%E8%87%B4%E8%80%97%E5%B0%BDcpu%E5%92%8C%E5%86%85%E5%AD%98%E8%B5%84%E6%BA%90%E3%80%82%0A%0A%23%23%23%23%23%20CachedThreadPool%E7%9A%84execute()%E6%96%B9%E6%B3%95%E7%9A%84%E6%89%A7%E8%A1%8C%E7%A4%BA%E6%84%8F%E5%9B%BE%0A%3E!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/6eac2176-4ff7-4ad8-a71c-77eeb40102ca/cb47d533-7df7-4b44-94ff-11070c0b6165.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F600%3A1)%0A%0A%E4%B8%8A%E5%9B%BE%E8%AF%B4%E6%98%8E%EF%BC%9A%0A%3E1.%20%E9%A6%96%E5%85%88%E6%89%A7%E8%A1%8CSynchronousQueue.offer(Runnable%20task)%E3%80%82%E5%A6%82%E6%9E%9C%E5%BD%93%E5%89%8DmaximumPool%E4%B8%AD%E6%9C%89%E9%97%B2%E7%BA%BF%E7%A8%8B%E6%AD%A3%E5%9C%A8%E6%89%A7%E8%A1%8CSynchronousQueue.poll(keepAliveTime%2CTimeUnit.NANOSECONDS)%EF%BC%8C%E9%82%A3%E4%B9%88%E4%B8%BB%E7%BA%BF%E7%A8%8B%E6%89%A7%E8%A1%8Coffer%E6%93%8D%E4%BD%9C%E4%B8%8E%E7%A9%BA%E9%97%B2%E7%BA%BF%E7%A8%8B%E6%89%A7%E8%A1%8C%E7%9A%84poll%E6%93%8D%E4%BD%9C%E9%85%8D%E5%AF%B9%E6%88%90%E5%8A%9F%EF%BC%8C%E4%B8%BB%E7%BA%BF%E7%A8%8B%E6%8A%8A%E4%BB%BB%E5%8A%A1%E4%BA%A4%E7%BB%99%E7%A9%BA%E9%97%B2%E7%BA%BF%E7%A8%8B%E6%89%A7%E8%A1%8C%EF%BC%8Cexecute()%E6%96%B9%E6%B3%95%E6%89%A7%E8%A1%8C%E5%AE%8C%E6%88%90%EF%BC%8C%E5%90%A6%E5%88%99%E6%89%A7%E8%A1%8C%E4%B8%8B%E9%9D%A2%E7%9A%84%E6%AD%A5%E9%AA%A42%EF%BC%9B%0A%3E2.%20%E5%BD%93%E5%88%9D%E5%A7%8BmaximumPool%E4%B8%BA%E7%A9%BA%EF%BC%8C%E6%88%96%E8%80%85maximumPool%E4%B8%AD%E6%B2%A1%E6%9C%89%E7%A9%BA%E9%97%B2%E7%BA%BF%E7%A8%8B%E6%97%B6%EF%BC%8C%E5%B0%86%E6%B2%A1%E6%9C%89%E7%BA%BF%E7%A8%8B%E6%89%A7%E8%A1%8CSynchronousQueue.poll(keepAliveTime%2CTimeUnit.NANOSECONDS)%E3%80%82%E8%BF%99%E7%A7%8D%E6%83%85%E5%86%B5%E4%B8%8B%EF%BC%8C%E6%AD%A5%E9%AA%A41%E5%B0%86%E5%A4%B1%E8%B4%A5%EF%BC%8C%E6%AD%A4%E6%97%B6CachedThreadPool%E4%BC%9A%E5%88%9B%E5%BB%BA%E6%96%B0%E7%BA%BF%E7%A8%8B%E6%89%A7%E8%A1%8C%E4%BB%BB%E5%8A%A1%EF%BC%8Cexecute%E6%96%B9%E6%B3%95%E6%89%A7%E8%A1%8C%E5%AE%8C%E6%88%90%EF%BC%9B%0A%0A%23%23%23%23%203.7%20ThreadPoolExecutor%E4%BD%BF%E7%94%A8%E7%A4%BA%E4%BE%8B%0A%20%E9%A6%96%E5%85%88%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AARunnable%E6%8E%A5%E5%8F%A3%E7%9A%84%E5%AE%9E%E7%8E%B0%E7%B1%BBWorkerThread%0A%20%60%60%60java%0Apublic%20class%20ThreadPoolExecutorDemo%20%7B%0A%0A%20%20%20%20public%20static%20void%20main(String%5B%5D%20args)%20%7B%0A%20%20%20%20%20%20%20%20%2F%2F%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AAFixedThreadPool%E5%AF%B9%E8%B1%A1%0A%20%20%20%20%20%20%20%20ExecutorService%20executor%20%3D%20Executors.newFixedThreadPool(5)%3B%0A%20%20%20%20%20%20%20%20for%20(int%20i%20%3D%200%3B%20i%20%3C%2010%3B%20i%2B%2B)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%E5%88%9B%E5%BB%BAWorkerThread%E5%AF%B9%E8%B1%A1%EF%BC%88WorkerThread%E7%B1%BB%E5%AE%9E%E7%8E%B0%E4%BA%86Runnable%20%E6%8E%A5%E5%8F%A3%EF%BC%89%0A%20%20%20%20%20%20%20%20%20%20%20%20Runnable%20worker%20%3D%20new%20WorkerThread(%22%22%20%2B%20i)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%E6%89%A7%E8%A1%8CRunnable%0A%20%20%20%20%20%20%20%20%20%20%20%20executor.execute(worker)%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%2F%2F%E7%BB%88%E6%AD%A2%E7%BA%BF%E7%A8%8B%E6%B1%A0%0A%20%20%20%20%20%20%20%20executor.shutdown()%3B%0A%20%20%20%20%20%20%20%20while%20(!executor.isTerminated())%20%7B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20System.out.println(%22Finished%20all%20threads%22)%3B%0A%20%20%20%20%7D%0A%7D%0A%60%60%60%0A-%20-%20-%0A**shutdown%EF%BC%88%EF%BC%89VS%20shutdownNow%EF%BC%88%EF%BC%89**%0A%3E1.%20shutdown%EF%BC%88%EF%BC%89%E6%96%B9%E6%B3%95%E8%A1%A8%E6%98%8E%E5%85%B3%E9%97%AD%E5%B7%B2%E5%9C%A8Executor%E4%B8%8A%E8%B0%83%E7%94%A8%EF%BC%8C%E5%9B%A0%E6%AD%A4%E4%B8%8D%E4%BC%9A%E5%86%8D%E5%90%91DelayedPool%E6%B7%BB%E5%8A%A0%E4%BB%BB%E4%BD%95%E5%85%B6%E4%BB%96%E4%BB%BB%E5%8A%A1%EF%BC%88%E7%94%B1ScheduledThreadPoolExecutor%E7%B1%BB%E5%9C%A8%E5%86%85%E9%83%A8%E4%BD%BF%E7%94%A8%EF%BC%89%2C%C2%A0%E4%BD%86%E6%98%AF%EF%BC%8C%E5%B7%B2%E7%BB%8F%E5%9C%A8%E9%98%9F%E5%88%97%E4%B8%AD%E6%8F%90%E4%BA%A4%E7%9A%84%E4%BB%BB%E5%8A%A1%E5%B0%86%E8%A2%AB%E5%85%81%E8%AE%B8%E5%AE%8C%E6%88%90%E3%80%82%0A%3E2.%20shutdownNow%EF%BC%88%EF%BC%89%E6%96%B9%E6%B3%95%E8%AF%95%E5%9B%BE%E7%BB%88%E6%AD%A2%E5%BD%93%E5%89%8D%E6%AD%A3%E5%9C%A8%E8%BF%90%E8%A1%8C%E7%9A%84%E4%BB%BB%E5%8A%A1%EF%BC%8C%E5%B9%B6%E5%81%9C%E6%AD%A2%E5%A4%84%E7%90%86%E6%8E%92%E9%98%9F%E7%9A%84%E4%BB%BB%E5%8A%A1%E5%B9%B6%E8%BF%94%E5%9B%9E%E6%AD%A3%E5%9C%A8%E7%AD%89%E5%BE%85%E6%89%A7%E8%A1%8C%E7%9A%84List%E3%80%82%0A%0A**isTerminated()%20Vs%20isShutdown()**%0A%3E1.%20isShutDown%E5%BD%93%E8%B0%83%E7%94%A8shutdown()%E6%96%B9%E6%B3%95%E5%90%8E%E8%BF%94%E5%9B%9E%E4%B8%BAtrue%E3%80%82%0A%3E2.%20%C2%A0isTerminated%E5%BD%93%E8%B0%83%E7%94%A8shutdown()%E6%96%B9%E6%B3%95%E5%90%8E%EF%BC%8C%E5%B9%B6%E4%B8%94%E6%89%80%E6%9C%89%E6%8F%90%E4%BA%A4%E7%9A%84%E4%BB%BB%E5%8A%A1%E5%AE%8C%E6%88%90%E5%90%8E%E8%BF%94%E5%9B%9E%E4%B8%BAtrue%0A%0A%23%23%23%204.%20ScheduledThreadPoolExecutor%E8%AF%A6%E8%A7%A3%0A%23%23%23%23%204.1%20ScheduledThreadPoolExecutor%E7%AE%80%E4%BB%8B%0A1.%20ScheduledThreadPoolExecutor%E4%B8%BB%E8%A6%81%E7%94%A8%E6%9D%A5%E5%9C%A8%E7%BB%99%E5%AE%9A%E7%9A%84**%E5%BB%B6%E8%BF%9F%E5%90%8E%E8%BF%90%E8%A1%8C%E4%BB%BB%E5%8A%A1**%EF%BC%8C%E6%88%96%E8%80%85**%E5%AE%9A%E6%9C%9F%E6%89%A7%E8%A1%8C**%E4%BB%BB%E5%8A%A1%E3%80%82%0A2.%20ScheduledThreadPoolExecutor%E4%BD%BF%E7%94%A8%E7%9A%84**%E4%BB%BB%E5%8A%A1%E9%98%9F%E5%88%97DelayQueue%E5%B0%81%E8%A3%85%E4%BA%86%E4%B8%80%E4%B8%AAPriorityQueue**%EF%BC%8CPriorityQueue%E4%BC%9A%E5%AF%B9%E9%98%9F%E5%88%97%E4%B8%AD%E7%9A%84%E4%BB%BB%E5%8A%A1%E8%BF%9B%E8%A1%8C%E6%8E%92%E5%BA%8F%EF%BC%8C%E6%89%A7%E8%A1%8C%E6%89%80%E9%9C%80%E6%97%B6%E9%97%B4%E7%9F%AD%E7%9A%84%E6%94%BE%E5%9C%A8%E5%89%8D%E9%9D%A2%E5%85%88%E8%A2%AB%E6%89%A7%E8%A1%8C(ScheduledFutureTask%E7%9A%84time%E5%8F%98%E9%87%8F%E5%B0%8F%E7%9A%84%E5%85%88%E6%89%A7%E8%A1%8C)%EF%BC%8C%E5%A6%82%E6%9E%9C%E6%89%A7%E8%A1%8C%E6%89%80%E9%9C%80%E6%97%B6%E9%97%B4%E7%9B%B8%E5%90%8C%E5%88%99%E5%85%88%E6%8F%90%E4%BA%A4%E7%9A%84%E4%BB%BB%E5%8A%A1%E5%B0%86%E8%A2%AB%E5%85%88%E6%89%A7%E8%A1%8C(ScheduledFutureTask%E7%9A%84squenceNumber%E5%8F%98%E9%87%8F%E5%B0%8F%E7%9A%84%E5%85%88%E6%89%A7%E8%A1%8C)%E3%80%82%0A%0A%23%23%23%23%204.2%20ScheduledThreadPoolExecutor%E8%BF%90%E8%A1%8C%E6%9C%BA%E5%88%B6%0A%3E!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/6eac2176-4ff7-4ad8-a71c-77eeb40102ca/858ca70a-6944-4f29-9766-c07d61201b59.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F601%3A1)%0A%0A**ScheduledThreadPoolExecutor%E7%9A%84%E6%89%A7%E8%A1%8C%E4%B8%BB%E8%A6%81%E5%88%86%E4%B8%BA%E4%B8%A4%E5%A4%A7%E9%83%A8%E5%88%86%EF%BC%9A**%0A%3E1.%20%E5%BD%93%E8%B0%83%E7%94%A8ScheduledThreadPoolExecutor%E7%9A%84%20scheduleAtFixedRate()%20%E6%96%B9%E6%B3%95%E6%88%96%E8%80%85scheduleWirhFixedDelay()%20%E6%96%B9%E6%B3%95%E6%97%B6%EF%BC%8C%E4%BC%9A%E5%90%91ScheduledThreadPoolExecutor%E7%9A%84%20DelayQueue%20%E6%B7%BB%E5%8A%A0%E4%B8%80%E4%B8%AA%E5%AE%9E%E7%8E%B0%E4%BA%86%20RunnableScheduledFutur%20%E6%8E%A5%E5%8F%A3%E7%9A%84%20ScheduledFutureTask%20%E3%80%82%0A%3E2.%20%E7%BA%BF%E7%A8%8B%E6%B1%A0%E4%B8%AD%E7%9A%84%E7%BA%BF%E7%A8%8B%E4%BB%8EDelayQueue%E4%B8%AD%E8%8E%B7%E5%8F%96ScheduledFutureTask%EF%BC%8C%E7%84%B6%E5%90%8E%E6%89%A7%E8%A1%8C%E4%BB%BB%E5%8A%A1%E3%80%82%0A%0A**ScheduledThreadPoolExecutor%E4%B8%BA%E4%BA%86%E5%AE%9E%E7%8E%B0%E5%91%A8%E6%9C%9F%E6%80%A7%E7%9A%84%E6%89%A7%E8%A1%8C%E4%BB%BB%E5%8A%A1%EF%BC%8C%E5%AF%B9ThreadPoolExecutor%E5%81%9A%E4%BA%86%E5%A6%82%E4%B8%8B%E4%BF%AE%E6%94%B9%EF%BC%9A**%0A%20%3E%20*%20%E4%BD%BF%E7%94%A8%C2%A0DelayQueue%C2%A0%E4%BD%9C%E4%B8%BA%E4%BB%BB%E5%8A%A1%E9%98%9F%E5%88%97%EF%BC%9B%0A%20%3E*%20%20%E8%8E%B7%E5%8F%96%E4%BB%BB%E5%8A%A1%E7%9A%84%E6%96%B9%E4%B8%8D%E5%90%8C%0A%20%3E%20*%20%E6%89%A7%E8%A1%8C%E5%91%A8%E6%9C%9F%E4%BB%BB%E5%8A%A1%E5%90%8E%EF%BC%8C%E5%A2%9E%E5%8A%A0%E4%BA%86%E9%A2%9D%E5%A4%96%E7%9A%84%E5%A4%84%E7%90%86%0A%0A%23%23%23%23%204.3%20ScheduledThreadPoolExecutor%E6%89%A7%E8%A1%8C%E5%91%A8%E6%9C%9F%E4%BB%BB%E5%8A%A1%E7%9A%84%E6%AD%A5%E9%AA%A4%0A%3E!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/6eac2176-4ff7-4ad8-a71c-77eeb40102ca/78c094de-0e1c-47d7-84ba-c92bc3523d71.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F596%3A1)%0A%0A%3E1.%20%E7%BA%BF%E7%A8%8B1%E4%BB%8EDelayQueue%E4%B8%AD%E8%8E%B7%E5%8F%96%E5%B7%B2%E5%88%B0%E6%9C%9F%E7%9A%84ScheduledFutureTask%EF%BC%88DelayQueue.take()%EF%BC%89%E3%80%82%E5%88%B0%E6%9C%9F%E4%BB%BB%E5%8A%A1%E6%98%AF%E6%8C%87ScheduledFutureTask%E7%9A%84time%E5%A4%A7%E4%BA%8E%E7%AD%89%E4%BA%8E%E5%BD%93%E5%89%8D%E7%B3%BB%E7%BB%9F%E7%9A%84%E6%97%B6%E9%97%B4%EF%BC%9B%0A%3E2.%20%E7%BA%BF%E7%A8%8B1%E6%89%A7%E8%A1%8C%E8%BF%99%E4%B8%AAScheduledFutureTask%EF%BC%9B%0A%3E3.%20%E7%BA%BF%E7%A8%8B1%E4%BF%AE%E6%94%B9ScheduledFutureTask%E7%9A%84time%E5%8F%98%E9%87%8F%E4%B8%BA%E4%B8%8B%E6%AC%A1%E5%B0%86%E8%A6%81%E8%A2%AB%E6%89%A7%E8%A1%8C%E7%9A%84%E6%97%B6%E9%97%B4%EF%BC%9B%0A%3E4.%20%E7%BA%BF%E7%A8%8B1%E6%8A%8A%E8%BF%99%E4%B8%AA%E4%BF%AE%E6%94%B9time%E4%B9%8B%E5%90%8E%E7%9A%84ScheduledFutureTask%E6%94%BE%E5%9B%9EDelayQueue%E4%B8%AD%EF%BC%88DelayQueue.add())%E3%80%82%0A%0A%23%23%23%23%204.4%20ScheduledThreadPoolExecutor%E4%BD%BF%E7%94%A8%E7%A4%BA%E4%BE%8B%0A%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E7%AE%80%E5%8D%95%E7%9A%84%E5%AE%9E%E7%8E%B0Runnable%E6%8E%A5%E5%8F%A3%E7%9A%84%E7%B1%BB%0A%E6%B5%8B%E8%AF%95%E7%A8%8B%E5%BA%8F%E4%BD%BF%E7%94%A8ScheduledExecutorService%E5%92%8CExecutors.newScheduledThreadPool%E5%AE%9E%E7%8E%B0%E7%9A%84java%E8%B0%83%E5%BA%A6%0A%0A%23%23%23%23%23%204.4.1%20ScheduledExecutorService%20scheduleAtFixedRate(Runnable%20command%2Clong%20initialDelay%2Clong%20period%2CTimeUnit%20unit)%E6%96%B9%E6%B3%95%0A%60%60%60java%0A%2F%2F%E5%8F%AF%E4%BB%A5%E4%BD%BF%E7%94%A8ScheduledExecutorService%20scheduleAtFixedRate%E6%96%B9%E6%B3%95%E6%9D%A5%E5%AE%89%E6%8E%92%E4%BB%BB%E5%8A%A1%E5%9C%A8%E5%88%9D%E5%A7%8B%E5%BB%B6%E8%BF%9F%E5%90%8E%E8%BF%90%E8%A1%8C%EF%BC%8C%E7%84%B6%E5%90%8E%E5%9C%A8%E7%BB%99%E5%AE%9A%E7%9A%84%E6%97%B6%E9%97%B4%E6%AE%B5%E5%86%85%E8%BF%90%E8%A1%8C%E3%80%82%0A%0AscheduledThreadPool.scheduleAtFixedRate(worker%2C%200%2C%2010%2C%20TimeUnit.SECONDS)%3B%0A%60%60%60%0A%0A%23%23%23%23%23%204.4.2%20ScheduledExecutorService%20scheduleWithFixedDelay(Runnable%20command%2Clong%20initialDelay%2Clong%20delay%2CTimeUnit%20unit)%E6%96%B9%E6%B3%95%0A%60%60%60java%0A%2F%2FScheduledExecutorService%20scheduleWithFixedDelay%E6%96%B9%E6%B3%95%E5%8F%AF%E7%94%A8%E4%BA%8E%E4%BB%A5%E5%88%9D%E5%A7%8B%E5%BB%B6%E8%BF%9F%E5%90%AF%E5%8A%A8%E5%91%A8%E6%9C%9F%E6%80%A7%E6%89%A7%E8%A1%8C%EF%BC%8C%E7%84%B6%E5%90%8E%E4%BB%A5%E7%BB%99%E5%AE%9A%E5%BB%B6%E8%BF%9F%E6%89%A7%E8%A1%8C%E3%80%82%20%E5%BB%B6%E8%BF%9F%E6%97%B6%E9%97%B4%E6%98%AF%E7%BA%BF%E7%A8%8B%E5%AE%8C%E6%88%90%E6%89%A7%E8%A1%8C%E7%9A%84%E6%97%B6%E9%97%B4%E3%80%82%0A%0AscheduledThreadPool.scheduleWithFixedDelay(worker%2C%200%2C%201%2C%20TimeUnit.SECONDS)%3B%0A%60%60%60%0A%23%23%23%23%23%204.4.3%20scheduleWithFixedDelay()%20vs%20scheduleAtFixedRate()%0A1.%20**scheduleAtFixedRate**%EF%BC%88%E2%80%A6%EF%BC%89%E5%B0%86%E5%BB%B6%E8%BF%9F%E8%A7%86%E4%B8%BA%E4%B8%A4%E4%B8%AA%E4%BB%BB%E5%8A%A1**%E5%BC%80%E5%A7%8B%E4%B9%8B%E9%97%B4%E7%9A%84%E5%B7%AE%E5%BC%82**%EF%BC%88%E5%8D%B3%E5%AE%9A%E6%9C%9F%E8%B0%83%E7%94%A8%EF%BC%89%0A%E4%B8%8D%E7%AE%A1%E6%98%AF%E5%90%A6%E6%89%A7%E8%A1%8C%E5%AE%8C%0A2.%20**scheduleWithFixedDelay**%EF%BC%88%E2%80%A6%EF%BC%89%E5%B0%86%E5%BB%B6%E8%BF%9F%E8%A7%86%E4%B8%BA**%E4%B8%80%E4%B8%AA%E4%BB%BB%E5%8A%A1%E7%BB%93%E6%9D%9F%E4%B8%8E%E4%B8%8B%E4%B8%80%E4%B8%AA%E4%BB%BB%E5%8A%A1%E5%BC%80%E5%A7%8B**%E4%B9%8B%E9%97%B4%E7%9A%84%E5%B7%AE%E5%BC%82%EF%BC%8C%E6%89%A7%E8%A1%8C%E5%AE%8C%E6%89%8D%E5%BC%80%E5%A7%8B%E4%B8%8B%E4%B8%80%E4%B8%AA%E3%80%82%0A%0A%3E**scheduleAtFixedRate()**%3A%20%E5%9C%A8%E7%BB%99%E5%AE%9A%E7%9A%84%E5%88%9D%E5%A7%8B%E5%BB%B6%E8%BF%9F%E4%B9%8B%E5%90%8E%E5%88%9B%E5%BB%BA%E5%B9%B6%E6%89%A7%E8%A1%8C%EF%BC%8C%E9%9A%8F%E5%90%8E%E4%BB%A5%E7%BB%99%E5%AE%9A%E7%9A%84%E6%97%B6%E9%97%B4%E6%AE%B5%E9%A6%96%E5%85%88%E5%90%AF%E7%94%A8%E7%9A%84%E5%91%A8%E6%9C%9F%E6%80%A7%E5%8A%A8%E4%BD%9C%3B%20%E9%82%A3%E5%B0%B1%E6%98%AF%E6%89%A7%E8%A1%8C%E5%B0%86%E5%9C%A8initialDelay%E4%B9%8B%E5%90%8E%E5%BC%80%E5%A7%8B%EF%BC%8C%E7%84%B6%E5%90%8EinitialDelay%2Bperiod%20%EF%BC%8C%E7%84%B6%E5%90%8E%E6%98%AFinitialDelay%20%2B%202%20*%20period%20%EF%BC%8C%E7%AD%89%E7%AD%89%E3%80%82%20%E5%A6%82%E6%9E%9C%E4%BB%BB%E5%8A%A1%E7%9A%84%E6%89%A7%E8%A1%8C%E9%81%87%E5%88%B0%E5%BC%82%E5%B8%B8%EF%BC%8C%E5%88%99%E5%90%8E%E7%BB%AD%E7%9A%84%E6%89%A7%E8%A1%8C%E8%A2%AB%E6%8A%91%E5%88%B6%E3%80%82%20%E5%90%A6%E5%88%99%EF%BC%8C%E4%BB%BB%E5%8A%A1%E5%B0%86%E4%BB%85%E9%80%9A%E8%BF%87%E5%8F%96%E6%B6%88%E6%88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88%99%EF%BC%8C%E4%BB%BB%E5%8A%A1%E5%B0%86%E4%BB%85%E9%80%9A%E8%BF%87%E5%8F%96%E6%B6%88%E6%88%96%E7%BB%88%E6%AD%A2%E6%89%A7%E8%A1%8C%E7%BB%88%E6%AD%A2%E3%80%82%0A%0A%23%23%23%205.%20%E5%90%84%E7%A7%8D%E7%BA%BF%E7%A8%8B%E6%B1%A0%E7%9A%84%E9%80%82%E7%94%A8%E5%9C%BA%E6%99%AF%E4%BB%8B%E7%BB%8D%0A**FixedThreadPool**%EF%BC%9A%20%E9%80%82%E7%94%A8%E4%BA%8E%E4%B8%BA%E4%BA%86%E6%BB%A1%E8%B6%B3%E8%B5%84%E6%BA%90%E7%AE%A1%E7%90%86%E9%9C%80%E6%B1%82%EF%BC%8C%E8%80%8C%E9%9C%80%E8%A6%81%E9%99%90%E5%88%B6%E5%BD%93%E5%89%8D%E7%BA%BF%E7%A8%8B%E6%95%B0%E9%87%8F%E7%9A%84%E5%BA%94%E7%94%A8%E5%9C%BA%E6%99%AF%E3%80%82%E5%AE%83%E9%80%82%E7%94%A8%E4%BA%8E%E8%B4%9F%E8%BD%BD%E6%AF%94%E8%BE%83%E9%87%8D%E7%9A%84%E6%9C%8D%E5%8A%A1%E5%99%A8%EF%BC%9B%0A%0A**SingleThreadExecutor**%EF%BC%9A%20%E9%80%82%E7%94%A8%E4%BA%8E%E9%9C%80%E8%A6%81%E4%BF%9D%E8%AF%81%E9%A1%BA%E5%BA%8F%E5%9C%B0%E6%89%A7%E8%A1%8C%E5%90%84%E4%B8%AA%E4%BB%BB%E5%8A%A1%E5%B9%B6%E4%B8%94%E5%9C%A8%E4%BB%BB%E6%84%8F%E6%97%B6%E9%97%B4%E7%82%B9%EF%BC%8C%E4%B8%8D%E4%BC%9A%E6%9C%89%E5%A4%9A%E4%B8%AA%E7%BA%BF%E7%A8%8B%E6%98%AF%E6%B4%BB%E5%8A%A8%E7%9A%84%E5%BA%94%E7%94%A8%E5%9C%BA%E6%99%AF%E3%80%82%0A%0A**CachedThreadPool**%EF%BC%9A%20%E9%80%82%E7%94%A8%E4%BA%8E%E6%89%A7%E8%A1%8C%E5%BE%88%E5%A4%9A%E7%9A%84%E7%9F%AD%E6%9C%9F%E5%BC%82%E6%AD%A5%E4%BB%BB%E5%8A%A1%E7%9A%84%E5%B0%8F%E7%A8%8B%E5%BA%8F%EF%BC%8C%E6%88%96%E8%80%85%E6%98%AF%E8%B4%9F%E8%BD%BD%E8%BE%83%E8%BD%BB%E7%9A%84%E6%9C%8D%E5%8A%A1%E5%99%A8%EF%BC%9B%0A%0A**ScheduledThreadPoolExecutor**%EF%BC%9A%20%E9%80%82%E7%94%A8%E4%BA%8E%E9%9C%80%E8%A6%81%E5%A4%9A%E4%B8%AA%E5%90%8E%E5%8F%B0%E6%89%A7%E8%A1%8C%E5%91%A8%E6%9C%9F%E4%BB%BB%E5%8A%A1%EF%BC%8C%E5%90%8C%E6%97%B6%E4%B8%BA%E4%BA%86%E6%BB%A1%E8%B6%B3%E8%B5%84%E6%BA%90%E7%AE%A1%E7%90%86%E9%9C%80%E6%B1%82%E8%80%8C%E9%9C%80%E8%A6%81%E9%99%90%E5%88%B6%E5%90%8E%E5%8F%B0%E7%BA%BF%E7%A8%8B%E7%9A%84%E6%95%B0%E9%87%8F%E7%9A%84%E5%BA%94%E7%94%A8%E5%9C%BA%E6%99%AF%EF%BC%8C%0A%0A**SingleThreadScheduledExecutor**%EF%BC%9A%20%E9%80%82%E7%94%A8%E4%BA%8E%E9%9C%80%E8%A6%81%E5%8D%95%E4%B8%AA%E5%90%8E%E5%8F%B0%E7%BA%BF%E7%A8%8B%E6%89%A7%E8%A1%8C%E5%91%A8%E6%9C%9F%E4%BB%BB%E5%8A%A1%EF%BC%8C%E5%90%8C%E6%97%B6%E4%BF%9D%E8%AF%81%E9%A1%BA%E5%BA%8F%E5%9C%B0%E6%89%A7%E8%A1%8C%E5%90%84%E4%B8%AA%E4%BB%BB%E5%8A%A1%E7%9A%84%E5%BA%94%E7%94%A8%E5%9C%BA%E6%99%AF%E3%80%82%0A&lt;/center&gt;&lt;/div&gt;
</content>
  </entry>
  <entry xml:base="http://linzhiteng.postach.io/feed.xml">
    <title type="text">五. 并发编程中一些问题</title>
    <id>https://linzhiteng.postach.io/post/wu-bing-fa-bian-cheng-zhong-yi-xie-wen-ti</id>
    <updated>2019-06-09T13:07:45.590000Z</updated>
    <published>2019-03-12T14:21:25Z</published>
    <link href="https://linzhiteng.postach.io/post/wu-bing-fa-bian-cheng-zhong-yi-xie-wen-ti" />
    <author>
      <name>linzhi teng</name>
    </author>
    <category term="xian-cheng" />
    <content type="html">&lt;div&gt;&lt;div style=&quot;font-size: 14px; margin: 0; padding: 0; width: 100%;&quot;&gt;&lt;div style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;五. 并发编程中一些问题
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1. 多线程就一定好吗？快吗？？
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2. 上下文切换
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.1 减少上下文切换
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.2 CAS算法
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.3 协程
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3. 避免死锁
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1 如何产生的死锁
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.2 避免死锁的常见方法
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.3 解决资源限制
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;五. 并发编程中一些问题&lt;/h2&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/981ef410-bf8e-43f2-a79d-16f0179b777b/ee35b00f-eae5-45fa-a85b-6531098449ac.jpg&quot; /&gt;&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;a href=&quot;https://blog.csdn.net/qq_34337272/article/details/79844051&quot; style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;并发编程的问题&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;1. 多线程就一定好吗？快吗？？&lt;/h3&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;并发编程的目的就是为了能提高程序的执行效率提高程序运行速度，但是并发编程并不总是能提高程序运行速度的，而且并发编程可能会遇到很多问题，&lt;br/&gt;
比如：内存泄漏、&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;上下文切换&lt;/strong&gt;、&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;死锁&lt;/strong&gt;还有受限于硬件和软件的资源闲置问题。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;多线程就是几乎同时执行多个线程（一个处理器在某一个时间点上永远都只能是一个线程！即使这个处理器是多核的，除非有多个处理器才能实现多个线程同时运行）。CPU通过给每个线程分配CPU时间片来实现伪同时运行，因为CPU时间片一般很短很短，所以给人一种同时运行的感觉。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;2. 上下文切换&lt;/h3&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;当前任务在执行完CPU时间片切换到另一个任务之前会先保存自己的状态，以便下次再切换会这个任务时，可以再加载这个任务的状态。任务从&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;保存到再加载的过程&lt;/strong&gt;就是一次上下文切换。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;上下文切换通常是计算密集型的。也就是说，它需要相当可观的处理器时间，在每秒几十上百次的切换中，每次切换都需要纳秒量级的时间。所以，上下文切换对系统来说意味着消耗大量的 CPU 时间，事实上，可能是操作系统中时间消耗最大的操作。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.1 减少上下文切换&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;上下文切换又分为2种：&lt;/li&gt;
&lt;/ul&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;让步式上下文切换&lt;br/&gt;
指执行线程主动释放CPU，与锁竞争严重程度成正比，可通过&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;减少锁竞争&lt;/strong&gt;和使用&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;CAS算法&lt;/strong&gt;来避免；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;抢占式上下文切换。&lt;br/&gt;
指线程因分配的时间片用尽而被迫放弃CPU或者被其他优先级更高的线程所抢占，一般由于线程数大于CPU可用核心数引起，可通过适当&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;减少线程数&lt;/strong&gt;和使用&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;协程&lt;/strong&gt;来避免。&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;总结一下：&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;减少锁的使用。因为多线程竞争锁时会引起上下文切换。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;使用CAS算法。这种算法也是为了减少锁的使用。CAS算法是一种无锁算法。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;减少线程的使用。人物很少的时候创建大量线程会导致大量线程都处于等待状态。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;使用协程。&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.2 CAS算法&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;CAS（比较与交换，Compare and swap） 是一种有名的无锁算法。无锁编程，即不使用锁的情况下实现多线程之间的变量同步，也就是在没有线程被阻塞的情况下实现变量的同步，所以也叫非阻塞同步（Non-blocking Synchronization）。&lt;br/&gt;
实现非阻塞同步的方案称为&quot;无锁编程算法&quot;（ Non-blocking algorithm）。 属于乐观锁。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;CAS算法涉及到三个操作数&lt;/strong&gt;&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;需要读写的内存值V&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;进行比较的值A&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;拟写入的新值B&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;当且仅当 V 的值等于 A时，CAS通过原子方式用新值B来更新V的值，否则不会执行任何操作（比较和替换是一个原子操作）。一般情况下是一个自旋操作，即不断的重试。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.3 协程&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;协程也可以说是微线程或者说是轻量级的线程，它占用的内存更少并且更灵活。很多编程语言中都有协程。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;3. 避免死锁&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.1 如何产生的死锁&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;在操作系统中，死锁是指两个或两个以上的进程在执行过程中，由于竞争资源或者由于彼此通信而造成的一种阻塞的现象，若无外力作用，它们都将无法推进下去。此时称系统处于死锁状态或系统产生了死锁，这些永远在互相等待的进程称为死锁进程。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;在线程中，如果两个线程同时等待对方释放锁也会产生死锁。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.2 避免死锁的常见方法&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;避免一个线程同时获得多个锁&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;避免一个线程在锁内同时占用多个资源，尽量保证每个锁只占用一个资源&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;尝试使用定时锁，使用lock.tryLock(timeout)来替代使用内部锁机制&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;对于数据库锁，加锁和解锁必须在一个数据库连接里，否则会出现解锁失败的情况&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.3 解决资源限制&lt;/h4&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;什么是资源限制？&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;所谓资源限制就是我们在进行并发编程时，程序的运行速度受限于计算机硬件资源比如CPU,内存等等或软件资源比如软件的质量、性能等等。举个例子：如果说服务器的带宽只有2MB/s，某个资源的下载速度是1MB/s，系统启动10个线程下载该资源并不会导致下载速度编程10MB/s，所以在并发编程时，需要考虑这些资源的限制。硬件资源限制有：带宽的上传和下载速度、硬盘读写速度和CPU处理速度；软件资源限制有数据库的连接数、socket连接数、软件质量和性能等等。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ol start=&quot;2&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;资源限制引发的问题&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;在并发编程中，程序运行加快的原因是运行方式从串行运行变为并发运行，但是如果某段程序的并发执行由于资源限制仍然在串行执行的话，这时候程序的运行不仅不会加快，反而会更慢，因为可能增加了上下文切换和资源调度的时间。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;3.&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;如何解决资源限制的问题&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;对于硬件资源限制，可以考虑使用集群并行执行程序。既然单机的资源有限制，那么就让程序在多机上运行。比如使用Hadoop或者自己搭建服务器集群。&lt;br/&gt;
对于软件资源的限制，可以考虑使用资源池将资源复用。比如使用连接池将数据库和Socket复用，或者在调用对方webservice接口获取数据时，只建立一个连接。另外还可以考虑使用良好的开源软件。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ol start=&quot;4&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;在资源限制的情况下如何进行并发编程&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;根据不同的资源限制调整程序的并发度，比如下载文件程序依赖于两个资源-带宽和硬盘读写速度。有数据库操作时，设计数据库练连接数，如果SQL语句执行非常快，而线程的数量比数据库连接数大很多，则某些线程会被阻塞，等待数据库连接。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/div&gt;&lt;center style='display:none !important;visibility:collapse !important;height:0 !important;white-space:nowrap;width:100%;overflow:hidden'&gt;%5Btoc%5D%0A%23%23%20%E4%BA%94.%20%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B%E4%B8%AD%E4%B8%80%E4%BA%9B%E9%97%AE%E9%A2%98%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/981ef410-bf8e-43f2-a79d-16f0179b777b/ee35b00f-eae5-45fa-a85b-6531098449ac.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F608%3A1)%0A%3E%5B%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B%E7%9A%84%E9%97%AE%E9%A2%98%5D(https%3A%2F%2Fblog.csdn.net%2Fqq_34337272%2Farticle%2Fdetails%2F79844051)%0A%0A%23%23%23%201.%20%E5%A4%9A%E7%BA%BF%E7%A8%8B%E5%B0%B1%E4%B8%80%E5%AE%9A%E5%A5%BD%E5%90%97%EF%BC%9F%E5%BF%AB%E5%90%97%EF%BC%9F%EF%BC%9F%0A*%20%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B%E7%9A%84%E7%9B%AE%E7%9A%84%E5%B0%B1%E6%98%AF%E4%B8%BA%E4%BA%86%E8%83%BD%E6%8F%90%E9%AB%98%E7%A8%8B%E5%BA%8F%E7%9A%84%E6%89%A7%E8%A1%8C%E6%95%88%E7%8E%87%E6%8F%90%E9%AB%98%E7%A8%8B%E5%BA%8F%E8%BF%90%E8%A1%8C%E9%80%9F%E5%BA%A6%EF%BC%8C%E4%BD%86%E6%98%AF%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B%E5%B9%B6%E4%B8%8D%E6%80%BB%E6%98%AF%E8%83%BD%E6%8F%90%E9%AB%98%E7%A8%8B%E5%BA%8F%E8%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%BF%E7%A8%8B%E4%BC%9A%E5%AF%BC%E8%87%B4%E5%A4%A7%E9%87%8F%E7%BA%BF%E7%A8%8B%E9%83%BD%E5%A4%84%E4%BA%8E%E7%AD%89%E5%BE%85%E7%8A%B6%E6%80%81%E3%80%82%0A*%20%E4%BD%BF%E7%94%A8%E5%8D%8F%E7%A8%8B%E3%80%82%0A%0A%23%23%23%23%202.2%20CAS%E7%AE%97%E6%B3%95%0A%3ECAS%EF%BC%88%E6%AF%94%E8%BE%83%E4%B8%8E%E4%BA%A4%E6%8D%A2%EF%BC%8CCompare%20and%20swap%EF%BC%89%20%E6%98%AF%E4%B8%80%E7%A7%8D%E6%9C%89%E5%90%8D%E7%9A%84%E6%97%A0%E9%94%81%E7%AE%97%E6%B3%95%E3%80%82%E6%97%A0%E9%94%81%E7%BC%96%E7%A8%8B%EF%BC%8C%E5%8D%B3%E4%B8%8D%E4%BD%BF%E7%94%A8%E9%94%81%E7%9A%84%E6%83%85%E5%86%B5%E4%B8%8B%E5%AE%9E%E7%8E%B0%E5%A4%9A%E7%BA%BF%E7%A8%8B%E4%B9%8B%E9%97%B4%E7%9A%84%E5%8F%98%E9%87%8F%E5%90%8C%E6%AD%A5%EF%BC%8C%E4%B9%9F%E5%B0%B1%E6%98%AF%E5%9C%A8%E6%B2%A1%E6%9C%89%E7%BA%BF%E7%A8%8B%E8%A2%AB%E9%98%BB%E5%A1%9E%E7%9A%84%E6%83%85%E5%86%B5%E4%B8%8B%E5%AE%9E%E7%8E%B0%E5%8F%98%E9%87%8F%E7%9A%84%E5%90%8C%E6%AD%A5%EF%BC%8C%E6%89%80%E4%BB%A5%E4%B9%9F%E5%8F%AB%E9%9D%9E%E9%98%BB%E5%A1%9E%E5%90%8C%E6%AD%A5%EF%BC%88Non-blocking%20Synchronization%EF%BC%89%E3%80%82%0A%3E%E5%AE%9E%E7%8E%B0%E9%9D%9E%E9%98%BB%E5%A1%9E%E5%90%8C%E6%AD%A5%E7%9A%84%E6%96%B9%E6%A1%88%E7%A7%B0%E4%B8%BA%E2%80%9C%E6%97%A0%E9%94%81%E7%BC%96%E7%A8%8B%E7%AE%97%E6%B3%95%E2%80%9D%EF%BC%88%20Non-blocking%20algorithm%EF%BC%89%E3%80%82%20%E5%B1%9E%E4%BA%8E%E4%B9%90%E8%A7%82%E9%94%81%E3%80%82%0A%0A%3E**CAS%E7%AE%97%E6%B3%95%E6%B6%89%E5%8F%8A%E5%88%B0%E4%B8%89%E4%B8%AA%E6%93%8D%E4%BD%9C%E6%95%B0**%0A%3E*%20%E9%9C%80%E8%A6%81%E8%AF%BB%E5%86%99%E7%9A%84%E5%86%85%E5%AD%98%E5%80%BCV%0A%3E*%20%E8%BF%9B%E8%A1%8C%E6%AF%94%E8%BE%83%E7%9A%84%E5%80%BCA%0A%3E*%20%E6%8B%9F%E5%86%99%E5%85%A5%E7%9A%84%E6%96%B0%E5%80%BCB%0A%3E*%20%E5%BD%93%E4%B8%94%E4%BB%85%E5%BD%93%20V%20%E7%9A%84%E5%80%BC%E7%AD%89%E4%BA%8E%20A%E6%97%B6%EF%BC%8CCAS%E9%80%9A%E8%BF%87%E5%8E%9F%E5%AD%90%E6%96%B9%E5%BC%8F%E7%94%A8%E6%96%B0%E5%80%BCB%E6%9D%A5%E6%9B%B4%E6%96%B0V%E7%9A%84%E5%80%BC%EF%BC%8C%E5%90%A6%E5%88%99%E4%B8%8D%E4%BC%9A%E6%89%A7%E8%A1%8C%E4%BB%BB%E4%BD%95%E6%93%8D%E4%BD%9C%EF%BC%88%E6%AF%94%E8%BE%83%E5%92%8C%E6%9B%BF%E6%8D%A2%E6%98%AF%E4%B8%80%E4%B8%AA%E5%8E%9F%E5%AD%90%E6%93%8D%E4%BD%9C%EF%BC%89%E3%80%82%E4%B8%80%E8%88%AC%E6%83%85%E5%86%B5%E4%B8%8B%E6%98%AF%E4%B8%80%E4%B8%AA%E8%87%AA%E6%97%8B%E6%93%8D%E4%BD%9C%EF%BC%8C%E5%8D%B3%E4%B8%8D%E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A%BF%E7%A8%8B%E5%9C%A8%E9%94%81%E5%86%85%E5%90%8C%E6%97%B6%E5%8D%A0%E7%94%A8%E5%A4%9A%E4%B8%AA%E8%B5%84%E6%BA%90%EF%BC%8C%E5%B0%BD%E9%87%8F%E4%BF%9D%E8%AF%81%E6%AF%8F%E4%B8%AA%E9%94%81%E5%8F%AA%E5%8D%A0%E7%94%A8%E4%B8%80%E4%B8%AA%E8%B5%84%E6%BA%90%0A%3E*%20%E5%B0%9D%E8%AF%95%E4%BD%BF%E7%94%A8%E5%AE%9A%E6%97%B6%E9%94%81%EF%BC%8C%E4%BD%BF%E7%94%A8lock.tryLock(timeout)%E6%9D%A5%E6%9B%BF%E4%BB%A3%E4%BD%BF%E7%94%A8%E5%86%85%E9%83%A8%E9%94%81%E6%9C%BA%E5%88%B6%0A%3E*%20%E5%AF%B9%E4%BA%8E%E6%95%B0%E6%8D%AE%E5%BA%93%E9%94%81%EF%BC%8C%E5%8A%A0%E9%94%81%E5%92%8C%E8%A7%A3%E9%94%81%E5%BF%85%E9%A1%BB%E5%9C%A8%E4%B8%80%E4%B8%AA%E6%95%B0%E6%8D%AE%E5%BA%93%E8%BF%9E%E6%8E%A5%E9%87%8C%EF%BC%8C%E5%90%A6%E5%88%99%E4%BC%9A%E5%87%BA%E7%8E%B0%E8%A7%A3%E9%94%81%E5%A4%B1%E8%B4%A5%E7%9A%84%E6%83%85%E5%86%B5%0A%0A%23%23%23%23%203.3%20%E8%A7%A3%E5%86%B3%E8%B5%84%E6%BA%90%E9%99%90%E5%88%B6%0A1.%20**%E4%BB%80%E4%B9%88%E6%98%AF%E8%B5%84%E6%BA%90%E9%99%90%E5%88%B6%EF%BC%9F**%0A%3E%E6%89%80%E8%B0%93%E8%B5%84%E6%BA%90%E9%99%90%E5%88%B6%E5%B0%B1%E6%98%AF%E6%88%91%E4%BB%AC%E5%9C%A8%E8%BF%9B%E8%A1%8C%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B%E6%97%B6%E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6%AF%94%E5%A6%82%E4%B8%8B%E8%BD%BD%E6%96%87%E4%BB%B6%E7%A8%8B%E5%BA%8F%E4%BE%9D%E8%B5%96%E4%BA%8E%E4%B8%A4%E4%B8%AA%E8%B5%84%E6%BA%90-%E5%B8%A6%E5%AE%BD%E5%92%8C%E7%A1%AC%E7%9B%98%E8%AF%BB%E5%86%99%E9%80%9F%E5%BA%A6%E3%80%82%E6%9C%89%E6%95%B0%E6%8D%AE%E5%BA%93%E6%93%8D%E4%BD%9C%E6%97%B6%EF%BC%8C%E8%AE%BE%E8%AE%A1%E6%95%B0%E6%8D%AE%E5%BA%93%E7%BB%83%E8%BF%9E%E6%8E%A5%E6%95%B0%EF%BC%8C%E5%A6%82%E6%9E%9CSQL%E8%AF%AD%E5%8F%A5%E6%89%A7%E8%A1%8C%E9%9D%9E%E5%B8%B8%E5%BF%AB%EF%BC%8C%E8%80%8C%E7%BA%BF%E7%A8%8B%E7%9A%84%E6%95%B0%E9%87%8F%E6%AF%94%E6%95%B0%E6%8D%AE%E5%BA%93%E8%BF%9E%E6%8E%A5%E6%95%B0%E5%A4%A7%E5%BE%88%E5%A4%9A%EF%BC%8C%E5%88%99%E6%9F%90%E4%BA%9B%E7%BA%BF%E7%A8%8B%E4%BC%9A%E8%A2%AB%E9%98%BB%E5%A1%9E%EF%BC%8C%E7%AD%89%E5%BE%85%E6%95%B0%E6%8D%AE%E5%BA%93%E8%BF%9E%E6%8E%A5%E3%80%82%0A&lt;/center&gt;&lt;/div&gt;
</content>
  </entry>
  <entry xml:base="http://linzhiteng.postach.io/feed.xml">
    <title type="text">三. 线程间通信知识点补充</title>
    <id>https://linzhiteng.postach.io/post/san-xian-cheng-jian-tong-xin-zhi-shi-dian-bu-chong</id>
    <updated>2019-06-09T13:07:47.303000Z</updated>
    <published>2019-03-12T14:20:52Z</published>
    <link href="https://linzhiteng.postach.io/post/san-xian-cheng-jian-tong-xin-zhi-shi-dian-bu-chong" />
    <author>
      <name>linzhi teng</name>
    </author>
    <category term="xian-cheng" />
    <content type="html">&lt;div&gt;&lt;div style=&quot;font-size: 14px; margin: 0; padding: 0; width: 100%;&quot;&gt;&lt;div style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;三. 线程间通信知识点补充
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1. 管道输入/输出流
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2. Thread.join()的使用
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.  ThreadLocal的使用
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1 ThreadLocal介绍
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.2 ThreadLocal方法
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.3  InheritableThreadLocal
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;三. 线程间通信知识点补充&lt;/h2&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/fe2f0d8b-bb19-4773-af47-1fbc0d05ec7f/158dda0d-935a-42c1-893d-6c3ae0271c4f.jpg&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;a href=&quot;https://blog.csdn.net/qq_34337272/article/details/79694226&quot; style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;线程通信知识补充&lt;/a&gt;&lt;/p&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;1. 管道输入/输出流&lt;/h3&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;管道输入/输出流主要用于线程之间的数据传输，而且传输的媒介为内存。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;管道输入/输出流主要包括下列两类的实现：&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;面向字节： PipedOutputStream、 PipedInputStream&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;面向字符: PipedWriter、 PipedReader&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;2. Thread.join()的使用&lt;/h3&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;在很多情况下，主线程生成并起动了子线程，如果子线程里要进行大量的耗时的运算，主线程往往将于子线程之前结束，但是如果主线程处理完其他的事务后，需要用到子线程的处理结果，也就是主线程需要等待子线程执行完成之后再结束，这个时候就要用到join()方法了。另外，一个线程需要等待另一个线程也需要用到join()方法。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;Thread类除了提供join()方法之外，还提供了join(long millis)、join(long millis, int nanos)两个具有超时特性的方法。这两个超时方法表示，如果线程thread在指定的超时时间没有终止，那么将会从该超时方法中返回。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;Thread.sleep(2000)不会释放锁，threadTest.join(2000)会释放锁 。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;3.  ThreadLocal的使用&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.1 ThreadLocal介绍&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;变量值的共享可以使用public static变量的形式，所有线程都使用一个public static变量。如果想实现&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;每一个线程都有自己的共享变量&lt;/strong&gt;该如何解决呢？&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;JDK中提供的ThreadLocal类正是为了解决这样的问题。ThreadLocal类主要解决的就是让&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;每个线程绑定自己的值&lt;/strong&gt;，可以将ThreadLocal类形象的比喻成存放数据的盒子，盒子中可以存储每个线程的私有数据。&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.2 ThreadLocal方法&lt;/h4&gt;
&lt;table style=&quot;margin: 2px 0 14px; color: #333; width: auto; border-collapse: collapse; box-sizing: border-box;&quot;&gt;&lt;thead style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;方法名称&lt;/th&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;描述&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;get()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;返回当前线程的此线程局部变量的副本中的值。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;set(T value)&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;将当前线程的此线程局部变量的副本设置为指定的值&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;remove()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;删除此线程局部变量的当前线程的值&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;initialValue()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;返回此线程局部变量的当前线程的&quot;初始值&quot;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.3  InheritableThreadLocal&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;ThreadLocal类固然很好，但是子线程并不能取到父线程的ThreadLocal类的变量，InheritableThreadLocal类就是解决这个问题的。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;在使用InheritableThreadLocal类需要注意的一点是：如果子线程在取得值的同时，主线程将InheritableThreadLocal中的值进行更改，那么子线程取到的还是旧值。&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;&lt;center style='display:none !important;visibility:collapse !important;height:0 !important;white-space:nowrap;width:100%;overflow:hidden'&gt;%5Btoc%5D%0A%23%23%20%E4%B8%89.%20%E7%BA%BF%E7%A8%8B%E9%97%B4%E9%80%9A%E4%BF%A1%E7%9F%A5%E8%AF%86%E7%82%B9%E8%A1%A5%E5%85%85%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/fe2f0d8b-bb19-4773-af47-1fbc0d05ec7f/158dda0d-935a-42c1-893d-6c3ae0271c4f.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F610%3A1)%0A%5B%E7%BA%BF%E7%A8%8B%E9%80%9A%E4%BF%A1%E7%9F%A5%E8%AF%86%E8%A1%A5%E5%85%85%5D(https%3A%2F%2Fblog.csdn.net%2Fqq_34337272%2Farticle%2Fdetails%2F79694226)%0A%23%23%23%201.%20%E7%AE%A1%E9%81%93%E8%BE%93%E5%85%A5%2F%E8%BE%93%E5%87%BA%E6%B5%81%0A*%20%E7%AE%A1%E9%81%93%E8%BE%93%E5%85%A5%2F%E8%BE%93%E5%87%BA%E6%B5%81%E4%B8%BB%E8%A6%81%E7%94%A8%E4%BA%8E%E7%BA%BF%E7%A8%8B%E4%B9%8B%E9%97%B4%E7%9A%84%E6%95%B0%E6%8D%AE%E4%BC%A0%E8%BE%93%EF%BC%8C%E8%80%8C%E4%B8%94%E4%BC%A0%E8%BE%93%E7%9A%84%E5%AA%92%E4%BB%8B%E4%B8%BA%E5%86%85%E5%AD%98%E3%80%82%0A*%20%E7%AE%A1%E9%81%93%E8%BE%93%E5%85%A5%2F%E8%BE%93%E5%87%BA%E6%B5%81%E4%B8%BB%E8%A6%81%E5%8C%85%E6%8B%AC%E4%B8%8B%E5%88%97%E4%B8%A4%E7%B1%BB%E7%9A%84%E5%AE%9E%E7%8E%B0%EF%BC%9A%0A%3E1.%20%E9%9D%A2%E5%90%91%E5%AD%97%E8%8A%82%EF%BC%9A%20PipedOutputStream%E3%80%81%20PipedInputStream%0A%3E2.%20%20%E9%9D%A2%E5%90%91%E5%AD%97%E7%AC%A6%3A%20PipedWriter%E3%80%81%20PipedReader%0A%0A%23%23%23%202.%20Thread.join()%E7%9A%84%E4%BD%BF%E7%94%A8%0A*%20%E5%9C%A8%E5%BE%88%E5%A4%9A%E6%83%85%E5%86%B5%E4%B8%8B%EF%BC%8C%E4%B8%BB%E7%BA%BF%E7%A8%8B%E7%94%9F%E6%88%90%E5%B9%B6%E8%B5%B7%E5%8A%A8%E4%BA%86%E5%AD%90%E7%BA%BF%E7%A8%8B%EF%BC%8C%E5%A6%82%E6%9E%9C%E5%AD%90%E7%BA%BF%E7%A8%8B%E9%87%8C%E8%A6%81%E8%BF%9B%E8%A1%8C%E5%A4%A7%E9%87%8F%E7%9A%84%E8%80%97%E6%97%B6%E7%9A%84%E8%BF%90%E7%AE%97%EF%BC%8C%E4%B8%BB%E7%BA%BF%E7%A8%8B%E5%BE%80%E5%BE%80%E5%B0%86%E4%BA%8E%E5%AD%90%E7%BA%BF%E7%A8%8B%E4%B9%8B%E5%89%8D%E7%BB%93%E6%9D%9F%EF%BC%8C%E4%BD%86%E6%98%AF%E5%A6%82%E6%9E%9C%E4%B8%BB%E7%BA%BF%E7%A8%8B%E5%A4%84%E7%90%86%E5%AE%8C%E5%85%B6%E4%BB%96%E7%9A%84%E4%BA%8B%E5%8A%A1%E5%90%8E%EF%BC%8C%E9%9C%80%E8%A6%81%E7%94%A8%E5%88%B0%E5%AD%90%E7%BA%BF%E7%A8%8B%E7%9A%84%E5%A4%84%E7%90%86%E7%BB%93%E6%9E%9C%EF%BC%8C%E4%B9%9F%E5%B0%B1%E6%98%AF%E4%B8%BB%E7%BA%BF%E7%A8%8B%E9%9C%80%E8%A6%81%E7%AD%89%E5%BE%85%E5%AD%90%E7%BA%BF%E7%A8%8B%E6%89%A7%E8%A1%8C%E5%AE%8C%E6%88%90%E4%B9%8B%E5%90%8E%E5%86%8D%E7%BB%93%E6%9D%9F%EF%BC%8C%E8%BF%99%E4%B8%AA%E6%97%B6%E5%80%99%E5%B0%B1%E8%A6%81%E7%94%A8%E5%88%B0join()%E6%96%B9%E6%B3%95%E4%BA%86%E3%80%82%E5%8F%A6%E5%A4%96%EF%BC%8C%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%E9%9C%80%E8%A6%81%E7%AD%89%E5%BE%85%E5%8F%A6%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%E4%B9%9F%E9%9C%80%E8%A6%81%E7%94%A8%E5%88%B0join()%E6%96%B9%E6%B3%95%E3%80%82%0A*%20Thread%E7%B1%BB%E9%99%A4%E4%BA%86%E6%8F%90%E4%BE%9Bjoin()%E6%96%B9%E6%B3%95%E4%B9%8B%E5%A4%96%EF%BC%8C%E8%BF%98%E6%8F%90%E4%BE%9B%E4%BA%86join(long%20millis)%E3%80%81join(long%20millis%2C%20int%20nanos)%E4%B8%A4%E4%B8%AA%E5%85%B7%E6%9C%89%E8%B6%85%E6%97%B6%E7%89%B9%E6%80%A7%E7%9A%84%E6%96%B9%E6%B3%95%E3%80%82%E8%BF%99%E4%B8%A4%E4%B8%AA%E8%B6%85%E6%97%B6%E6%96%B9%E6%B3%95%E8%A1%A8%E7%A4%BA%EF%BC%8C%E5%A6%82%E6%9E%9C%E7%BA%BF%E7%A8%8Bthread%E5%9C%A8%E6%8C%87%E5%AE%9A%E7%9A%84%E8%B6%85%E6%97%B6%E6%97%B6%E9%97%B4%E6%B2%A1%E6%9C%89%E7%BB%88%E6%AD%A2%EF%BC%8C%E9%82%A3%E4%B9%88%E5%B0%86%E4%BC%9A%E4%BB%8E%E8%AF%A5%E8%B6%85%E6%97%B6%E6%96%B9%E6%B3%95%E4%B8%AD%E8%BF%94%E5%9B%9E%E3%80%82%0A*%20%C2%A0Thread.sleep(2000)%E4%B8%8D%E4%BC%9A%E9%87%8A%E6%94%BE%E9%94%81%EF%BC%8CthreadTest.join(2000)%E4%BC%9A%E9%87%8A%E6%94%BE%E9%94%81%C2%A0%E3%80%82%0A%0A%23%23%23%203.%20%C2%A0ThreadLocal%E7%9A%84%E4%BD%BF%E7%94%A8%0A%23%23%23%23%203.1%20ThreadLocal%E4%BB%8B%E7%BB%8D%0A*%20%E5%8F%98%E9%87%8F%E5%80%BC%E7%9A%84%E5%85%B1%E4%BA%AB%E5%8F%AF%E4%BB%A5%E4%BD%BF%E7%94%A8public%20static%E5%8F%98%E9%87%8F%E7%9A%84%E5%BD%A2%E5%BC%8F%EF%BC%8C%E6%89%80%E6%9C%89%E7%BA%BF%E7%A8%8B%E9%83%BD%E4%BD%BF%E7%94%A8%E4%B8%80%E4%B8%AApublic%20static%E5%8F%98%E9%87%8F%E3%80%82%E5%A6%82%E6%9E%9C%E6%83%B3%E5%AE%9E%E7%8E%B0**%E6%AF%8F%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%E9%83%BD%E6%9C%89%E8%87%AA%E5%B7%B1%E7%9A%84%E5%85%B1%E4%BA%AB%E5%8F%98%E9%87%8F**%E8%AF%A5%E5%A6%82%E4%BD%95%E8%A7%A3%E5%86%B3%E5%91%A2%EF%BC%9F%0A*%20JDK%E4%B8%AD%E6%8F%90%E4%BE%9B%E7%9A%84ThreadLocal%E7%B1%BB%E6%AD%A3%E6%98%AF%E4%B8%BA%E4%BA%86%E8%A7%A3%E5%86%B3%E8%BF%99%E6%A0%B7%E7%9A%84%E9%97%AE%E9%A2%98%E3%80%82ThreadLocal%E7%B1%BB%E4%B8%BB%E8%A6%81%E8%A7%A3%E5%86%B3%E7%9A%84%E5%B0%B1%E6%98%AF%E8%AE%A9**%E6%AF%8F%E4%B8%AA%E7%BA%BF%E7%A8%8B%E7%BB%91%E5%AE%9A%E8%87%AA%E5%B7%B1%E7%9A%84%E5%80%BC**%EF%BC%8C%E5%8F%AF%E4%BB%A5%E5%B0%86ThreadLocal%E7%B1%BB%E5%BD%A2%E8%B1%A1%E7%9A%84%E6%AF%94%E5%96%BB%E6%88%90%E5%AD%98%E6%94%BE%E6%95%B0%E6%8D%AE%E7%9A%84%E7%9B%92%E5%AD%90%EF%BC%8C%E7%9B%92%E5%AD%90%E4%B8%AD%E5%8F%AF%E4%BB%A5%E5%AD%98%E5%82%A8%E6%AF%8F%E4%B8%AA%E7%BA%BF%E7%A8%8B%E7%9A%84%E7%A7%81%E6%9C%89%E6%95%B0%E6%8D%AE%E3%80%82%0A%0A%23%23%23%23%203.2%20ThreadLocal%E6%96%B9%E6%B3%95%0A%0A%7C%20%E6%96%B9%E6%B3%95%E5%90%8D%E7%A7%B0%20%7C%20%E6%8F%8F%E8%BF%B0%20%7C%0A%7C%20---%20%7C%20---%20%7C%0A%7C%20%20get()%7C%E8%BF%94%E5%9B%9E%E5%BD%93%E5%89%8D%E7%BA%BF%E7%A8%8B%E7%9A%84%E6%AD%A4%E7%BA%BF%E7%A8%8B%E5%B1%80%E9%83%A8%E5%8F%98%E9%87%8F%E7%9A%84%E5%89%AF%E6%9C%AC%E4%B8%AD%E7%9A%84%E5%80%BC%E3%80%82%20%20%7C%0A%7Cset(T%20value)%20%20%7C%20%E5%B0%86%E5%BD%93%E5%89%8D%E7%BA%BF%E7%A8%8B%E7%9A%84%E6%AD%A4%E7%BA%BF%E7%A8%8B%E5%B1%80%E9%83%A8%E5%8F%98%E9%87%8F%E7%9A%84%E5%89%AF%E6%9C%AC%E8%AE%BE%E7%BD%AE%E4%B8%BA%E6%8C%87%E5%AE%9A%E7%9A%84%E5%80%BC%20%7C%0A%7C%20remove()%20%7C%20%E5%88%A0%E9%99%A4%E6%AD%A4%E7%BA%BF%E7%A8%8B%E5%B1%80%E9%83%A8%E5%8F%98%E9%87%8F%E7%9A%84%E5%BD%93%E5%89%8D%E7%BA%BF%E7%A8%8B%E7%9A%84%E5%80%BC%20%7C%0A%7C%20initialValue()%20%7C%E8%BF%94%E5%9B%9E%E6%AD%A4%E7%BA%BF%E7%A8%8B%E5%B1%80%E9%83%A8%E5%8F%98%E9%87%8F%E7%9A%84%E5%BD%93%E5%89%8D%E7%BA%BF%E7%A8%8B%E7%9A%84%E2%80%9C%E5%88%9D%E5%A7%8B%E5%80%BC%E2%80%9D%20%20%7C%0A%0A%0A%23%23%23%23%203.3%20%C2%A0InheritableThreadLocal%0A*%20ThreadLocal%E7%B1%BB%E5%9B%BA%E7%84%B6%E5%BE%88%E5%A5%BD%EF%BC%8C%E4%BD%86%E6%98%AF%E5%AD%90%E7%BA%BF%E7%A8%8B%E5%B9%B6%E4%B8%8D%E8%83%BD%E5%8F%96%E5%88%B0%E7%88%B6%E7%BA%BF%E7%A8%8B%E7%9A%84ThreadLocal%E7%B1%BB%E7%9A%84%E5%8F%98%E9%87%8F%EF%BC%8CInheritableThreadLocal%E7%B1%BB%E5%B0%B1%E6%98%AF%E8%A7%A3%E5%86%B3%E8%BF%99%E4%B8%AA%E9%97%AE%E9%A2%98%E7%9A%84%E3%80%82%0A*%20%E5%9C%A8%E4%BD%BF%E7%94%A8InheritableThreadLocal%E7%B1%BB%E9%9C%80%E8%A6%81%E6%B3%A8%E6%84%8F%E7%9A%84%E4%B8%80%E7%82%B9%E6%98%AF%EF%BC%9A%E5%A6%82%E6%9E%9C%E5%AD%90%E7%BA%BF%E7%A8%8B%E5%9C%A8%E5%8F%96%E5%BE%97%E5%80%BC%E7%9A%84%E5%90%8C%E6%97%B6%EF%BC%8C%E4%B8%BB%E7%BA%BF%E7%A8%8B%E5%B0%86InheritableThreadLocal%E4%B8%AD%E7%9A%84%E5%80%BC%E8%BF%9B%E8%A1%8C%E6%9B%B4%E6%94%B9%EF%BC%8C%E9%82%A3%E4%B9%88%E5%AD%90%E7%BA%BF%E7%A8%8B%E5%8F%96%E5%88%B0%E7%9A%84%E8%BF%98%E6%98%AF%E6%97%A7%E5%80%BC%E3%80%82%0A&lt;/center&gt;&lt;/div&gt;
</content>
  </entry>
  <entry xml:base="http://linzhiteng.postach.io/feed.xml">
    <title type="text">四. Lock锁的使用</title>
    <id>https://linzhiteng.postach.io/post/si-locksuo-de-shi-yong</id>
    <updated>2019-06-09T13:07:49.285000Z</updated>
    <published>2019-03-12T14:19:38Z</published>
    <link href="https://linzhiteng.postach.io/post/si-locksuo-de-shi-yong" />
    <author>
      <name>linzhi teng</name>
    </author>
    <category term="xian-cheng" />
    <content type="html">&lt;div&gt;&lt;div style=&quot;font-size: 14px; margin: 0; padding: 0; width: 100%;&quot;&gt;&lt;div style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;四. Lock锁的使用
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1 Lock接口
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.1 Lock接口简介
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.2. Lock的简单使用
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.3. Lock接口的特性和常见方法
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2. Lock接口的实现类：ReentrantLock
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.1 ReentrantLock类常见方法
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.2 第一个ReentrantLock程序
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3. Condition接口简介
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1 使用Condition实现等待/通知机制
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4. 公平锁与非公平锁
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;5. ReadWriteLock接口的实现类：ReentrantReadWriteLock
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;5.1 简介
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;5.2 ReentrantReadWriteLock的特性与常见方法
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;5.3 ReentrantReadWriteLock的使用
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;四. Lock锁的使用&lt;/h2&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/540068a3-005f-4cf5-a3b9-0b5cb27867f6/11bf2a91-3c9d-40db-8ce7-595e51678efc.jpg&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;a href=&quot;https://blog.csdn.net/qq_34337272/article/details/79714196&quot; style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;lock锁的使用&lt;/a&gt;&lt;/p&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;1 Lock接口&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.1 Lock接口简介&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;锁是用于通过多个线程&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;控制对共享资源的访问&lt;/strong&gt;的工具。&lt;br/&gt;
通常，锁提供对&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;共享资源的独占访问&lt;/strong&gt;：一次只能有一个线程可以获取锁，并且对共享资源的所有访问都要求首先获取锁。&lt;br/&gt;
但是，一些锁可能允许并发访问共享资源，如ReadWriteLock的读写锁。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;在Lock接口出现之前，Java程序是靠synchronized关键字实现锁功能的。JDK1.5之后并发包中新增了Lock接口以及相关实现类来实现锁功能。&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0;&quot;&gt;Lock接口的实现类：&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;ReentrantLock&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;ReentrantReadWriteLock.ReadLock&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;ReentrantReadWriteLock.WriteLock&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.2. Lock的简单使用&lt;/h4&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt; Lock lock = &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; ReentrantLock()； 
 lock.lock(); 
 &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;try&lt;/span&gt;{ 
 }&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;finally&lt;/span&gt;{ 
 lock.unlock(); 
 }
&lt;/code&gt;&lt;/pre&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;因为Lock是接口所以使用时要结合它的实现类，另外在finall语句块中释放锁的目的是保证获取到锁之后，最终能够被释放。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;注意： 最好不要把获取锁的过程写在try语句块中，因为如果在获取锁时发生了异常，异常抛出的同时也会导致锁无法被释放。&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.3. Lock接口的特性和常见方法&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;Lock接口提供的synchronized关键字不具备的主要特性：&lt;/li&gt;
&lt;/ul&gt;
&lt;table style=&quot;margin: 2px 0 14px; color: #333; width: auto; border-collapse: collapse; box-sizing: border-box;&quot;&gt;&lt;thead style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;特性&lt;/th&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;描述&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;尝试非阻塞地获取锁&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;当前线程尝试获取锁，如果这一时刻锁没有被其他线程获取到，则成功获取并持有锁&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;能被中断地获取锁&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;获取到锁的线程能够响应中断，当获取到锁的线程被中断时，中断异常将会被抛出，同时锁会被释放&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;超时获取锁&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;在指定的截止时间之前获取锁， 超过截止时间后仍旧无法获取则返回&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;Lock接口基本的方法：&lt;/li&gt;
&lt;/ul&gt;
&lt;table style=&quot;margin: 2px 0 14px; color: #333; width: auto; border-collapse: collapse; box-sizing: border-box;&quot;&gt;&lt;thead style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;方法名称&lt;/th&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;描述&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;void lock()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;获得锁。如果锁不可用，则当前线程将被禁用以进行线程调度，并处于休眠状态，直到获取锁。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;void lockInterruptibly()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;获取锁，如果可用并立即返回。如果锁不可用，那么当前线程将被禁用以进行线程调度，并且处于休眠状态，和lock()方法不同的是在锁的获取中可以中断当前线程（相应中断）。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;Condition newCondition()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;获取等待通知组件，该组件和当前的锁绑定，当前线程只有获得了锁，才能调用该组件的wait()方法，而调用后，当前线程将释放锁。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;boolean tryLock()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;只有在调用时才可以获得锁。如果可用，则获取锁定，并立即返回值为true；如果锁不可用，则此方法将立即返回值为false 。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;boolean tryLock(long time, TimeUnit unit)&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;超时获取锁，当前线程在一下三种情况下会返回： 1. 当前线程在超时时间内获得了锁；2.当前线程在超时时间内被中断；3.超时时间结束，返回false.&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;void unlock()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;释放锁。&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;2. Lock接口的实现类：ReentrantLock&lt;/h3&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;ReentrantLock和synchronized关键字一样可以用来实现线程之间的同步互斥，但是在功能是比synchronized关键字更强大而且更灵活。&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.1 ReentrantLock类常见方法&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;构造方法：&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;table style=&quot;margin: 2px 0 14px; color: #333; width: auto; border-collapse: collapse; box-sizing: border-box;&quot;&gt;&lt;thead style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;方法名称&lt;/th&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;描述&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;ReentrantLock()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;创建一个 ReentrantLock的实例。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;ReentrantLock(boolean fair)&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;创建一个特定锁类型（公平锁/非公平锁）的ReentrantLock的实例&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;ReentrantLock类常见方法(Lock接口已有方法这里没加上)：&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;table style=&quot;margin: 2px 0 14px; color: #333; width: auto; border-collapse: collapse; box-sizing: border-box;&quot;&gt;&lt;thead style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;方法名称&lt;/th&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;描述&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;int getHoldCount()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;查询当前线程保持此锁定的个数，也就是调用lock()方法的次数。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;protected Thread getOwner()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;返回当前拥有此锁的线程，如果不拥有，则返回 null&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;protected Collection getQueuedThreads()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;返回包含可能正在等待获取此锁的线程的集合&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;int getQueueLength()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;返回等待获取此锁的线程数的估计。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;protected Collection getWaitingThreads(Condition condition)&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;返回包含可能在与此锁相关联的给定条件下等待的线程的集合。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;int getWaitQueueLength(Condition condition)&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;返回与此锁相关联的给定条件等待的线程数的估计。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;boolean hasQueuedThread(Thread thread)&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;查询给定线程是否等待获取此锁。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;boolean hasQueuedThreads()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;查询是否有线程正在等待获取此锁。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;boolean hasWaiters(Condition condition)&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;查询任何线程是否等待与此锁相关联的给定条件&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;boolean isFair()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;如果此锁的公平设置为true，则返回 true 。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;boolean isHeldByCurrentThread()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;查询此锁是否由当前线程持有。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;boolean isLocked()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;查询此锁是否由任何线程持有。&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.2 第一个ReentrantLock程序&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;当一个线程运行完毕后才把锁释放，其他线程才能执行，其他线程的执行顺序是不确定的。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;3. Condition接口简介&lt;/h3&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;synchronized关键字与wait()和notify/notifyAll()方法相结合可以实现等待/通知机制，ReentrantLock类当然也可以实现，但是需要借助于Condition接口与newCondition() 方法。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;Condition是JDK1.5之后才有的，它具有很好的灵活性，比如可以实现&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;多路通知功&lt;/strong&gt;能，也就是在一个Lock对象中可以创建多个Condition实例（即对象监视器），线程对象可以注册在指定的Condition中，从而可以有选择性的进行线程通知，在调度线程上更加灵活。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;在使用notify/notifyAll()方法进行通知时，被通知的线程是有JVM选择的，使用ReentrantLock类结合Condition实例可以实现&quot;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;选择性通知&lt;/strong&gt;&quot;，这个功能非常重要，而且是Condition接口默认提供的。&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;Condition接口的常见方法：&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;table style=&quot;margin: 2px 0 14px; color: #333; width: auto; border-collapse: collapse; box-sizing: border-box;&quot;&gt;&lt;thead style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;方法名称&lt;/th&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;描述&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;void await()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;相当于Object类的wait方法&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;boolean await(long time, TimeUnit unit)&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;相当于Object类的wait(long timeout)方法&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;signal()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;相当于Object类的notify方法&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;signalAll()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;相当于Object类的notifyAll方法&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;synchronized关键字就相当于整个Lock对象中只有一个Condition实例，所有的线程都注册在它一个身上。如果执行notifyAll()方法的话就会通知所有处于等待状态的线程这样会造成很大的效率问题，而Condition实例的signalAll()方法 只会唤醒注册在该Condition实例中的所有等待线程&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.1 使用Condition实现等待/通知机制&lt;/h4&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;使用单个Condition实例实现等待/通知机制：&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;必须执行完signal所在的try语句块之后才释放锁，condition.await()后的语句才能被执行。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;注意： 必须在condition.await()方法调用之前调用lock.lock()代码获得同步监视器，不然会报错。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;ol start=&quot;2&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;使用多个Condition实例实现等待/通知机制：&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;实现&quot;选择性通知&quot;,只会唤醒注册在指定Condition实例中的所有等待线程&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;ol start=&quot;3&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;使用Condition实现顺序执行&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;在一个线程运行完之后通过condition.signal()/condition.signalAll()方法通知下一个特定的线程运行，就这样循环往复即可。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;注意： 默认情况下ReentranLock类使用的是非公平锁&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;4. 公平锁与非公平锁&lt;/h3&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;Lock锁分为：公平锁 和 非公平锁。&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;公平锁表示线程获取锁的顺序是按照线程加锁的顺序来分配的，即先来先得的FIFO先进先出顺序。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;而非公平锁就是一种获取锁的抢占机制，是随机获取锁的，和公平锁不一样的就是先来的不一定先的到锁，这样可能造成某些线程一直拿不到锁，结果也就是不公平的了。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;5. ReadWriteLock接口的实现类：ReentrantReadWriteLock&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;5.1 简介&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;ReentrantLock（排他锁）具有完全互斥排他的效果，即同一时刻只允许一个线程访问，这样做虽然虽然保证了实例变量的线程安全性，但效率非常低下。&lt;br/&gt;
ReadWriteLock接口的实现类-ReentrantReadWriteLock读写锁就是为了解决这个问题。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;读写锁维护了两个锁，一个是&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;读操作&lt;/strong&gt;相关的锁也成为&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;共享锁&lt;/strong&gt;，&lt;br/&gt;
一个是&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;写操作&lt;/strong&gt;相关的锁也称为&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;排他锁&lt;/strong&gt;。&lt;br/&gt;
通过分离读锁和写锁，其并发性比一般排他锁有了很大提升。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;多个读锁之间不互斥，读锁与写锁互斥，写锁与写锁互斥（只要出现写操作的过程就是互斥的）&lt;br/&gt;
在没有线程Thread进行写入操作时，进行读取操作的多个Thread都可以获取读锁，&lt;br/&gt;
而进行写入操作的Thread只有在获取写锁后才能进行写入操作。&lt;br/&gt;
即多个Thread可以&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;同时进行读取操作&lt;/strong&gt;,但是同一时刻&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;只允许一个Thread进行写入操作&lt;/strong&gt;。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;5.2 ReentrantReadWriteLock的特性与常见方法&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;ReentrantReadWriteLock的特性：&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;table style=&quot;margin: 2px 0 14px; color: #333; width: auto; border-collapse: collapse; box-sizing: border-box;&quot;&gt;&lt;thead style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;特性&lt;/th&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;说明&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;公平性选择&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;支持非公平（默认）和公平的锁获取方式，吞吐量上来看还是非公平优于公平&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;重进入&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;该锁支持重进入，以读写线程为例：读线程在获取了读锁之后，能够再次获取读锁。而写线程在获取了写锁之后能够再次获取写锁也能够同时获取读锁&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;锁降级&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;遵循获取写锁、获取读锁再释放写锁的次序，写锁能够降级称为读锁&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;ReentrantReadWriteLock常见方法：&lt;br/&gt;
 构造方法&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;table style=&quot;margin: 2px 0 14px; color: #333; width: auto; border-collapse: collapse; box-sizing: border-box;&quot;&gt;&lt;thead style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;方法名称&lt;/th&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;描述&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;ReentrantReadWriteLock()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;创建一个 ReentrantReadWriteLock()的实例&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;ReentrantReadWriteLock(boolean fair)&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;创建一个特定锁类型（公平锁/非公平锁）的ReentrantReadWriteLock的实例&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;常见方法： &lt;br/&gt;
和ReentrantLock类 类似&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;5.3 ReentrantReadWriteLock的使用&lt;/h4&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;读读共享
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;两个线程同时运行read方法，你会发现两个线程可以同时或者说是几乎同时运行lock()方法后面的代码，输出的两句话显示的时间一样。这样提高了程序的运行效率。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;写写互斥
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;两个线程同时运行write方法，你会发现同一时间只允许一个线程执行lock()方法后面的代码&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;读写互斥（读写互斥）
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0;&quot;&gt;运行两个使用同一个Service对象实例的线程a,b，线程a执行上面的read方法，线程b执行上面的write方法。你会发现同一时间只允许一个线程执行lock()方法后面的代码。&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;记住：只要出现写操作的过程就是互斥的。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;&lt;center style='display:none !important;visibility:collapse !important;height:0 !important;white-space:nowrap;width:100%;overflow:hidden'&gt;%5Btoc%5D%0A%23%23%20%E5%9B%9B.%20Lock%E9%94%81%E7%9A%84%E4%BD%BF%E7%94%A8%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/540068a3-005f-4cf5-a3b9-0b5cb27867f6/11bf2a91-3c9d-40db-8ce7-595e51678efc.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F612%3A1)%0A%5Block%E9%94%81%E7%9A%84%E4%BD%BF%E7%94%A8%5D(https%3A%2F%2Fblog.csdn.net%2Fqq_34337272%2Farticle%2Fdetails%2F79714196)%0A%0A%23%23%23%201%20Lock%E6%8E%A5%E5%8F%A3%0A%23%23%23%23%201.1%20Lock%E6%8E%A5%E5%8F%A3%E7%AE%80%E4%BB%8B%0A%3E%E9%94%81%E6%98%AF%E7%94%A8%E4%BA%8E%E9%80%9A%E8%BF%87%E5%A4%9A%E4%B8%AA%E7%BA%BF%E7%A8%8B**%E6%8E%A7%E5%88%B6%E5%AF%B9%E5%85%B1%E4%BA%AB%E8%B5%84%E6%BA%90%E7%9A%84%E8%AE%BF%E9%97%AE**%E7%9A%84%E5%B7%A5%E5%85%B7%E3%80%82%0A%3E%E9%80%9A%E5%B8%B8%EF%BC%8C%E9%94%81%E6%8F%90%E4%BE%9B%E5%AF%B9**%E5%85%B1%E4%BA%AB%E8%B5%84%E6%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%8F%A3%E7%9A%84%E5%AE%9E%E7%8E%B0%E7%B1%BB%EF%BC%9A%C2%A0%0A%3E*%20ReentrantLock%20%0A%3E%20*%20ReentrantReadWriteLock.ReadLock%20%0A%3E%20%20*%20ReentrantReadWriteLock.WriteLock%0A%0A%23%23%23%23%201.2.%20Lock%E7%9A%84%E7%AE%80%E5%8D%95%E4%BD%BF%E7%94%A8%0A%60%60%60java%0A%20Lock%20lock%20%3D%20new%20ReentrantLock()%EF%BC%9B%20%0A%20lock.lock()%3B%20%0A%20try%7B%20%0A%20%7Dfinally%7B%20%0A%20lock.unlock()%3B%20%0A%20%7D%0A%60%60%60%0A*%20%E5%9B%A0%E4%B8%BALock%E6%98%AF%E6%8E%A5%E5%8F%A3%E6%89%80%E4%BB%A5%E4%BD%BF%E7%94%A8%E6%97%B6%E8%A6%81%E7%BB%93%E5%90%88%E5%AE%83%E7%9A%84%E5%AE%9E%E7%8E%B0%E7%B1%BB%EF%BC%8C%E5%8F%A6%E5%A4%96%E5%9C%A8finall%E8%AF%AD%E5%8F%A5%E5%9D%97%E4%B8%AD%E9%87%8A%E6%94%BE%E9%94%81%E7%9A%84%E7%9B%AE%E7%9A%84%E6%98%AF%E4%BF%9D%E8%AF%81%E8%8E%B7%E5%8F%96%E5%88%B0%E9%94%81%E4%B9%8B%E5%90%8E%EF%BC%8C%E6%9C%80%E7%BB%88%E8%83%BD%E5%A4%9F%E8%A2%AB%E9%87%8A%E6%94%BE%E3%80%82%0A*%20%E6%B3%A8%E6%84%8F%EF%BC%9A%C2%A0%E6%9C%80%E5%A5%BD%E4%B8%8D%E8%A6%81%E6%8A%8A%E8%8E%B7%E5%8F%96%E9%94%81%E7%9A%84%E8%BF%87%E7%A8%8B%E5%86%99%E5%9C%A8try%E8%AF%AD%E5%8F%A5%E5%9D%97%E4%B8%AD%EF%BC%8C%E5%9B%A0%E4%B8%BA%E5%A6%82%E6%9E%9C%E5%9C%A8%E8%8E%B7%E5%8F%96%E9%94%81%E6%97%B6%E5%8F%91%E7%94%9F%E4%BA%86%E5%BC%82%E5%B8%B8%EF%BC%8C%E5%BC%82%E5%B8%B8%E6%8A%9B%E5%87%BA%E7%9A%84%E5%90%8C%E6%97%B6%E4%B9%9F%E4%BC%9A%E5%AF%BC%E8%87%B4%E9%94%81%E6%97%A0%E6%B3%95%E8%A2%AB%E9%87%8A%E6%94%BE%E3%80%82%0A%0A%23%23%23%23%201.3.%20Lock%E6%8E%A5%E5%8F%A3%E7%9A%84%E7%89%B9%E6%80%A7%E5%92%8C%E5%B8%B8%E8%A7%81%E6%96%B9%E6%B3%95%0A*%20Lock%E6%8E%A5%E5%8F%A3%E6%8F%90%E4%BE%9B%E7%9A%84synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E4%B8%8D%E5%85%B7%E5%A4%87%E7%9A%84%E4%B8%BB%E8%A6%81%E7%89%B9%E6%80%A7%EF%BC%9A%0A%0A%7C%20%E7%89%B9%E6%80%A7%20%7C%E6%8F%8F%E8%BF%B0%20%20%7C%0A%7C%20---%20%7C%20---%20%7C%0A%7C%20%E5%B0%9D%E8%AF%95%E9%9D%9E%E9%98%BB%E5%A1%9E%E5%9C%B0%E8%8E%B7%E5%8F%96%E9%94%81%20%7C%E5%BD%93%E5%89%8D%E7%BA%BF%E7%A8%8B%E5%B0%9D%E8%AF%95%E8%8E%B7%E5%8F%96%E9%94%81%EF%BC%8C%E5%A6%82%E6%9E%9C%E8%BF%99%E4%B8%80%E6%97%B6%E5%88%BB%E9%94%81%E6%B2%A1%E6%9C%89%E8%A2%AB%E5%85%B6%E4%BB%96%E7%BA%BF%E7%A8%8B%E8%8E%B7%E5%8F%96%E5%88%B0%EF%BC%8C%E5%88%99%E6%88%90%E5%8A%9F%E8%8E%B7%E5%8F%96%E5%B9%B6%E6%8C%81%E6%9C%89%E9%94%81%20%7C%0A%7C%20%E8%83%BD%E8%A2%AB%E4%B8%AD%E6%96%AD%E5%9C%B0%E8%8E%B7%E5%8F%96%E9%94%81%20%7C%20%E8%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%E5%89%8D%E7%9A%84%E9%94%81%E7%BB%91%E5%AE%9A%EF%BC%8C%E5%BD%93%E5%89%8D%E7%BA%BF%E7%A8%8B%E5%8F%AA%E6%9C%89%E8%8E%B7%E5%BE%97%E4%BA%86%E9%94%81%EF%BC%8C%E6%89%8D%E8%83%BD%E8%B0%83%E7%94%A8%E8%AF%A5%E7%BB%84%E4%BB%B6%E7%9A%84wait()%E6%96%B9%E6%B3%95%EF%BC%8C%E8%80%8C%E8%B0%83%E7%94%A8%E5%90%8E%EF%BC%8C%E5%BD%93%E5%89%8D%E7%BA%BF%E7%A8%8B%E5%B0%86%E9%87%8A%E6%94%BE%E9%94%81%E3%80%82%7C%0A%7Cboolean%20tryLock()%09%7C%E5%8F%AA%E6%9C%89%E5%9C%A8%E8%B0%83%E7%94%A8%E6%97%B6%E6%89%8D%E5%8F%AF%E4%BB%A5%E8%8E%B7%E5%BE%97%E9%94%81%E3%80%82%E5%A6%82%E6%9E%9C%E5%8F%AF%E7%94%A8%EF%BC%8C%E5%88%99%E8%8E%B7%E5%8F%96%E9%94%81%E5%AE%9A%EF%BC%8C%E5%B9%B6%E7%AB%8B%E5%8D%B3%E8%BF%94%E5%9B%9E%E5%80%BC%E4%B8%BAtrue%EF%BC%9B%E5%A6%82%E6%9E%9C%E9%94%81%E4%B8%8D%E5%8F%AF%E7%94%A8%EF%BC%8C%E5%88%99%E6%AD%A4%E6%96%B9%E6%B3%95%E5%B0%86%E7%AB%8B%E5%8D%B3%E8%BF%94%E5%9B%9E%E5%80%BC%E4%B8%BAfalse%20%E3%80%82%7C%0A%7Cboolean%20tryLock(long%20time%2C%20TimeUnit%20unit)%09%7C%E8%B6%85%E6%97%B6%E8%8E%B7%E5%8F%96%E9%94%81%EF%BC%8C%E5%BD%93%E5%89%8D%E7%BA%BF%E7%A8%8B%E5%9C%A8%E4%B8%80%E4%B8%8B%E4%B8%89%E7%A7%8D%E6%83%85%E5%86%B5%E4%B8%8B%E4%BC%9A%E8%BF%94%E5%9B%9E%EF%BC%9A%201.%20%E5%BD%93%E5%89%8D%E7%BA%BF%E7%A8%8B%E5%9C%A8%E8%B6%85%E6%97%B6%E6%97%B6%E9%97%B4%E5%86%85%E8%8E%B7%E5%BE%97%E4%BA%86%E9%94%81%EF%BC%9B2.%E5%BD%93%E5%89%8D%E7%BA%BF%E7%A8%8B%E5%9C%A8%E8%B6%85%E6%97%B6%E6%97%B6%E9%97%B4%E5%86%85%E8%A2%AB%E4%B8%AD%E6%96%AD%EF%BC%9B3.%E8%B6%85%E6%97%B6%E6%97%B6%E9%97%B4%E7%BB%93%E6%9D%9F%EF%BC%8C%E8%BF%94%E5%9B%9Efalse.%7C%0A%7Cvoid%20unlock()%09%7C%E9%87%8A%E6%94%BE%E9%94%81%E3%80%82%7C%0A%0A%23%23%23%202.%20Lock%E6%8E%A5%E5%8F%A3%E7%9A%84%E5%AE%9E%E7%8E%B0%E7%B1%BB%EF%BC%9AReentrantLock%0A*%20ReentrantLock%E5%92%8Csynchronized%E5%85%B3%E9%94%AE%E5%AD%97%E4%B8%80%E6%A0%B7%E5%8F%AF%E4%BB%A5%E7%94%A8%E6%9D%A5%E5%AE%9E%E7%8E%B0%E7%BA%BF%E7%A8%8B%E4%B9%8B%E9%97%B4%E7%9A%84%E5%90%8C%E6%AD%A5%E4%BA%92%E6%96%A5%EF%BC%8C%E4%BD%86%E6%98%AF%E5%9C%A8%E5%8A%9F%E8%83%BD%E6%98%AF%E6%AF%94synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E6%9B%B4%E5%BC%BA%E5%A4%A7%E8%80%8C%E4%B8%94%E6%9B%B4%E7%81%B5%E6%B4%BB%E3%80%82%0A%23%23%23%23%202.1%20ReentrantLock%E7%B1%BB%E5%B8%B8%E8%A7%81%E6%96%B9%E6%B3%95%0A%3E%20*%20%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95%EF%BC%9A%0A%0A%7C%E6%96%B9%E6%B3%95%E5%90%8D%E7%A7%B0%7C%E6%8F%8F%E8%BF%B0%7C%0A%7C%20---%20%7C%20---%20%7C%0A%7CReentrantLock()%7C%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%20ReentrantLock%E7%9A%84%E5%AE%9E%E4%BE%8B%E3%80%82%7C%0A%7CReentrantLock(boolean%20fair)%7C%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E7%89%B9%E5%AE%9A%E9%94%81%E7%B1%BB%E5%9E%8B%EF%BC%88%E5%85%AC%E5%B9%B3%E9%94%81%2F%E9%9D%9E%E5%85%AC%E5%B9%B3%E9%94%81%EF%BC%89%E7%9A%84ReentrantLock%E7%9A%84%E5%AE%9E%E4%BE%8B%7C%0A%0A%3E*%20ReentrantLock%E7%B1%BB%E5%B8%B8%E8%A7%81%E6%96%B9%E6%B3%95(Lock%E6%8E%A5%E5%8F%A3%E5%B7%B2%E6%9C%89%E6%96%B9%E6%B3%95%E8%BF%99%E9%87%8C%E6%B2%A1%E5%8A%A0%E4%B8%8A)%EF%BC%9A%0A%0A%7C%E6%96%B9%E6%B3%95%E5%90%8D%E7%A7%B0%09%7C%E6%8F%8F%E8%BF%B0%7C%0A%7C%20---%20%7C%20---%20%7C%0A%7Cint%20getHoldCount()%09%7C%E6%9F%A5%E8%AF%A2%E5%BD%93%E5%89%8D%E7%BA%BF%E7%A8%8B%E4%BF%9D%E6%8C%81%E6%AD%A4%E9%94%81%E5%AE%9A%E7%9A%84%E4%B8%AA%E6%95%B0%EF%BC%8C%E4%B9%9F%E5%B0%B1%E6%98%AF%E8%B0%83%E7%94%A8lock()%E6%96%B9%E6%B3%95%E7%9A%84%E6%AC%A1%E6%95%B0%E3%80%82%7C%0A%7Cprotected%20Thread%20getOwner()%09%7C%E8%BF%94%E5%9B%9E%E5%BD%93%E5%89%8D%E6%8B%A5%E6%9C%89%E6%AD%A4%E9%94%81%E7%9A%84%E7%BA%BF%E7%A8%8B%EF%BC%8C%E5%A6%82%E6%9E%9C%E4%B8%8D%E6%8B%A5%E6%9C%89%EF%BC%8C%E5%88%99%E8%BF%94%E5%9B%9E%20null%7C%0A%7Cprotected%20Collection%20getQueuedThreads()%09%7C%E8%BF%94%E5%9B%9E%E5%8C%85%E5%90%AB%E5%8F%AF%E8%83%BD%E6%AD%A3%E5%9C%A8%E7%AD%89%E5%BE%85%E8%8E%B7%E5%8F%96%E6%AD%A4%E9%94%81%E7%9A%84%E7%BA%BF%E7%A8%8B%E7%9A%84%E9%9B%86%E5%90%88%7C%0A%7Cint%20getQueueLength()%09%7C%E8%BF%94%E5%9B%9E%E7%AD%89%E5%BE%85%E8%8E%B7%E5%8F%96%E6%AD%A4%E9%94%81%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%95%B0%E7%9A%84%E4%BC%B0%E8%AE%A1%E3%80%82%7C%0A%7Cprotected%20Collection%20getWaitingThreads(Condition%20condition)%09%7C%E8%BF%94%E5%9B%9E%E5%8C%85%E5%90%AB%E5%8F%AF%E8%83%BD%E5%9C%A8%E4%B8%8E%E6%AD%A4%E9%94%81%E7%9B%B8%E5%85%B3%E8%81%94%E7%9A%84%E7%BB%99%E5%AE%9A%E6%9D%A1%E4%BB%B6%E4%B8%8B%E7%AD%89%E5%BE%85%E7%9A%84%E7%BA%BF%E7%A8%8B%E7%9A%84%E9%9B%86%E5%90%88%E3%80%82%7C%0A%7Cint%20getWaitQueueLength(Condition%20condition)%7C%09%E8%BF%94%E5%9B%9E%E4%B8%8E%E6%AD%A4%E9%94%81%E7%9B%B8%E5%85%B3%E8%81%94%E7%9A%84%E7%BB%99%E5%AE%9A%E6%9D%A1%E4%BB%B6%E7%AD%89%E5%BE%85%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%95%B0%E7%9A%84%E4%BC%B0%E8%AE%A1%E3%80%82%7C%0A%7Cboolean%20hasQueuedThread(Thread%20thread)%7C%09%E6%9F%A5%E8%AF%A2%E7%BB%99%E5%AE%9A%E7%BA%BF%E7%A8%8B%E6%98%AF%E5%90%A6%E7%AD%89%E5%BE%85%E8%8E%B7%E5%8F%96%E6%AD%A4%E9%94%81%E3%80%82%7C%0A%7Cboolean%20hasQueuedThreads()%7C%09%E6%9F%A5%E8%AF%A2%E6%98%AF%E5%90%A6%E6%9C%89%E7%BA%BF%E7%A8%8B%E6%AD%A3%E5%9C%A8%E7%AD%89%E5%BE%85%E8%8E%B7%E5%8F%96%E6%AD%A4%E9%94%81%E3%80%82%7C%0A%7Cboolean%20hasWaiters(Condition%20condition)%7C%09%E6%9F%A5%E8%AF%A2%E4%BB%BB%E4%BD%95%E7%BA%BF%E7%A8%8B%E6%98%AF%E5%90%A6%E7%AD%89%E5%BE%85%E4%B8%8E%E6%AD%A4%E9%94%81%E7%9B%B8%E5%85%B3%E8%81%94%E7%9A%84%E7%BB%99%E5%AE%9A%E6%9D%A1%E4%BB%B6%7C%0A%7Cboolean%20isFair()%09%7C%E5%A6%82%E6%9E%9C%E6%AD%A4%E9%94%81%E7%9A%84%E5%85%AC%E5%B9%B3%E8%AE%BE%E7%BD%AE%E4%B8%BAtrue%EF%BC%8C%E5%88%99%E8%BF%94%E5%9B%9E%20true%20%E3%80%82%7C%0A%7Cboolean%20isHeldByCurrentThread()%7C%09%E6%9F%A5%E8%AF%A2%E6%AD%A4%E9%94%81%E6%98%AF%E5%90%A6%E7%94%B1%E5%BD%93%E5%89%8D%E7%BA%BF%E7%A8%8B%E6%8C%81%E6%9C%89%E3%80%82%7C%0A%7Cboolean%20isLocked()%7C%E6%9F%A5%E8%AF%A2%E6%AD%A4%E9%94%81%E6%98%AF%E5%90%A6%E7%94%B1%E4%BB%BB%E4%BD%95%E7%BA%BF%E7%A8%8B%E6%8C%81%E6%9C%89%E3%80%82%7C%0A%0A%23%23%23%23%202.2%20%E7%AC%AC%E4%B8%80%E4%B8%AAReentrantLock%E7%A8%8B%E5%BA%8F%0A*%20%E5%BD%93%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%E8%BF%90%E8%A1%8C%E5%AE%8C%E6%AF%95%E5%90%8E%E6%89%8D%E6%8A%8A%E9%94%81%E9%87%8A%E6%94%BE%EF%BC%8C%E5%85%B6%E4%BB%96%E7%BA%BF%E7%A8%8B%E6%89%8D%E8%83%BD%E6%89%A7%E8%A1%8C%EF%BC%8C%E5%85%B6%E4%BB%96%E7%BA%BF%E7%A8%8B%E7%9A%84%E6%89%A7%E8%A1%8C%E9%A1%BA%E5%BA%8F%E6%98%AF%E4%B8%8D%E7%A1%AE%E5%AE%9A%E7%9A%84%E3%80%82%0A%0A%23%23%23%203.%20Condition%E6%8E%A5%E5%8F%A3%E7%AE%80%E4%BB%8B%0A*%20synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E4%B8%8Ewait()%E5%92%8Cnotify%2FnotifyAll()%E6%96%B9%E6%B3%95%E7%9B%B8%E7%BB%93%E5%90%88%E5%8F%AF%E4%BB%A5%E5%AE%9E%E7%8E%B0%E7%AD%89%E5%BE%85%2F%E9%80%9A%E7%9F%A5%E6%9C%BA%E5%88%B6%EF%BC%8CReentrantLock%E7%B1%BB%E5%BD%93%E7%84%B6%E4%B9%9F%E5%8F%AF%E4%BB%A5%E5%AE%9E%E7%8E%B0%EF%BC%8C%E4%BD%86%E6%98%AF%E9%9C%80%E8%A6%81%E5%80%9F%E5%8A%A9%E4%BA%8ECondition%E6%8E%A5%E5%8F%A3%E4%B8%8EnewCondition()%20%E6%96%B9%E6%B3%95%E3%80%82%0A*%20Condition%E6%98%AFJDK1.5%E4%B9%8B%E5%90%8E%E6%89%8D%E6%9C%89%E7%9A%84%EF%BC%8C%E5%AE%83%E5%85%B7%E6%9C%89%E5%BE%88%E5%A5%BD%E7%9A%84%E7%81%B5%E6%B4%BB%E6%80%A7%EF%BC%8C%E6%AF%94%E5%A6%82%E5%8F%AF%E4%BB%A5%E5%AE%9E%E7%8E%B0**%E5%A4%9A%E8%B7%AF%E9%80%9A%E7%9F%A5%E5%8A%9F**%E8%83%BD%EF%BC%8C%E4%B9%9F%E5%B0%B1%E6%98%AF%E5%9C%A8%E4%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4%B8%94%E6%98%AFCondition%E6%8E%A5%E5%8F%A3%E9%BB%98%E8%AE%A4%E6%8F%90%E4%BE%9B%E7%9A%84%E3%80%82%0A%0A%3E%20*%20Condition%E6%8E%A5%E5%8F%A3%E7%9A%84%E5%B8%B8%E8%A7%81%E6%96%B9%E6%B3%95%EF%BC%9A%0A%0A%7C%E6%96%B9%E6%B3%95%E5%90%8D%E7%A7%B0%7C%09%E6%8F%8F%E8%BF%B0%7C%0A%7C%20---%20%7C%20---%20%7C%0A%7Cvoid%20await()%7C%09%E7%9B%B8%E5%BD%93%E4%BA%8EObject%E7%B1%BB%E7%9A%84wait%E6%96%B9%E6%B3%95%7C%0A%7Cboolean%20await(long%20time%2C%20TimeUnit%20unit)%09%7C%E7%9B%B8%E5%BD%93%E4%BA%8EObject%E7%B1%BB%E7%9A%84wait(long%20timeout)%E6%96%B9%E6%B3%95%7C%0A%7Csignal()%7C%09%E7%9B%B8%E5%BD%93%E4%BA%8EObject%E7%B1%BB%E7%9A%84notify%E6%96%B9%E6%B3%95%7C%0A%7CsignalAll()%7C%09%E7%9B%B8%E5%BD%93%E4%BA%8EObject%E7%B1%BB%E7%9A%84notifyAll%E6%96%B9%E6%B3%95%7C%0A%0A*%20synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E5%B0%B1%E7%9B%B8%E5%BD%93%E4%BA%8E%E6%95%B4%E4%B8%AALock%E5%AF%B9%E8%B1%A1%E4%B8%AD%E5%8F%AA%E6%9C%89%E4%B8%80%E4%B8%AACondition%E5%AE%9E%E4%BE%8B%EF%BC%8C%E6%89%80%E6%9C%89%E7%9A%84%E7%BA%BF%E7%A8%8B%E9%83%BD%E6%B3%A8%E5%86%8C%E5%9C%A8%E5%AE%83%E4%B8%80%E4%B8%AA%E8%BA%AB%E4%B8%8A%E3%80%82%E5%A6%82%E6%9E%9C%E6%89%A7%E8%A1%8CnotifyAll()%E6%96%B9%E6%B3%95%E7%9A%84%E8%AF%9D%E5%B0%B1%E4%BC%9A%E9%80%9A%E7%9F%A5%E6%89%80%E6%9C%89%E5%A4%84%E4%BA%8E%E7%AD%89%E5%BE%85%E7%8A%B6%E6%80%81%E7%9A%84%E7%BA%BF%E7%A8%8B%E8%BF%99%E6%A0%B7%E4%BC%9A%E9%80%A0%E6%88%90%E5%BE%88%E5%A4%A7%E7%9A%84%E6%95%88%E7%8E%87%E9%97%AE%E9%A2%98%EF%BC%8C%E8%80%8CCondition%E5%AE%9E%E4%BE%8B%E7%9A%84signalAll()%E6%96%B9%E6%B3%95%20%E5%8F%AA%E4%BC%9A%E5%94%A4%E9%86%92%E6%B3%A8%E5%86%8C%E5%9C%A8%E8%AF%A5Condition%E5%AE%9E%E4%BE%8B%E4%B8%AD%E7%9A%84%E6%89%80%E6%9C%89%E7%AD%89%E5%BE%85%E7%BA%BF%E7%A8%8B%0A%0A%23%23%23%23%203.1%20%E4%BD%BF%E7%94%A8Condition%E5%AE%9E%E7%8E%B0%E7%AD%89%E5%BE%85%2F%E9%80%9A%E7%9F%A5%E6%9C%BA%E5%88%B6%0A1.%20%20%E4%BD%BF%E7%94%A8%E5%8D%95%E4%B8%AACondition%E5%AE%9E%E4%BE%8B%E5%AE%9E%E7%8E%B0%E7%AD%89%E5%BE%85%2F%E9%80%9A%E7%9F%A5%E6%9C%BA%E5%88%B6%EF%BC%9A%0A%3E*%20%E5%BF%85%E9%A1%BB%E6%89%A7%E8%A1%8C%E5%AE%8Csignal%E6%89%80%E5%9C%A8%E7%9A%84try%E8%AF%AD%E5%8F%A5%E5%9D%97%E4%B9%8B%E5%90%8E%E6%89%8D%E9%87%8A%E6%94%BE%E9%94%81%EF%BC%8Ccondition.await()%E5%90%8E%E7%9A%84%E8%AF%AD%E5%8F%A5%E6%89%8D%E8%83%BD%E8%A2%AB%E6%89%A7%E8%A1%8C%E3%80%82%0A%3E*%20%E6%B3%A8%E6%84%8F%EF%BC%9A%C2%A0%E5%BF%85%E9%A1%BB%E5%9C%A8condition.await()%E6%96%B9%E6%B3%95%E8%B0%83%E7%94%A8%E4%B9%8B%E5%89%8D%E8%B0%83%E7%94%A8lock.lock()%E4%BB%A3%E7%A0%81%E8%8E%B7%E5%BE%97%E5%90%8C%E6%AD%A5%E7%9B%91%E8%A7%86%E5%99%A8%EF%BC%8C%E4%B8%8D%E7%84%B6%E4%BC%9A%E6%8A%A5%E9%94%99%E3%80%82%0A%0A2.%20%E4%BD%BF%E7%94%A8%E5%A4%9A%E4%B8%AACondition%E5%AE%9E%E4%BE%8B%E5%AE%9E%E7%8E%B0%E7%AD%89%E5%BE%85%2F%E9%80%9A%E7%9F%A5%E6%9C%BA%E5%88%B6%EF%BC%9A%0A%3E*%20%E5%AE%9E%E7%8E%B0%E2%80%9C%E9%80%89%E6%8B%A9%E6%80%A7%E9%80%9A%E7%9F%A5%E2%80%9D%2C%E5%8F%AA%E4%BC%9A%E5%94%A4%E9%86%92%E6%B3%A8%E5%86%8C%E5%9C%A8%E6%8C%87%E5%AE%9ACondition%E5%AE%9E%E4%BE%8B%E4%B8%AD%E7%9A%84%E6%89%80%E6%9C%89%E7%AD%89%E5%BE%85%E7%BA%BF%E7%A8%8B%0A%0A3.%20%E4%BD%BF%E7%94%A8Condition%E5%AE%9E%E7%8E%B0%E9%A1%BA%E5%BA%8F%E6%89%A7%E8%A1%8C%0A%3E*%20%E5%9C%A8%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%E8%BF%90%E8%A1%8C%E5%AE%8C%E4%B9%8B%E5%90%8E%E9%80%9A%E8%BF%87condition.signal()%2Fcondition.signalAll()%E6%96%B9%E6%B3%95%E9%80%9A%E7%9F%A5%E4%B8%8B%E4%B8%80%E4%B8%AA%E7%89%B9%E5%AE%9A%E7%9A%84%E7%BA%BF%E7%A8%8B%E8%BF%90%E8%A1%8C%EF%BC%8C%E5%B0%B1%E8%BF%99%E6%A0%B7%E5%BE%AA%E7%8E%AF%E5%BE%80%E5%A4%8D%E5%8D%B3%E5%8F%AF%E3%80%82%20%0A%3E*%20%E6%B3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%E6%9D%A5%E7%9A%84%E4%B8%8D%E4%B8%80%E5%AE%9A%E5%85%88%E7%9A%84%E5%88%B0%E9%94%81%EF%BC%8C%E8%BF%99%E6%A0%B7%E5%8F%AF%E8%83%BD%E9%80%A0%E6%88%90%E6%9F%90%E4%BA%9B%E7%BA%BF%E7%A8%8B%E4%B8%80%E7%9B%B4%E6%8B%BF%E4%B8%8D%E5%88%B0%E9%94%81%EF%BC%8C%E7%BB%93%E6%9E%9C%E4%B9%9F%E5%B0%B1%E6%98%AF%E4%B8%8D%E5%85%AC%E5%B9%B3%E7%9A%84%E4%BA%86%E3%80%82%0A%0A%23%23%23%205.%20ReadWriteLock%E6%8E%A5%E5%8F%A3%E7%9A%84%E5%AE%9E%E7%8E%B0%E7%B1%BB%EF%BC%9AReentrantReadWriteLock%0A%0A%23%23%23%23%205.1%20%E7%AE%80%E4%BB%8B%0A%3E*%20ReentrantLock%EF%BC%88%E6%8E%92%E4%BB%96%E9%94%81%EF%BC%89%E5%85%B7%E6%9C%89%E5%AE%8C%E5%85%A8%E4%BA%92%E6%96%A5%E6%8E%92%E4%BB%96%E7%9A%84%E6%95%88%E6%9E%9C%EF%BC%8C%E5%8D%B3%E5%90%8C%E4%B8%80%E6%97%B6%E5%88%BB%E5%8F%AA%E5%85%81%E8%AE%B8%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%E8%AE%BF%E9%97%AE%EF%BC%8C%E8%BF%99%E6%A0%B7%E5%81%9A%E8%99%BD%E7%84%B6%E8%99%BD%E7%84%B6%E4%BF%9D%E8%AF%81%E4%BA%86%E5%AE%9E%E4%BE%8B%E5%8F%98%E9%87%8F%E7%9A%84%E7%BA%BF%E7%A8%8B%E5%AE%89%E5%85%A8%E6%80%A7%EF%BC%8C%E4%BD%86%E6%95%88%E7%8E%87%E9%9D%9E%E5%B8%B8%E4%BD%8E%E4%B8%8B%E3%80%82%0A%3EReadWriteLock%E6%8E%A5%E5%8F%A3%E7%9A%84%E5%AE%9E%E7%8E%B0%E7%B1%BB-ReentrantReadWriteLock%E8%AF%BB%E5%86%99%E9%94%81%E5%B0%B1%E6%98%AF%E4%B8%BA%E4%BA%86%E8%A7%A3%E5%86%B3%E8%BF%99%E4%B8%AA%E9%97%AE%E9%A2%98%E3%80%82%0A%0A%3E*%20%E8%AF%BB%E5%86%99%E9%94%81%E7%BB%B4%E6%8A%A4%E4%BA%86%E4%B8%A4%E4%B8%AA%E9%94%81%EF%BC%8C%E4%B8%80%E4%B8%AA%E6%98%AF**%E8%AF%BB%E6%93%8D%E4%BD%9C**%E7%9B%B8%E5%85%B3%E7%9A%84%E9%94%81%E4%B9%9F%E6%88%90%E4%B8%BA**%E5%85%B1%E4%BA%AB%E9%94%81**%EF%BC%8C%0A%3E%E4%B8%80%E4%B8%AA%E6%98%AF**%E5%86%99%E6%93%8D%E4%BD%9C**%E7%9B%B8%E5%85%B3%E7%9A%84%E9%94%81%E4%B9%9F%E7%A7%B0%E4%B8%BA**%E6%8E%92%E4%BB%96%E9%94%81**%E3%80%82%0A%3E%E9%80%9A%E8%BF%87%E5%88%86%E7%A6%BB%E8%AF%BB%E9%94%81%E5%92%8C%E5%86%99%E9%94%81%EF%BC%8C%E5%85%B6%E5%B9%B6%E5%8F%91%E6%80%A7%E6%AF%94%E4%B8%80%E8%88%AC%E6%8E%92%E4%BB%96%E9%94%81%E6%9C%89%E4%BA%86%E5%BE%88%E5%A4%A7%E6%8F%90%E5%8D%87%E3%80%82%0A%0A%3E*%20%E5%A4%9A%E4%B8%AA%E8%AF%BB%E9%94%81%E4%B9%8B%E9%97%B4%E4%B8%8D%E4%BA%92%E6%96%A5%EF%BC%8C%E8%AF%BB%E9%94%81%E4%B8%8E%E5%86%99%E9%94%81%E4%BA%92%E6%96%A5%EF%BC%8C%E5%86%99%E9%94%81%E4%B8%8E%E5%86%99%E9%94%81%E4%BA%92%E6%96%A5%EF%BC%88%E5%8F%AA%E8%A6%81%E5%87%BA%E7%8E%B0%E5%86%99%E6%93%8D%E4%BD%9C%E7%9A%84%E8%BF%87%E7%A8%8B%E5%B0%B1%E6%98%AF%E4%BA%92%E6%96%A5%E7%9A%84%EF%BC%89%0A%3E%E5%9C%A8%E6%B2%A1%E6%9C%89%E7%BA%BF%E7%A8%8BThread%E8%BF%9B%E8%A1%8C%E5%86%99%E5%85%A5%E6%93%8D%E4%BD%9C%E6%97%B6%EF%BC%8C%E8%BF%9B%E8%A1%8C%E8%AF%BB%E5%8F%96%E6%93%8D%E4%BD%9C%E7%9A%84%E5%A4%9A%E4%B8%AAThread%E9%83%BD%E5%8F%AF%E4%BB%A5%E8%8E%B7%E5%8F%96%E8%AF%BB%E9%94%81%EF%BC%8C%0A%3E%E8%80%8C%E8%BF%9B%E8%A1%8C%E5%86%99%E5%85%A5%E6%93%8D%E4%BD%9C%E7%9A%84Thread%E5%8F%AA%E6%9C%89%E5%9C%A8%E8%8E%B7%E5%8F%96%E5%86%99%E9%94%81%E5%90%8E%E6%89%8D%E8%83%BD%E8%BF%9B%E8%A1%8C%E5%86%99%E5%85%A5%E6%93%8D%E4%BD%9C%E3%80%82%0A%3E%E5%8D%B3%E5%A4%9A%E4%B8%AAThread%E5%8F%AF%E4%BB%A5**%E5%90%8C%E6%97%B6%E8%BF%9B%E8%A1%8C%E8%AF%BB%E5%8F%96%E6%93%8D%E4%BD%9C**%2C%E4%BD%86%E6%98%AF%E5%90%8C%E4%B8%80%E6%97%B6%E5%88%BB**%E5%8F%AA%E5%85%81%E8%AE%B8%E4%B8%80%E4%B8%AAThread%E8%BF%9B%E8%A1%8C%E5%86%99%E5%85%A5%E6%93%8D%E4%BD%9C**%E3%80%82%0A%0A%23%23%23%23%205.2%20ReentrantReadWriteLock%E7%9A%84%E7%89%B9%E6%80%A7%E4%B8%8E%E5%B8%B8%E8%A7%81%E6%96%B9%E6%B3%95%0A%0A%3E*%20ReentrantReadWriteLock%E7%9A%84%E7%89%B9%E6%80%A7%EF%BC%9A%0A%0A%7C%E7%89%B9%E6%80%A7%7C%E8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5%86%99%E9%94%81%E3%80%81%E8%8E%B7%E5%8F%96%E8%AF%BB%E9%94%81%E5%86%8D%E9%87%8A%E6%94%BE%E5%86%99%E9%94%81%E7%9A%84%E6%AC%A1%E5%BA%8F%EF%BC%8C%E5%86%99%E9%94%81%E8%83%BD%E5%A4%9F%E9%99%8D%E7%BA%A7%E7%A7%B0%E4%B8%BA%E8%AF%BB%E9%94%81%0A%0A%3E*%20ReentrantReadWriteLock%E5%B8%B8%E8%A7%81%E6%96%B9%E6%B3%95%EF%BC%9A%0A%3E%C2%A0%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95%0A%0A%E6%96%B9%E6%B3%95%E5%90%8D%E7%A7%B0%7C%09%E6%8F%8F%E8%BF%B0%0A%7C%20---%20%7C%20---%20%7C%0AReentrantReadWriteLock()%09%7C%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%20ReentrantReadWriteLock()%E7%9A%84%E5%AE%9E%E4%BE%8B%0AReentrantReadWriteLock(boolean%20fair)%09%7C%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E7%89%B9%E5%AE%9A%E9%94%81%E7%B1%BB%E5%9E%8B%EF%BC%88%E5%85%AC%E5%B9%B3%E9%94%81%2F%E9%9D%9E%E5%85%AC%E5%B9%B3%E9%94%81%EF%BC%89%E7%9A%84ReentrantReadWriteLock%E7%9A%84%E5%AE%9E%E4%BE%8B%0A%0A%3E%E5%B8%B8%E8%A7%81%E6%96%B9%E6%B3%95%EF%BC%9A%C2%A0%0A%E5%92%8CReentrantLock%E7%B1%BB%20%E7%B1%BB%E4%BC%BC%0A%0A%23%23%23%23%205.3%20ReentrantReadWriteLock%E7%9A%84%E4%BD%BF%E7%94%A8%0A1.%20%E8%AF%BB%E8%AF%BB%E5%85%B1%E4%BA%AB%0A%20%20%20%20%3E%E4%B8%A4%E4%B8%AA%E7%BA%BF%E7%A8%8B%E5%90%8C%E6%97%B6%E8%BF%90%E8%A1%8Cread%E6%96%B9%E6%B3%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%AF%B9%E8%B1%A1%E5%AE%9E%E4%BE%8B%E7%9A%84%E7%BA%BF%E7%A8%8Ba%2Cb%EF%BC%8C%E7%BA%BF%E7%A8%8Ba%E6%89%A7%E8%A1%8C%E4%B8%8A%E9%9D%A2%E7%9A%84read%E6%96%B9%E6%B3%95%EF%BC%8C%E7%BA%BF%E7%A8%8Bb%E6%89%A7%E8%A1%8C%E4%B8%8A%E9%9D%A2%E7%9A%84write%E6%96%B9%E6%B3%95%E3%80%82%E4%BD%A0%E4%BC%9A%E5%8F%91%E7%8E%B0%E5%90%8C%E4%B8%80%E6%97%B6%E9%97%B4%E5%8F%AA%E5%85%81%E8%AE%B8%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%E6%89%A7%E8%A1%8Clock()%E6%96%B9%E6%B3%95%E5%90%8E%E9%9D%A2%E7%9A%84%E4%BB%A3%E7%A0%81%E3%80%82%0A%20%20%20%20%3E*%20%E8%AE%B0%E4%BD%8F%EF%BC%9A%E5%8F%AA%E8%A6%81%E5%87%BA%E7%8E%B0%E5%86%99%E6%93%8D%E4%BD%9C%E7%9A%84%E8%BF%87%E7%A8%8B%E5%B0%B1%E6%98%AF%E4%BA%92%E6%96%A5%E7%9A%84%E3%80%82%0A&lt;/center&gt;&lt;/div&gt;
</content>
  </entry>
  <entry xml:base="http://linzhiteng.postach.io/feed.xml">
    <title type="text">二. 线程安全</title>
    <id>https://linzhiteng.postach.io/post/er-xian-cheng-an-quan</id>
    <updated>2019-06-09T13:07:51.586000Z</updated>
    <published>2019-03-12T09:48:48Z</published>
    <link href="https://linzhiteng.postach.io/post/er-xian-cheng-an-quan" />
    <author>
      <name>linzhi teng</name>
    </author>
    <category term="xian-cheng" />
    <content type="html">&lt;div&gt;&lt;div style=&quot;font-size: 14px; margin: 0; padding: 0; width: 100%;&quot;&gt;&lt;div style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;二. 线程安全
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;0. 锁
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;0.1 为什么需要锁（并发控制）？
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;0.2 并发控制机制（锁）
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;0.3 两种锁的使用场景
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;0.4 乐观锁的缺点
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;0.5 乐观锁与悲观锁详解
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1. synchronized关键字(1)
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.1 变量安全性
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.2 多个对象对个锁
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.3 synchronized方法与锁对象
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.4 脏读
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.5 synchronized锁重入
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.6  同步不具有继承性
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2. synchronized关键字（2）
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.1 synchronized方法的缺点
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.2 synchronized（this）同步代码块的使用
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.3 synchronized（object）代码块间使用
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.4 synchronized代码块间的同步性
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.5 静态同步synchronized方法与synchronized(class)代码块
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3. volatile关键字
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1 volatile关键字简介
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.2 volatile关键字的可见性
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.3 synchronized关键字和volatile关键字比较
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4. 等待/通知（wait/notify）机制
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.1 等待/通知机制介绍
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;为什么要使用等待/通知机制？
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;概念
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.2 等待/通知机制的实现
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.3 notify()锁不释放
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;二. 线程安全&lt;/h2&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;0. 锁&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;0.1 为什么需要锁（并发控制）？&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;在多用户环境中，在同一时间可能会有多个用户更新相同的记录，这会产生&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;冲突&lt;/strong&gt;。这就是著名的并发性问题。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0;&quot;&gt;典型的冲突有：&lt;/p&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;丢失更新：一个事务的更新覆盖了其它事务的更新结果，就是所谓的更新丢失。例如：用户A把值从6改为2，用户B把值从2改为6，则用户A丢失了他的更新。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;脏读：当一个事务读取其它完成一半事务的记录时，就会发生脏读取。例如：用户A,B看到的值都是6，用户B把值改为2，用户A读到的值仍为6。&lt;/li&gt;
&lt;/ol&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;为了解决这些并发带来的问题。 我们需要引入并发控制机制。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;0.2 并发控制机制（锁）&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;悲观锁&lt;/li&gt;
&lt;/ul&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;总是假设最坏的情况，每次去拿数据的时候都认为别人会修改，所以每次在拿数据的时候都会上锁，这样别人想拿这个数据就会阻塞直到它拿到锁（共享资源每次只给一个线程使用，其它线程阻塞，用完后再把资源转让给其它线程）。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;传统的关系型数据库里边就用到了很多这种锁机制，比如行锁，表锁等，读锁，写锁等，都是在做操作之前先上锁。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;Java中synchronized和ReentrantLock等独占锁就是悲观锁思想的实现。&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;乐观锁&lt;/li&gt;
&lt;/ul&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;总是假设最好的情况，每次去拿数据的时候都认为别人不会修改，所以不会上锁，但是在更新的时候会判断一下在此期间别人有没有去更新这个数据，可以使用版本号机制和CAS算法实现。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;乐观锁适用于多读的应用类型，这样可以提高吞吐量，像数据库提供的类似于write_condition机制，其实都是提供的乐观锁。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;在Java中java.util.concurrent.atomic包下面的原子变量类就是使用了乐观锁的一种实现方式CAS实现的。&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;0.3 两种锁的使用场景&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;乐观锁适用于写比较少的情况下（多读场景），即冲突真的很少发生的时候，这样可以省去了锁的开销，加大了系统的整个吞吐量。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;但如果是多写的情况，一般会经常产生冲突，这就会导致上层应用会不断的进行retry，这样反倒是降低了性能，所以一般多写的场景下用悲观锁就比较合适。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;0.4 乐观锁的缺点&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;ABA 问题&lt;/strong&gt;&lt;br/&gt;
如果一个变量V初次读取的时候是A值，并且在准备赋值的时候检查到它仍然是A值，那我们就能说明它的值没有被其他线程修改过了吗？很明显是不能的，因为在这段时间它的值可能被改为其他值，然后又改回A，那CAS操作就会误认为它从来没有被修改过。这个问题被称为CAS操作的 &quot;ABA&quot;问题。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;循环时间长开销大&lt;/strong&gt;&lt;br/&gt;
自旋CAS（也就是不成功就一直循环执行直到成功）如果长时间不成功，会给CPU带来非常大的执行开销。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;只能保证一个共享变量的原子操作&lt;/strong&gt;&lt;br/&gt;
CAS 只对单个共享变量有效，当操作涉及跨多个共享变量时 CAS 无效。&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;0.5 乐观锁与悲观锁详解&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;a href=&quot;https://blog.csdn.net/qq_34337272/article/details/81072874&quot; style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;乐观锁与悲观锁详解&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;hr style=&quot;line-height: 160%; box-sizing: content-box; border-top: 1px solid #eee; margin: 16px 0;&quot;/&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;1. synchronized关键字(1)&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/c7b52098-298e-4410-a86c-ee341fa8c8f8/f3caced3-6343-4fca-a1d3-626a81bbe709.jpg&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;a href=&quot;https://blog.csdn.net/qq_34337272/article/details/79655194&quot; style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;synchronized关键字1&lt;/a&gt;&lt;/p&gt;
&lt;hr style=&quot;line-height: 160%; box-sizing: content-box; border-top: 1px solid #eee; margin: 16px 0;&quot;/&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;synchronized&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;synchronized关键字解决的是多个线程之间访问资源的同步性，synchronized关键字可以保证被它修饰的方法或者代码块在任意时刻只能有一个线程执行。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;Java并发编程这个领域中synchronized关键字一直都是元老级的角色，很久之前很多人都会称它为 &quot;重量级锁&quot; 。&lt;br/&gt;
但是，在JavaSE 1.6之后进行了主要包括为了减少获得锁和释放锁带来的性能消耗而引入的 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;偏向锁&lt;/strong&gt;和 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;轻量级锁&lt;/strong&gt; 以及其它各种优化之后变得在某些情况下并不是那么重了。synchronized的底层实现主要依靠 Lock-Free 的队列，基本思路是 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;自旋后阻塞&lt;/strong&gt;，&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;竞争切换后继续竞争锁&lt;/strong&gt;，稍微牺牲了公平性，但获得了高吞吐量。在线程冲突较少的情况下，可以获得和CAS类似的性能；而线程冲突严重的情况下，性能远高于CAS。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.1 变量安全性&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&quot;非线程安全&quot;(线程不安全) 问题存在于&quot;实例变量&quot;中，如果是方法内部的私有变量，则不存在&quot;非线程安全&quot;，所得结果也就是&quot;线程安全&quot;的了。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;如果两个线程同时操作对象中的实例变量，则会出现&quot;&lt;u style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;非线程安全&lt;/u&gt;&quot;，解决办法就是在方法前加上&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;synchronized&lt;/strong&gt;关键字即可。&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.2 多个对象对个锁&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;synchronized取得的锁都是&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;对象锁&lt;/strong&gt;，而不是把一段代码或方法当做锁。所以在上面的实例中，哪个线程先执行带synchronized关键字的方法，则哪个线程就持有该方法所属对象的锁Lock，那么其他线程只能呈等待状态，前提是多个线程访问的是&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;同一个对象&lt;/strong&gt;。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.3 synchronized方法与锁对象&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;synchronized取得的锁都是对象锁，而不是把一段代码或方法当做锁。如果多个线程访问的是同一个对象，哪个线程先执行带synchronized关键字的方法，则哪个线程就持有该方法，那么其他线程只能呈等待状态。&lt;br/&gt;
如果多个线程访问的是多个对象则不一定，因为多个对象会产生多个锁。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.4 脏读&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;发生脏读的情况是在读取实例变量时，此值已经被其他线程更改过。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;代码没有做同步，虽然set方法同步，但是由于get方法一般都会忘了，导致读的值是被写过的&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.5 synchronized锁重入&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;可重入锁&quot;概念是：自己可以再次获取自己的内部锁。比如一个线程获得了某个对象的锁，此时这个对象锁还没有释放，当其再次想要获取这个对象的锁的时候还是可以获取的，如果不可锁重入的话，就会造成死锁。&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.6  同步不具有继承性&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;如果父类有一个带synchronized关键字的方法，子类继承并重写了这个方法。 但是同步不能继承，所以还是需要在子类方法中添加synchronized关键字。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;2. synchronized关键字（2）&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/c7b52098-298e-4410-a86c-ee341fa8c8f8/33d6223f-fd83-4816-a981-15fb5ac7e5bc.jpg&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;a href=&quot;https://blog.csdn.net/qq_34337272/article/details/79670775&quot; style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;synchronized关键字2&lt;/a&gt;&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.1 synchronized方法的缺点&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;使用synchronized关键字声明方法有些时候是有很大的弊端的，比如我们有两个线程一个线程A调用同步方法后获得锁，那么另一个线程B就需要等待A执行完，但是如果说A执行的是一个很费时间的任务的话这样就会很耗时。&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;可以使用&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;synchronized同步块&lt;/strong&gt;来解决这个问题。但是要注意synchronized同步块的使用方式，如果synchronized同步块使用不好的话并不会带来效率的提升。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.2 synchronized（this）同步代码块的使用&lt;/h4&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;Task&lt;/span&gt; &lt;/span&gt;{

    &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;private&lt;/span&gt; String getData1;
    &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;private&lt;/span&gt; String getData2;

    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;doLongTimeTask&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;try&lt;/span&gt; {
            System.out.println(&lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;begin task&quot;&lt;/span&gt;);
            Thread.sleep(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;3000&lt;/span&gt;);

            String privateGetData1 = &lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;长时间处理任务后从远程返回的值1 threadName=&quot;&lt;/span&gt;
                    + Thread.currentThread().getName();
            String privateGetData2 = &lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;长时间处理任务后从远程返回的值2 threadName=&quot;&lt;/span&gt;
                    + Thread.currentThread().getName();

            &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;synchronized&lt;/span&gt; (&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;this&lt;/span&gt;) {
                getData1 = privateGetData1;
                getData2 = privateGetData2;
            }

            System.out.println(getData1);
            System.out.println(getData2);
            System.out.println(&lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;end task&quot;&lt;/span&gt;);
        } &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;catch&lt;/span&gt; (InterruptedException e) {
            &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;// TODO Auto-generated catch block&lt;/span&gt;
            e.printStackTrace();
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;当一个线程访问一个对象的synchronized同步代码块时，另一个线程任然可以访问该对象非synchronized同步代码块。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;不在synchronized代码块中就异步执行，在synchronized代码块中就是同步执行。&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.3 synchronized（object）代码块间使用&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;两个线程使用了同一个&quot;对象监视器&quot;,所以运行结果是同步的。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;两个线程使用了不同的&quot;对象监视器&quot;,所以运行结果不是同步的了。&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.4 synchronized代码块间的同步性&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;当一个对象访问synchronized(this)代码块时，其他线程对同一个对象中所有其他synchronized(this)代码块代码块的访问将被阻塞，这说明synchronized(this)代码块使用的&quot;对象监视器&quot;是同一个。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;和synchronized方法一样，synchronized(this)代码块也是锁定当前对象。&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;其他线程执行对象中synchronized同步方法和synchronized(this)代码块时呈现同步效果;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;如果两个线程使用了同一个&quot;对象监视器&quot;,运行结果同步，否则不同步.&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.5 静态同步synchronized方法与synchronized(class)代码块&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;synchronized关键字加到static静态方法和synchronized(class)代码块上都是是&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;给Class类上锁&lt;/strong&gt;，而synchronized关键字加到&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;非静态方法&lt;/strong&gt;上是给&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;对象上锁&lt;/strong&gt;。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;静态同步synchronized方法与synchronized(class)代码块持有的锁一样，都是Class锁，Class锁对对象的所有实例起作用。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;3. volatile关键字&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/c7b52098-298e-4410-a86c-ee341fa8c8f8/bdd036cc-35ff-41a2-b885-ab4afa30cc00.jpg&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;a href=&quot;https://blog.csdn.net/qq_34337272/article/details/79680771&quot; style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;volatile关键字&lt;/a&gt;&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.1 volatile关键字简介&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;volatile关键字可以用来提醒编译器它后面所定义的变量随时有可能改变，因此编译后的程序每次需要存储或读取这个变量的时候，都会直接从变量地址中读取数。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;如果没有volatile关键字，则编译器可能优化读取和存储，可能暂时使用寄存器中的值，如果这个变量由别的程序更新了的话，将出现不一致的现象。&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.2 volatile关键字的可见性&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;volatile 修饰的成员变量在每次被线程访问时，都强迫从主存（共享内存）中重读该成员变量的值。而且，当成员变量发生变化时，强迫线程将变化值回写到主存（共享内存）。这样在任何时刻，两个不同的线程总是看到某个成员变量的同一个值，这样也就保证了同步数据的可见性。&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/c7b52098-298e-4410-a86c-ee341fa8c8f8/1e03da94-d38e-413a-8536-4721d3782bac.jpg&quot; /&gt;&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/c7b52098-298e-4410-a86c-ee341fa8c8f8/0953b2ed-af8a-41fd-9d83-798785655774.jpg&quot; /&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.3 synchronized关键字和volatile关键字比较&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;volatile关键字是&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;线程同步的轻量级实现&lt;/strong&gt;，所以volatile性能肯定比synchronized关键字要好。但是&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;volatile关键字只能用于变量&lt;/strong&gt;而synchronized关键字可以修饰方法以及代码块。synchronized关键字在JavaSE1.6之后进行了主要包括为了减少获得锁和释放锁带来的性能消耗而引入的偏向锁和轻量级锁以及其它各种优化之后执行效率有了显著提升，实际开发中使用synchronized关键字还是更多一些。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;多线程访问volatile关键字不会发生阻塞，而synchronized关键字可能会发生阻塞&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;volatile关键字能保证数据的可见性，但不能保证数据的原子性。synchronized关键字两者都能保证。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;volatile关键字用于解决变量在多个线程之间的可见性，而ynchronized关键字解决的是多个线程之间访问资源的同步性。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;4. 等待/通知（wait/notify）机制&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;4.1 等待/通知机制介绍&lt;/h4&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;为什么要使用等待/通知机制？&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;当两个线程之间存在生产和消费者关系，也就是说第一个线程（生产者）做相应的操作然后第二个线程（消费者）感知到了变化又进行相应的操作。&lt;br/&gt;
第二个语句不停过通过轮询机制来检测判断条件是否成立。如果轮询时间的间隔太小会浪费CPU资源，轮询时间的间隔太大，就可能取不到自己想要的数据。所以这里就需要我们今天讲到的等待/通知（wait/notify）机制来解决这两个矛盾。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;概念&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;等待/通知机制，是指一个线程A调用了对象O的wait()方法进入等待状态，而另一个线程B调用了对象O的notify()/notifyAll()方法，线程A收到通知后退出等待队列，进入可运行状态，进而执行后续操作。上诉两个线程通过对象O来完成交互，而对象上的wait()方法和notify()/notifyAll()方法的关系就如同开关信号一样，用来完成等待方和通知方之间的交互工作。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;4.2 等待/通知机制的实现&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;notify()执行后并不会立即释放锁&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;synchronized关键字可以将任何一个Object对象作为同步对象来看待，而Java为每个Object都实现了等待/通知（wait/notify）机制的相关方法，它们必须用在synchronized关键字同步的Object的临界区内。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;通过调用wait()方法可以使处于临界区内的线程进入等待状态，同时释放被同步对象的锁。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;而notify()方法可以唤醒一个因调用wait操作而处于阻塞状态中的线程，使其进入就绪状态。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;被重新唤醒的线程会试图重新获得临界区的控制权也就是锁，并继续执行wait方法之后的代码。&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;4.3 notify()锁不释放&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;当方法wait()被执行后，锁自动被释放，但执行完notify()方法后，锁不会自动释放。必须&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;执行完notify()方法所在的synchronized代码块后&lt;/strong&gt;才释放。&lt;/p&gt;
&lt;/div&gt;&lt;center style=&quot;display:none !important;visibility:collapse !important;height:0 !important;white-space:nowrap;width:100%;overflow:hidden&quot;&gt;%5Btoc%5D%0A%23%23%20%E4%BA%8C.%20%E7%BA%BF%E7%A8%8B%E5%AE%89%E5%85%A8%0A%0A%23%23%23%200.%20%E9%94%81%0A%23%23%23%23%200.1%20%E4%B8%BA%E4%BB%80%E4%B9%88%E9%9C%80%E8%A6%81%E9%94%81%EF%BC%88%E5%B9%B6%E5%8F%91%E6%8E%A7%E5%88%B6%EF%BC%89%EF%BC%9F%0A%3E%E5%9C%A8%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%0A%3E2.%20%E4%B9%90%E8%A7%82%E9%94%81%E9%80%82%E7%94%A8%E4%BA%8E%E5%A4%9A%E8%AF%BB%E7%9A%84%E5%BA%94%E7%94%A8%E7%B1%BB%E5%9E%8B%EF%BC%8C%E8%BF%99%E6%A0%B7%E5%8F%AF%E4%BB%A5%E6%8F%90%E9%AB%98%E5%90%9E%E5%90%90%E9%87%8F%EF%BC%8C%E5%83%8F%E6%95%B0%E6%8D%AE%E5%BA%93%E6%8F%90%E4%BE%9B%E7%9A%84%E7%B1%BB%E4%BC%BC%E4%BA%8Ewrite_condition%E6%9C%BA%E5%88%B6%EF%BC%8C%E5%85%B6%E5%AE%9E%E9%83%BD%E6%98%AF%E6%8F%90%E4%BE%9B%E7%9A%84%E4%B9%90%E8%A7%82%E9%94%81%E3%80%82%0A%3E3.%20%E5%9C%A8Java%E4%B8%ADjava.util.concurrent.atomic%E5%8C%85%E4%B8%8B%E9%9D%A2%E7%9A%84%E5%8E%9F%E5%AD%90%E5%8F%98%E9%87%8F%E7%B1%BB%E5%B0%B1%E6%98%AF%E4%BD%BF%E7%94%A8%E4%BA%86%E4%B9%90%E8%A7%82%E9%94%81%E7%9A%84%E4%B8%80%E7%A7%8D%E5%AE%9E%E7%8E%B0%E6%96%B9%E5%BC%8FCAS%E5%AE%9E%E7%8E%B0%E7%9A%84%E3%80%82%0A%0A%23%23%23%23%200.3%20%E4%B8%A4%E7%A7%8D%E9%94%81%E7%9A%84%E4%BD%BF%E7%94%A8%E5%9C%BA%E6%99%AF%0A%3E*%20%E4%B9%90%E8%A7%82%E9%94%81%E9%80%82%E7%94%A8%E4%BA%8E%E5%86%99%E6%AF%94%E8%BE%83%E5%B0%91%E7%9A%84%E6%83%85%E5%86%B5%E4%B8%8B%EF%BC%88%E5%A4%9A%E8%AF%BB%E5%9C%BA%E6%99%AF%EF%BC%89%EF%BC%8C%E5%8D%B3%E5%86%B2%E7%AA%81%E7%9C%9F%E7%9A%84%E5%BE%88%E5%B0%91%E5%8F%91%E7%94%9F%E7%9A%84%E6%97%B6%E5%80%99%EF%BC%8C%E8%BF%99%E6%A0%B7%E5%8F%AF%E4%BB%A5%E7%9C%81%E5%8E%BB%E4%BA%86%E9%94%81%E7%9A%84%E5%BC%80%E9%94%80%EF%BC%8C%E5%8A%A0%E5%A4%A7%E4%BA%86%E7%B3%BB%E7%BB%9F%E7%9A%84%E6%95%B4%E4%B8%AA%E5%90%9E%E5%90%90%E9%87%8F%E3%80%82%0A%3E*%20%E4%BD%86%E5%A6%82%E6%9E%9C%E6%98%AF%E5%A4%9A%E5%86%99%E7%9A%84%E6%83%85%E5%86%B5%EF%BC%8C%E4%B8%80%E8%88%AC%E4%BC%9A%E7%BB%8F%E5%B8%B8%E4%BA%A7%E7%94%9F%E5%86%B2%E7%AA%81%EF%BC%8C%E8%BF%99%E5%B0%B1%E4%BC%9A%E5%AF%BC%E8%87%B4%E4%B8%8A%E5%B1%82%E5%BA%94%E7%94%A8%E4%BC%9A%E4%B8%8D%E6%96%AD%E7%9A%84%E8%BF%9B%E8%A1%8Cretry%EF%BC%8C%E8%BF%99%E6%A0%B7%E5%8F%8D%E5%80%92%E6%98%AF%E9%99%8D%E4%BD%8E%E4%BA%86%E6%80%A7%E8%83%BD%EF%BC%8C%E6%89%80%E4%BB%A5%E4%B8%80%E8%88%AC%E5%A4%9A%E5%86%99%E7%9A%84%E5%9C%BA%E6%99%AF%E4%B8%8B%E7%94%A8%E6%82%B2%E8%A7%82%E9%94%81%E5%B0%B1%E6%AF%94%E8%BE%83%E5%90%88%E9%80%82%E3%80%82%0A%0A%23%23%23%23%200.4%20%E4%B9%90%E8%A7%82%E9%94%81%E7%9A%84%E7%BC%BA%E7%82%B9%0A%3E1.%20**ABA%20%E9%97%AE%E9%A2%98**%0A%3E%E5%A6%82%E6%9E%9C%E4%B8%80%E4%B8%AA%E5%8F%98%E9%87%8FV%E5%88%9D%E6%AC%A1%E8%AF%BB%E5%8F%96%E7%9A%84%E6%97%B6%E5%80%99%E6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CAS%EF%BC%88%E4%B9%9F%E5%B0%B1%E6%98%AF%E4%B8%8D%E6%88%90%E5%8A%9F%E5%B0%B1%E4%B8%80%E7%9B%B4%E5%BE%AA%E7%8E%AF%E6%89%A7%E8%A1%8C%E7%9B%B4%E5%88%B0%E6%88%90%E5%8A%9F%EF%BC%89%E5%A6%82%E6%9E%9C%E9%95%BF%E6%97%B6%E9%97%B4%E4%B8%8D%E6%88%90%E5%8A%9F%EF%BC%8C%E4%BC%9A%E7%BB%99CPU%E5%B8%A6%E6%9D%A5%E9%9D%9E%E5%B8%B8%E5%A4%A7%E7%9A%84%E6%89%A7%E8%A1%8C%E5%BC%80%E9%94%80%E3%80%82%0A%3E3.%20**%E5%8F%AA%E8%83%BD%E4%BF%9D%E8%AF%81%E4%B8%80%E4%B8%AA%E5%85%B1%E4%BA%AB%E5%8F%98%E9%87%8F%E7%9A%84%E5%8E%9F%E5%AD%90%E6%93%8D%E4%BD%9C**%0A%3ECAS%20%E5%8F%AA%E5%AF%B9%E5%8D%95%E4%B8%AA%E5%85%B1%E4%BA%AB%E5%8F%98%E9%87%8F%E6%9C%89%E6%95%88%EF%BC%8C%E5%BD%93%E6%93%8D%E4%BD%9C%E6%B6%89%E5%8F%8A%E8%B7%A8%E5%A4%9A%E4%B8%AA%E5%85%B1%E4%BA%AB%E5%8F%98%E9%87%8F%E6%97%B6%20CAS%20%E6%97%A0%E6%95%88%E3%80%82%0A%0A%23%23%23%23%200.5%20%E4%B9%90%E8%A7%82%E9%94%81%E4%B8%8E%E6%82%B2%E8%A7%82%E9%94%81%E8%AF%A6%E8%A7%A3%0A%3E%5B%E4%B9%90%E8%A7%82%E9%94%81%E4%B8%8E%E6%82%B2%E8%A7%82%E9%94%81%E8%AF%A6%E8%A7%A3%5D(https%3A%2F%2Fblog.csdn.net%2Fqq_34337272%2Farticle%2Fdetails%2F81072874)%0A%0A---%0A%23%23%23%201.%20synchronized%E5%85%B3%E9%94%AE%E5%AD%97(1)%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/c7b52098-298e-4410-a86c-ee341fa8c8f8/f3caced3-6343-4fca-a1d3-626a81bbe709.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F1043%3A1)%0A%5Bsynchronized%E5%85%B3%E9%94%AE%E5%AD%971%5D(https%3A%2F%2Fblog.csdn.net%2Fqq_34337272%2Farticle%2Fdetails%2F79655194)%0A-%20-%20-%0A*%20synchronized%0A%3Esynchronized%E5%85%B3%E9%94%AE%E5%AD%97%E8%A7%A3%E5%86%B3%E7%9A%84%E6%98%AF%E5%A4%9A%E4%B8%AA%E7%BA%BF%E7%A8%8B%E4%B9%8B%E9%97%B4%E8%AE%BF%E9%97%AE%E8%B5%84%E6%BA%90%E7%9A%84%E5%90%8C%E6%AD%A5%E6%80%A7%EF%BC%8Csynchronized%E5%85%B3%E9%94%AE%E5%AD%97%E5%8F%AF%E4%BB%A5%E4%BF%9D%E8%AF%81%E8%A2%AB%E5%AE%83%E4%BF%AE%E9%A5%B0%E7%9A%84%E6%96%B9%E6%B3%95%E6%88%96%E8%80%85%E4%BB%A3%E7%A0%81%E5%9D%97%E5%9C%A8%E4%BB%BB%E6%84%8F%E6%97%B6%E5%88%BB%E5%8F%AA%E8%83%BD%E6%9C%89%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%E6%89%A7%E8%A1%8C%E3%80%82%0A%0A%3EJava%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B%E8%BF%99%E4%B8%AA%E9%A2%86%E5%9F%9F%E4%B8%ADsynchronized%E5%85%B3%E9%94%AE%E5%AD%97%E4%B8%80%E7%9B%B4%E9%83%BD%E6%98%AF%E5%85%83%E8%80%81%E7%BA%A7%E7%9A%84%E8%A7%92%E8%89%B2%EF%BC%8C%E5%BE%88%E4%B9%85%E4%B9%8B%E5%89%8D%E5%BE%88%E5%A4%9A%E4%BA%BA%E9%83%BD%E4%BC%9A%E7%A7%B0%E5%AE%83%E4%B8%BA%20%E2%80%9C%E9%87%8D%E9%87%8F%E7%BA%A7%E9%94%81%E2%80%9D%20%E3%80%82%0A%3E%E4%BD%86%E6%98%AF%EF%BC%8C%E5%9C%A8JavaSE%201.6%E4%B9%8B%E5%90%8E%E8%BF%9B%E8%A1%8C%E4%BA%86%E4%B8%BB%E8%A6%81%E5%8C%85%E6%8B%AC%E4%B8%BA%E4%BA%86%E5%87%8F%E5%B0%91%E8%8E%B7%E5%BE%97%E9%94%81%E5%92%8C%E9%87%8A%E6%94%BE%E9%94%81%E5%B8%A6%E6%9D%A5%E7%9A%84%E6%80%A7%E8%83%BD%E6%B6%88%E8%80%97%E8%80%8C%E5%BC%95%E5%85%A5%E7%9A%84%20**%E5%81%8F%E5%90%91%E9%94%81**%E5%92%8C%20**%E8%BD%BB%E9%87%8F%E7%BA%A7%E9%94%81**%20%E4%BB%A5%E5%8F%8A%E5%85%B6%E5%AE%83%E5%90%84%E7%A7%8D%E4%BC%98%E5%8C%96%E4%B9%8B%E5%90%8E%E5%8F%98%E5%BE%97%E5%9C%A8%E6%9F%90%E4%BA%9B%E6%83%85%E5%86%B5%E4%B8%8B%E5%B9%B6%E4%B8%8D%E6%98%AF%E9%82%A3%E4%B9%88%E9%87%8D%E4%BA%86%E3%80%82synchronized%E7%9A%84%E5%BA%95%E5%B1%82%E5%AE%9E%E7%8E%B0%E4%B8%BB%E8%A6%81%E4%BE%9D%E9%9D%A0%20Lock-Free%20%E7%9A%84%E9%98%9F%E5%88%97%EF%BC%8C%E5%9F%BA%E6%9C%AC%E6%80%9D%E8%B7%AF%E6%98%AF%20**%E8%87%AA%E6%97%8B%E5%90%8E%E9%98%BB%E5%A1%9E**%EF%BC%8C**%E7%AB%9E%E4%BA%89%E5%88%87%E6%8D%A2%E5%90%8E%E7%BB%A7%E7%BB%AD%E7%AB%9E%E4%BA%89%E9%94%81**%EF%BC%8C%E7%A8%8D%E5%BE%AE%E7%89%BA%E7%89%B2%E4%BA%86%E5%85%AC%E5%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89%E5%85%A8%E2%80%9D%E7%9A%84%E4%BA%86%E3%80%82%0A*%20%E5%A6%82%E6%9E%9C%E4%B8%A4%E4%B8%AA%E7%BA%BF%E7%A8%8B%E5%90%8C%E6%97%B6%E6%93%8D%E4%BD%9C%E5%AF%B9%E8%B1%A1%E4%B8%AD%E7%9A%84%E5%AE%9E%E4%BE%8B%E5%8F%98%E9%87%8F%EF%BC%8C%E5%88%99%E4%BC%9A%E5%87%BA%E7%8E%B0%E2%80%9C%3Cu%3E%E9%9D%9E%E7%BA%BF%E7%A8%8B%E5%AE%89%E5%85%A8%3C%2Fu%3E%E2%80%9D%EF%BC%8C%E8%A7%A3%E5%86%B3%E5%8A%9E%E6%B3%95%E5%B0%B1%E6%98%AF%E5%9C%A8%E6%96%B9%E6%B3%95%E5%89%8D%E5%8A%A0%E4%B8%8A**synchronized**%E5%85%B3%E9%94%AE%E5%AD%97%E5%8D%B3%E5%8F%AF%E3%80%82%0A%23%23%23%23%201.2%20%E5%A4%9A%E4%B8%AA%E5%AF%B9%E8%B1%A1%E5%AF%B9%E4%B8%AA%E9%94%81%0A%3Esynchronized%E5%8F%96%E5%BE%97%E7%9A%84%E9%94%81%E9%83%BD%E6%98%AF**%E5%AF%B9%E8%B1%A1%E9%94%81**%EF%BC%8C%E8%80%8C%E4%B8%8D%E6%98%AF%E6%8A%8A%E4%B8%80%E6%AE%B5%E4%BB%A3%E7%A0%81%E6%88%96%E6%96%B9%E6%B3%95%E5%BD%93%E5%81%9A%E9%94%81%E3%80%82%E6%89%80%E4%BB%A5%E5%9C%A8%E4%B8%8A%E9%9D%A2%E7%9A%84%E5%AE%9E%E4%BE%8B%E4%B8%AD%EF%BC%8C%E5%93%AA%E4%B8%AA%E7%BA%BF%E7%A8%8B%E5%85%88%E6%89%A7%E8%A1%8C%E5%B8%A6synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E7%9A%84%E6%96%B9%E6%B3%95%EF%BC%8C%E5%88%99%E5%93%AA%E4%B8%AA%E7%BA%BF%E7%A8%8B%E5%B0%B1%E6%8C%81%E6%9C%89%E8%AF%A5%E6%96%B9%E6%B3%95%E6%89%80%E5%B1%9E%E5%AF%B9%E8%B1%A1%E7%9A%84%E9%94%81Lock%EF%BC%8C%E9%82%A3%E4%B9%88%E5%85%B6%E4%BB%96%E7%BA%BF%E7%A8%8B%E5%8F%AA%E8%83%BD%E5%91%88%E7%AD%89%E5%BE%85%E7%8A%B6%E6%80%81%EF%BC%8C%E5%89%8D%E6%8F%90%E6%98%AF%E5%A4%9A%E4%B8%AA%E7%BA%BF%E7%A8%8B%E8%AE%BF%E9%97%AE%E7%9A%84%E6%98%AF**%E5%90%8C%E4%B8%80%E4%B8%AA%E5%AF%B9%E8%B1%A1**%E3%80%82%0A%0A%23%23%23%23%201.3%20synchronized%E6%96%B9%E6%B3%95%E4%B8%8E%E9%94%81%E5%AF%B9%E8%B1%A1%0A%3Esynchronized%E5%8F%96%E5%BE%97%E7%9A%84%E9%94%81%E9%83%BD%E6%98%AF%E5%AF%B9%E8%B1%A1%E9%94%81%EF%BC%8C%E8%80%8C%E4%B8%8D%E6%98%AF%E6%8A%8A%E4%B8%80%E6%AE%B5%E4%BB%A3%E7%A0%81%E6%88%96%E6%96%B9%E6%B3%95%E5%BD%93%E5%81%9A%E9%94%81%E3%80%82%E5%A6%82%E6%9E%9C%E5%A4%9A%E4%B8%AA%E7%BA%BF%E7%A8%8B%E8%AE%BF%E9%97%AE%E7%9A%84%E6%98%AF%E5%90%8C%E4%B8%80%E4%B8%AA%E5%AF%B9%E8%B1%A1%EF%BC%8C%E5%93%AA%E4%B8%AA%E7%BA%BF%E7%A8%8B%E5%85%88%E6%89%A7%E8%A1%8C%E5%B8%A6synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E7%9A%84%E6%96%B9%E6%B3%95%EF%BC%8C%E5%88%99%E5%93%AA%E4%B8%AA%E7%BA%BF%E7%A8%8B%E5%B0%B1%E6%8C%81%E6%9C%89%E8%AF%A5%E6%96%B9%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F%87%E7%9A%84%0A%0A%23%23%23%23%201.5%20synchronized%E9%94%81%E9%87%8D%E5%85%A5%0A*%20%E5%8F%AF%E9%87%8D%E5%85%A5%E9%94%81%E2%80%9D%E6%A6%82%E5%BF%B5%E6%98%AF%EF%BC%9A%E8%87%AA%E5%B7%B1%E5%8F%AF%E4%BB%A5%E5%86%8D%E6%AC%A1%E8%8E%B7%E5%8F%96%E8%87%AA%E5%B7%B1%E7%9A%84%E5%86%85%E9%83%A8%E9%94%81%E3%80%82%E6%AF%94%E5%A6%82%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%E8%8E%B7%E5%BE%97%E4%BA%86%E6%9F%90%E4%B8%AA%E5%AF%B9%E8%B1%A1%E7%9A%84%E9%94%81%EF%BC%8C%E6%AD%A4%E6%97%B6%E8%BF%99%E4%B8%AA%E5%AF%B9%E8%B1%A1%E9%94%81%E8%BF%98%E6%B2%A1%E6%9C%89%E9%87%8A%E6%94%BE%EF%BC%8C%E5%BD%93%E5%85%B6%E5%86%8D%E6%AC%A1%E6%83%B3%E8%A6%81%E8%8E%B7%E5%8F%96%E8%BF%99%E4%B8%AA%E5%AF%B9%E8%B1%A1%E7%9A%84%E9%94%81%E7%9A%84%E6%97%B6%E5%80%99%E8%BF%98%E6%98%AF%E5%8F%AF%E4%BB%A5%E8%8E%B7%E5%8F%96%E7%9A%84%EF%BC%8C%E5%A6%82%E6%9E%9C%E4%B8%8D%E5%8F%AF%E9%94%81%E9%87%8D%E5%85%A5%E7%9A%84%E8%AF%9D%EF%BC%8C%E5%B0%B1%E4%BC%9A%E9%80%A0%E6%88%90%E6%AD%BB%E9%94%81%E3%80%82%0A%0A%23%23%23%23%201.6%20%C2%A0%E5%90%8C%E6%AD%A5%E4%B8%8D%E5%85%B7%E6%9C%89%E7%BB%A7%E6%89%BF%E6%80%A7%0A*%20%E5%A6%82%E6%9E%9C%E7%88%B6%E7%B1%BB%E6%9C%89%E4%B8%80%E4%B8%AA%E5%B8%A6synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E7%9A%84%E6%96%B9%E6%B3%95%EF%BC%8C%E5%AD%90%E7%B1%BB%E7%BB%A7%E6%89%BF%E5%B9%B6%E9%87%8D%E5%86%99%E4%BA%86%E8%BF%99%E4%B8%AA%E6%96%B9%E6%B3%95%E3%80%82%C2%A0%E4%BD%86%E6%98%AF%E5%90%8C%E6%AD%A5%E4%B8%8D%E8%83%BD%E7%BB%A7%E6%89%BF%EF%BC%8C%E6%89%80%E4%BB%A5%E8%BF%98%E6%98%AF%E9%9C%80%E8%A6%81%E5%9C%A8%E5%AD%90%E7%B1%BB%E6%96%B9%E6%B3%95%E4%B8%AD%E6%B7%BB%E5%8A%A0synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E3%80%82%0A%0A%23%23%23%202.%20synchronized%E5%85%B3%E9%94%AE%E5%AD%97%EF%BC%882%EF%BC%89%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/c7b52098-298e-4410-a86c-ee341fa8c8f8/33d6223f-fd83-4816-a981-15fb5ac7e5bc.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F1045%3A1)%0A%5Bsynchronized%E5%85%B3%E9%94%AE%E5%AD%972%5D(https%3A%2F%2Fblog.csdn.net%2Fqq_34337272%2Farticle%2Fdetails%2F79670775)%0A%23%23%23%23%202.1%20synchronized%E6%96%B9%E6%B3%95%E7%9A%84%E7%BC%BA%E7%82%B9%0A*%20%E4%BD%BF%E7%94%A8synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E5%A3%B0%E6%98%8E%E6%96%B9%E6%B3%95%E6%9C%89%E4%BA%9B%E6%97%B6%E5%80%99%E6%98%AF%E6%9C%89%E5%BE%88%E5%A4%A7%E7%9A%84%E5%BC%8A%E7%AB%AF%E7%9A%84%EF%BC%8C%E6%AF%94%E5%A6%82%E6%88%91%E4%BB%AC%E6%9C%89%E4%B8%A4%E4%B8%AA%E7%BA%BF%E7%A8%8B%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8BA%E8%B0%83%E7%94%A8%E5%90%8C%E6%AD%A5%E6%96%B9%E6%B3%95%E5%90%8E%E8%8E%B7%E5%BE%97%E9%94%81%EF%BC%8C%E9%82%A3%E4%B9%88%E5%8F%A6%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8BB%E5%B0%B1%E9%9C%80%E8%A6%81%E7%AD%89%E5%BE%85A%E6%89%A7%E8%A1%8C%E5%AE%8C%EF%BC%8C%E4%BD%86%E6%98%AF%E5%A6%82%E6%9E%9C%E8%AF%B4A%E6%89%A7%E8%A1%8C%E7%9A%84%E6%98%AF%E4%B8%80%E4%B8%AA%E5%BE%88%E8%B4%B9%E6%97%B6%E9%97%B4%E7%9A%84%E4%BB%BB%E5%8A%A1%E7%9A%84%E8%AF%9D%E8%BF%99%E6%A0%B7%E5%B0%B1%E4%BC%9A%E5%BE%88%E8%80%97%E6%97%B6%E3%80%82%0A%0A%3E%E5%8F%AF%E4%BB%A5%E4%BD%BF%E7%94%A8**synchronized%E5%90%8C%E6%AD%A5%E5%9D%97**%E6%9D%A5%E8%A7%A3%E5%86%B3%E8%BF%99%E4%B8%AA%E9%97%AE%E9%A2%98%E3%80%82%E4%BD%86%E6%98%AF%E8%A6%81%E6%B3%A8%E6%84%8Fsynchronized%E5%90%8C%E6%AD%A5%E5%9D%97%E7%9A%84%E4%BD%BF%E7%94%A8%E6%96%B9%E5%BC%8F%EF%BC%8C%E5%A6%82%E6%9E%9Csynchronized%E5%90%8C%E6%AD%A5%E5%9D%97%E4%BD%BF%E7%94%A8%E4%B8%8D%E5%A5%BD%E7%9A%84%E8%AF%9D%E5%B9%B6%E4%B8%8D%E4%BC%9A%E5%B8%A6%E6%9D%A5%E6%95%88%E7%8E%87%E7%9A%84%E6%8F%90%E5%8D%87%E3%80%82%0A%0A%23%23%23%23%202.2%20synchronized%EF%BC%88this%EF%BC%89%E5%90%8C%E6%AD%A5%E4%BB%A3%E7%A0%81%E5%9D%97%E7%9A%84%E4%BD%BF%E7%94%A8%0A%60%60%60java%0Apublic%20class%20Task%20%7B%0A%0A%20%20%20%20private%20String%20getData1%3B%0A%20%20%20%20private%20String%20getData2%3B%0A%0A%20%20%20%20public%20void%20doLongTimeTask()%20%7B%0A%20%20%20%20%20%20%20%20try%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20System.out.println(%22begin%20task%22)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20Thread.sleep(3000)%3B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20String%20privateGetData1%20%3D%20%22%E9%95%BF%E6%97%B6%E9%97%B4%E5%A4%84%E7%90%86%E4%BB%BB%E5%8A%A1%E5%90%8E%E4%BB%8E%E8%BF%9C%E7%A8%8B%E8%BF%94%E5%9B%9E%E7%9A%84%E5%80%BC1%20threadName%3D%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2B%20Thread.currentThread().getName()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20String%20privateGetData2%20%3D%20%22%E9%95%BF%E6%97%B6%E9%97%B4%E5%A4%84%E7%90%86%E4%BB%BB%E5%8A%A1%E5%90%8E%E4%BB%8E%E8%BF%9C%E7%A8%8B%E8%BF%94%E5%9B%9E%E7%9A%84%E5%80%BC2%20threadName%3D%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2B%20Thread.currentThread().getName()%3B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20synchronized%20(this)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20getData1%20%3D%20privateGetData1%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20getData2%20%3D%20privateGetData2%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20System.out.println(getData1)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20System.out.println(getData2)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20System.out.println(%22end%20task%22)%3B%0A%20%20%20%20%20%20%20%20%7D%20catch%20(InterruptedException%20e)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20TODO%20Auto-generated%20catch%20block%0A%20%20%20%20%20%20%20%20%20%20%20%20e.printStackTrace()%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%7D%0A%60%60%60%0A*%20%E5%BD%93%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%E8%AE%BF%E9%97%AE%E4%B8%80%E4%B8%AA%E5%AF%B9%E8%B1%A1%E7%9A%84synchronized%E5%90%8C%E6%AD%A5%E4%BB%A3%E7%A0%81%E5%9D%97%E6%97%B6%EF%BC%8C%E5%8F%A6%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%E4%BB%BB%E7%84%B6%E5%8F%AF%E4%BB%A5%E8%AE%BF%E9%97%AE%E8%AF%A5%E5%AF%B9%E8%B1%A1%E9%9D%9Esynchronized%E5%90%8C%E6%AD%A5%E4%BB%A3%E7%A0%81%E5%9D%97%E3%80%82%0A*%20%E4%B8%8D%E5%9C%A8synchronized%E4%BB%A3%E7%A0%81%E5%9D%97%E4%B8%AD%E5%B0%B1%E5%BC%82%E6%AD%A5%E6%89%A7%E8%A1%8C%EF%BC%8C%E5%9C%A8synchronized%E4%BB%A3%E7%A0%81%E5%9D%97%E4%B8%AD%E5%B0%B1%E6%98%AF%E5%90%8C%E6%AD%A5%E6%89%A7%E8%A1%8C%E3%80%82%0A%0A%23%23%23%23%202.3%20synchronized%EF%BC%88object%EF%BC%89%E4%BB%A3%E7%A0%81%E5%9D%97%E9%97%B4%E4%BD%BF%E7%94%A8%0A*%20%E4%B8%A4%E4%B8%AA%E7%BA%BF%E7%A8%8B%E4%BD%BF%E7%94%A8%E4%BA%86%E5%90%8C%E4%B8%80%E4%B8%AA%E2%80%9C%E5%AF%B9%E8%B1%A1%E7%9B%91%E8%A7%86%E5%99%A8%E2%80%9D%2C%E6%89%80%E4%BB%A5%E8%BF%90%E8%A1%8C%E7%BB%93%E6%9E%9C%E6%98%AF%E5%90%8C%E6%AD%A5%E7%9A%84%E3%80%82%0A*%20%E4%B8%A4%E4%B8%AA%E7%BA%BF%E7%A8%8B%E4%BD%BF%E7%94%A8%E4%BA%86%E4%B8%8D%E5%90%8C%E7%9A%84%E2%80%9C%E5%AF%B9%E8%B1%A1%E7%9B%91%E8%A7%86%E5%99%A8%E2%80%9D%2C%E6%89%80%E4%BB%A5%E8%BF%90%E8%A1%8C%E7%BB%93%E6%9E%9C%E4%B8%8D%E6%98%AF%E5%90%8C%E6%AD%A5%E7%9A%84%E4%BA%86%E3%80%82%C2%A0%0A%0A%23%23%23%23%202.4%20synchronized%E4%BB%A3%E7%A0%81%E5%9D%97%E9%97%B4%E7%9A%84%E5%90%8C%E6%AD%A5%E6%80%A7%0A*%20%E5%BD%93%E4%B8%80%E4%B8%AA%E5%AF%B9%E8%B1%A1%E8%AE%BF%E9%97%AEsynchronized(this)%E4%BB%A3%E7%A0%81%E5%9D%97%E6%97%B6%EF%BC%8C%E5%85%B6%E4%BB%96%E7%BA%BF%E7%A8%8B%E5%AF%B9%E5%90%8C%E4%B8%80%E4%B8%AA%E5%AF%B9%E8%B1%A1%E4%B8%AD%E6%89%80%E6%9C%89%E5%85%B6%E4%BB%96synchronized(this)%E4%BB%A3%E7%A0%81%E5%9D%97%E4%BB%A3%E7%A0%81%E5%9D%97%E7%9A%84%E8%AE%BF%E9%97%AE%E5%B0%86%E8%A2%AB%E9%98%BB%E5%A1%9E%EF%BC%8C%E8%BF%99%E8%AF%B4%E6%98%8Esynchronized(this)%E4%BB%A3%E7%A0%81%E5%9D%97%E4%BD%BF%E7%94%A8%E7%9A%84%E2%80%9C%E5%AF%B9%E8%B1%A1%E7%9B%91%E8%A7%86%E5%99%A8%E2%80%9D%E6%98%AF%E5%90%8C%E4%B8%80%E4%B8%AA%E3%80%82%0A*%20%E5%92%8Csynchronized%E6%96%B9%E6%B3%95%E4%B8%80%E6%A0%B7%EF%BC%8Csynchronized(this)%E4%BB%A3%E7%A0%81%E5%9D%97%E4%B9%9F%E6%98%AF%E9%94%81%E5%AE%9A%E5%BD%93%E5%89%8D%E5%AF%B9%E8%B1%A1%E3%80%82%0A%3E1.%20%E5%85%B6%E4%BB%96%E7%BA%BF%E7%A8%8B%E6%89%A7%E8%A1%8C%E5%AF%B9%E8%B1%A1%E4%B8%ADsynchronized%E5%90%8C%E6%AD%A5%E6%96%B9%E6%B3%95%E5%92%8Csynchronized(this)%E4%BB%A3%E7%A0%81%E5%9D%97%E6%97%B6%E5%91%88%E7%8E%B0%E5%90%8C%E6%AD%A5%E6%95%88%E6%9E%9C%3B%0A%3E2.%20%E5%A6%82%E6%9E%9C%E4%B8%A4%E4%B8%AA%E7%BA%BF%E7%A8%8B%E4%BD%BF%E7%94%A8%E4%BA%86%E5%90%8C%E4%B8%80%E4%B8%AA%E2%80%9C%E5%AF%B9%E8%B1%A1%E7%9B%91%E8%A7%86%E5%99%A8%E2%80%9D%2C%E8%BF%90%E8%A1%8C%E7%BB%93%E6%9E%9C%E5%90%8C%E6%AD%A5%EF%BC%8C%E5%90%A6%E5%88%99%E4%B8%8D%E5%90%8C%E6%AD%A5.%0A%0A%23%23%23%23%202.5%20%E9%9D%99%E6%80%81%E5%90%8C%E6%AD%A5synchronized%E6%96%B9%E6%B3%95%E4%B8%8Esynchronized(class)%E4%BB%A3%E7%A0%81%E5%9D%97%0A*%20synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E5%8A%A0%E5%88%B0static%E9%9D%99%E6%80%81%E6%96%B9%E6%B3%95%E5%92%8Csynchronized(class)%E4%BB%A3%E7%A0%81%E5%9D%97%E4%B8%8A%E9%83%BD%E6%98%AF%E6%98%AF**%E7%BB%99Class%E7%B1%BB%E4%B8%8A%E9%94%81**%EF%BC%8C%E8%80%8Csynchronized%E5%85%B3%E9%94%AE%E5%AD%97%E5%8A%A0%E5%88%B0**%E9%9D%9E%E9%9D%99%E6%80%81%E6%96%B9%E6%B3%95**%E4%B8%8A%E6%98%AF%E7%BB%99**%E5%AF%B9%E8%B1%A1%E4%B8%8A%E9%94%81**%E3%80%82%0A*%20%E9%9D%99%E6%80%81%E5%90%8C%E6%AD%A5synchronized%E6%96%B9%E6%B3%95%E4%B8%8Esynchronized(class)%E4%BB%A3%E7%A0%81%E5%9D%97%E6%8C%81%E6%9C%89%E7%9A%84%E9%94%81%E4%B8%80%E6%A0%B7%EF%BC%8C%E9%83%BD%E6%98%AFClass%E9%94%81%EF%BC%8CClass%E9%94%81%E5%AF%B9%E5%AF%B9%E8%B1%A1%E7%9A%84%E6%89%80%E6%9C%89%E5%AE%9E%E4%BE%8B%E8%B5%B7%E4%BD%9C%E7%94%A8%E3%80%82%0A%0A%23%23%23%203.%20volatile%E5%85%B3%E9%94%AE%E5%AD%97%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/c7b52098-298e-4410-a86c-ee341fa8c8f8/bdd036cc-35ff-41a2-b885-ab4afa30cc00.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F1047%3A1)%0A%5Bvolatile%E5%85%B3%E9%94%AE%E5%AD%97%5D(https%3A%2F%2Fblog.csdn.net%2Fqq_34337272%2Farticle%2Fdetails%2F79680771)%0A%23%23%23%23%203.1%20volatile%E5%85%B3%E9%94%AE%E5%AD%97%E7%AE%80%E4%BB%8B%0A*%20volatile%E5%85%B3%E9%94%AE%E5%AD%97%E5%8F%AF%E4%BB%A5%E7%94%A8%E6%9D%A5%E6%8F%90%E9%86%92%E7%BC%96%E8%AF%91%E5%99%A8%E5%AE%83%E5%90%8E%E9%9D%A2%E6%89%80%E5%AE%9A%E4%B9%89%E7%9A%84%E5%8F%98%E9%87%8F%E9%9A%8F%E6%97%B6%E6%9C%89%E5%8F%AF%E8%83%BD%E6%94%B9%E5%8F%98%EF%BC%8C%E5%9B%A0%E6%AD%A4%E7%BC%96%E8%AF%91%E5%90%8E%E7%9A%84%E7%A8%8B%E5%BA%8F%E6%AF%8F%E6%AC%A1%E9%9C%80%E8%A6%81%E5%AD%98%E5%82%A8%E6%88%96%E8%AF%BB%E5%8F%96%E8%BF%99%E4%B8%AA%E5%8F%98%E9%87%8F%E7%9A%84%E6%97%B6%E5%80%99%EF%BC%8C%E9%83%BD%E4%BC%9A%E7%9B%B4%E6%8E%A5%E4%BB%8E%E5%8F%98%E9%87%8F%E5%9C%B0%E5%9D%80%E4%B8%AD%E8%AF%BB%E5%8F%96%E6%95%B0%E3%80%82%0A*%20%E5%A6%82%E6%9E%9C%E6%B2%A1%E6%9C%89volatile%E5%85%B3%E9%94%AE%E5%AD%97%EF%BC%8C%E5%88%99%E7%BC%96%E8%AF%91%E5%99%A8%E5%8F%AF%E8%83%BD%E4%BC%98%E5%8C%96%E8%AF%BB%E5%8F%96%E5%92%8C%E5%AD%98%E5%82%A8%EF%BC%8C%E5%8F%AF%E8%83%BD%E6%9A%82%E6%97%B6%E4%BD%BF%E7%94%A8%E5%AF%84%E5%AD%98%E5%99%A8%E4%B8%AD%E7%9A%84%E5%80%BC%EF%BC%8C%E5%A6%82%E6%9E%9C%E8%BF%99%E4%B8%AA%E5%8F%98%E9%87%8F%E7%94%B1%E5%88%AB%E7%9A%84%E7%A8%8B%E5%BA%8F%E6%9B%B4%E6%96%B0%E4%BA%86%E7%9A%84%E8%AF%9D%EF%BC%8C%E5%B0%86%E5%87%BA%E7%8E%B0%E4%B8%8D%E4%B8%80%E8%87%B4%E7%9A%84%E7%8E%B0%E8%B1%A1%E3%80%82%0A%0A%23%23%23%23%203.2%20volatile%E5%85%B3%E9%94%AE%E5%AD%97%E7%9A%84%E5%8F%AF%E8%A7%81%E6%80%A7%0A*%20volatile%20%E4%BF%AE%E9%A5%B0%E7%9A%84%E6%88%90%E5%91%98%E5%8F%98%E9%87%8F%E5%9C%A8%E6%AF%8F%E6%AC%A1%E8%A2%AB%E7%BA%BF%E7%A8%8B%E8%AE%BF%E9%97%AE%E6%97%B6%EF%BC%8C%E9%83%BD%E5%BC%BA%E8%BF%AB%E4%BB%8E%E4%B8%BB%E5%AD%98%EF%BC%88%E5%85%B1%E4%BA%AB%E5%86%85%E5%AD%98%EF%BC%89%E4%B8%AD%E9%87%8D%E8%AF%BB%E8%AF%A5%E6%88%90%E5%91%98%E5%8F%98%E9%87%8F%E7%9A%84%E5%80%BC%E3%80%82%E8%80%8C%E4%B8%94%EF%BC%8C%E5%BD%93%E6%88%90%E5%91%98%E5%8F%98%E9%87%8F%E5%8F%91%E7%94%9F%E5%8F%98%E5%8C%96%E6%97%B6%EF%BC%8C%E5%BC%BA%E8%BF%AB%E7%BA%BF%E7%A8%8B%E5%B0%86%E5%8F%98%E5%8C%96%E5%80%BC%E5%9B%9E%E5%86%99%E5%88%B0%E4%B8%BB%E5%AD%98%EF%BC%88%E5%85%B1%E4%BA%AB%E5%86%85%E5%AD%98%EF%BC%89%E3%80%82%E8%BF%99%E6%A0%B7%E5%9C%A8%E4%BB%BB%E4%BD%95%E6%97%B6%E5%88%BB%EF%BC%8C%E4%B8%A4%E4%B8%AA%E4%B8%8D%E5%90%8C%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%80%BB%E6%98%AF%E7%9C%8B%E5%88%B0%E6%9F%90%E4%B8%AA%E6%88%90%E5%91%98%E5%8F%98%E9%87%8F%E7%9A%84%E5%90%8C%E4%B8%80%E4%B8%AA%E5%80%BC%EF%BC%8C%E8%BF%99%E6%A0%B7%E4%B9%9F%E5%B0%B1%E4%BF%9D%E8%AF%81%E4%BA%86%E5%90%8C%E6%AD%A5%E6%95%B0%E6%8D%AE%E7%9A%84%E5%8F%AF%E8%A7%81%E6%80%A7%E3%80%82%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/c7b52098-298e-4410-a86c-ee341fa8c8f8/1e03da94-d38e-413a-8536-4721d3782bac.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F1049%3A1)%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/c7b52098-298e-4410-a86c-ee341fa8c8f8/0953b2ed-af8a-41fd-9d83-798785655774.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F1051%3A1)%0A%0A%23%23%23%23%203.3%20synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E5%92%8Cvolatile%E5%85%B3%E9%94%AE%E5%AD%97%E6%AF%94%E8%BE%83%0A*%20volatile%E5%85%B3%E9%94%AE%E5%AD%97%E6%98%AF**%E7%BA%BF%E7%A8%8B%E5%90%8C%E6%AD%A5%E7%9A%84%E8%BD%BB%E9%87%8F%E7%BA%A7%E5%AE%9E%E7%8E%B0**%EF%BC%8C%E6%89%80%E4%BB%A5volatile%E6%80%A7%E8%83%BD%E8%82%AF%E5%AE%9A%E6%AF%94synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E8%A6%81%E5%A5%BD%E3%80%82%E4%BD%86%E6%98%AF**volatile%E5%85%B3%E9%94%AE%E5%AD%97%E5%8F%AA%E8%83%BD%E7%94%A8%E4%BA%8E%E5%8F%98%E9%87%8F**%E8%80%8Csynchronized%E5%85%B3%E9%94%AE%E5%AD%97%E5%8F%AF%E4%BB%A5%E4%BF%AE%E9%A5%B0%E6%96%B9%E6%B3%95%E4%BB%A5%E5%8F%8A%E4%BB%A3%E7%A0%81%E5%9D%97%E3%80%82synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E5%9C%A8JavaSE1.6%E4%B9%8B%E5%90%8E%E8%BF%9B%E8%A1%8C%E4%BA%86%E4%B8%BB%E8%A6%81%E5%8C%85%E6%8B%AC%E4%B8%BA%E4%BA%86%E5%87%8F%E5%B0%91%E8%8E%B7%E5%BE%97%E9%94%81%E5%92%8C%E9%87%8A%E6%94%BE%E9%94%81%E5%B8%A6%E6%9D%A5%E7%9A%84%E6%80%A7%E8%83%BD%E6%B6%88%E8%80%97%E8%80%8C%E5%BC%95%E5%85%A5%E7%9A%84%E5%81%8F%E5%90%91%E9%94%81%E5%92%8C%E8%BD%BB%E9%87%8F%E7%BA%A7%E9%94%81%E4%BB%A5%E5%8F%8A%E5%85%B6%E5%AE%83%E5%90%84%E7%A7%8D%E4%BC%98%E5%8C%96%E4%B9%8B%E5%90%8E%E6%89%A7%E8%A1%8C%E6%95%88%E7%8E%87%E6%9C%89%E4%BA%86%E6%98%BE%E8%91%97%E6%8F%90%E5%8D%87%EF%BC%8C%E5%AE%9E%E9%99%85%E5%BC%80%E5%8F%91%E4%B8%AD%E4%BD%BF%E7%94%A8synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E8%BF%98%E6%98%AF%E6%9B%B4%E5%A4%9A%E4%B8%80%E4%BA%9B%E3%80%82%0A*%20%E5%A4%9A%E7%BA%BF%E7%A8%8B%E8%AE%BF%E9%97%AEvolatile%E5%85%B3%E9%94%AE%E5%AD%97%E4%B8%8D%E4%BC%9A%E5%8F%91%E7%94%9F%E9%98%BB%E5%A1%9E%EF%BC%8C%E8%80%8Csynchronized%E5%85%B3%E9%94%AE%E5%AD%97%E5%8F%AF%E8%83%BD%E4%BC%9A%E5%8F%91%E7%94%9F%E9%98%BB%E5%A1%9E%0A*%20volatile%E5%85%B3%E9%94%AE%E5%AD%97%E8%83%BD%E4%BF%9D%E8%AF%81%E6%95%B0%E6%8D%AE%E7%9A%84%E5%8F%AF%E8%A7%81%E6%80%A7%EF%BC%8C%E4%BD%86%E4%B8%8D%E8%83%BD%E4%BF%9D%E8%AF%81%E6%95%B0%E6%8D%AE%E7%9A%84%E5%8E%9F%E5%AD%90%E6%80%A7%E3%80%82synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E4%B8%A4%E8%80%85%E9%83%BD%E8%83%BD%E4%BF%9D%E8%AF%81%E3%80%82%0A*%20volatile%E5%85%B3%E9%94%AE%E5%AD%97%E7%94%A8%E4%BA%8E%E8%A7%A3%E5%86%B3%E5%8F%98%E9%87%8F%E5%9C%A8%E5%A4%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%85%E6%96%B9%E5%92%8C%E9%80%9A%E7%9F%A5%E6%96%B9%E4%B9%8B%E9%97%B4%E7%9A%84%E4%BA%A4%E4%BA%92%E5%B7%A5%E4%BD%9C%E3%80%82%0A%0A%23%23%23%23%204.2%20%E7%AD%89%E5%BE%85%2F%E9%80%9A%E7%9F%A5%E6%9C%BA%E5%88%B6%E7%9A%84%E5%AE%9E%E7%8E%B0%0A*%20notify()%E6%89%A7%E8%A1%8C%E5%90%8E%E5%B9%B6%E4%B8%8D%E4%BC%9A%E7%AB%8B%E5%8D%B3%E9%87%8A%E6%94%BE%E9%94%81%0A*%20synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E5%8F%AF%E4%BB%A5%E5%B0%86%E4%BB%BB%E4%BD%95%E4%B8%80%E4%B8%AAObject%E5%AF%B9%E8%B1%A1%E4%BD%9C%E4%B8%BA%E5%90%8C%E6%AD%A5%E5%AF%B9%E8%B1%A1%E6%9D%A5%E7%9C%8B%E5%BE%85%EF%BC%8C%E8%80%8CJava%E4%B8%BA%E6%AF%8F%E4%B8%AAObject%E9%83%BD%E5%AE%9E%E7%8E%B0%E4%BA%86%E7%AD%89%E5%BE%85%2F%E9%80%9A%E7%9F%A5%EF%BC%88wait%2Fnotify%EF%BC%89%E6%9C%BA%E5%88%B6%E7%9A%84%E7%9B%B8%E5%85%B3%E6%96%B9%E6%B3%95%EF%BC%8C%E5%AE%83%E4%BB%AC%E5%BF%85%E9%A1%BB%E7%94%A8%E5%9C%A8synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E5%90%8C%E6%AD%A5%E7%9A%84Object%E7%9A%84%E4%B8%B4%E7%95%8C%E5%8C%BA%E5%86%85%E3%80%82%0A*%20%E9%80%9A%E8%BF%87%E8%B0%83%E7%94%A8wait()%E6%96%B9%E6%B3%95%E5%8F%AF%E4%BB%A5%E4%BD%BF%E5%A4%84%E4%BA%8E%E4%B8%B4%E7%95%8C%E5%8C%BA%E5%86%85%E7%9A%84%E7%BA%BF%E7%A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%AE%8Cnotify()%E6%96%B9%E6%B3%95%E5%90%8E%EF%BC%8C%E9%94%81%E4%B8%8D%E4%BC%9A%E8%87%AA%E5%8A%A8%E9%87%8A%E6%94%BE%E3%80%82%E5%BF%85%E9%A1%BB**%E6%89%A7%E8%A1%8C%E5%AE%8Cnotify()%E6%96%B9%E6%B3%95%E6%89%80%E5%9C%A8%E7%9A%84synchronized%E4%BB%A3%E7%A0%81%E5%9D%97%E5%90%8E**%E6%89%8D%E9%87%8A%E6%94%BE%E3%80%82%0A&lt;/center&gt;&lt;/div&gt;
</content>
  </entry>
  <entry xml:base="http://linzhiteng.postach.io/feed.xml">
    <title type="text">三级基础知识</title>
    <id>https://linzhiteng.postach.io/post/san-ji-ji-chu-zhi-shi</id>
    <updated>2019-04-01T05:22:48.236000Z</updated>
    <published>2019-03-09T13:46:56Z</published>
    <link href="https://linzhiteng.postach.io/post/san-ji-ji-chu-zhi-shi" />
    <author>
      <name>linzhi teng</name>
    </author>
    <content type="html">&lt;div&gt;&lt;div style=&quot;font-size: 14px; margin: 0; padding: 0; width: 100%;&quot;&gt;&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;选择题&lt;/h2&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;必考&lt;/h4&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;问传输速度&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;OC-3&lt;/strong&gt; 对应 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;155&lt;/strong&gt;.52 Mbps&lt;br/&gt;
&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;OC-12&lt;/strong&gt; 对应 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;622&lt;/strong&gt;.08 Mbps &lt;br/&gt;
&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;OC-48&lt;/strong&gt;对应&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;2.488&lt;/strong&gt;GMbps&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ol start=&quot;2&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;求交换机带宽&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;某交换机有 12 个 10/100 Mbps 电端口和 2 个 1000 Mbps 光端口，所有端口都在&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;全双工&lt;/strong&gt;状态下，那么&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;总带宽&lt;/strong&gt;为（ ） &lt;br/&gt;
解：忽略 10/100 中的 10，当成 100 Mbps 就好。12 * 100 + 2 * 1000 = 3200，又因为全双工所以乘以 2 得 6400 Mbps ,即 6.4 Gbps&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;某交换机有 16个100/1000 Mbps 全双工&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;下联端口&lt;/strong&gt;，那么&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;上联端口&lt;/strong&gt;带宽至少为（ ） &lt;br/&gt;
解：16 * 1000 * 2 = 32000 Mbps = 32 Gbps，&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;上联一般是下联的 1/20&lt;/strong&gt; ，所以至少为 32 除以 20 得 1.6 Gbps&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;3.系统可用性与停机时间&lt;/p&gt;
&lt;table style=&quot;margin: 2px 0 14px; color: #333; width: auto; border-collapse: collapse; box-sizing: border-box;&quot;&gt;&lt;thead style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;可用性&lt;/th&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;停机时间&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;99.9%&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;≤8.8小时&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;99.99%&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;≤53分钟&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;99.999%&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;≤5分钟&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;ol start=&quot;4&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;写地址块的子网掩码&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;例：IP 地址块 59.67.159.125/11 的子网掩码可写为（ ）&lt;br/&gt;
解：不用看 IP 地址，只看 /11 就够了。 11 代表子网掩码的前 11 位都是 1 ，所以可以写出子网掩码 11111111.11100000.00000000.00000000 转换为十进制即是 255.224.0.0&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;5. 网络地址转换 NAT&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/2347a20d-0da4-444f-8233-f881cd6272fe.png&quot; /&gt;&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;会给你一个这样的图，问你 ① ② 是什么 只需要知道②和紧挨着它的 S 数字相同，所以②应该是 202.0.1.1,5001 ;同理，①是 10.0.0.1,3342。 还有时候会问某个小方框里的 S,D 分别是什么，看上面的图你会发现，上面两个方框和下面两个方框里的数字是对称的，做题时对称一下就写出答案了。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/59bbe5a2-1403-4c23-a939-2db1ecd79e7e.png&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/9b9ae9b7-5d1b-46f2-aef8-6bb1e264d189.png&quot; /&gt;&lt;/p&gt;
&lt;hr style=&quot;line-height: 160%; box-sizing: content-box; border-top: 1px solid #eee; margin: 16px 0;&quot;/&gt;
&lt;ol start=&quot;6&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;IP 地址块聚合&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;第一种：问聚合后的地址块&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/cabe7911-6520-4a9b-8217-760b906017f3.png&quot; /&gt;&lt;br/&gt;
步骤为：转成二进制；对齐找前多少位是相同的；转回十进制写答案。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;第二种：问聚合后可用 IP 数 &lt;br/&gt;
【第一种情况】如未来教育上机考试第一套试题第10题： &lt;br/&gt;
&quot; IP 地址块 202.113.79.128/27、202.113.79.160/27 和 202.113.79.192/27 经过聚合后可用的地址数为___&quot;&lt;br/&gt;
因为格式都是 xxx.xxx.xxx.xxx/27，本题中&quot;/&quot;后边的数字都是相同的。 &lt;br/&gt;
所以遇到这种题，先把前两个 IP 聚合求出可用地址数，202.113.79.128/26  2^6-2=62&lt;br/&gt;
然后单独算出第三个 IP 地址可用地址数，2^5-2=32&lt;br/&gt;
两个地址数相加即正确答案。32+62=94&lt;br/&gt;
【第二种情况】如未来教育上机考试第三套试题第10题： &lt;br/&gt;
&quot; IP 地址块 202.113.79.0/27、202.113.79.32/27、202.113.79.64/26 经过聚合后可用的地址数为___&quot;&lt;br/&gt;
本题中&quot;/&quot;后边的数字前两个是相同的，第三个与前两个不同。 &lt;br/&gt;
所以遇到这种题，直接将三个 IP 聚合得到地址块，202.113.79.0/25&lt;br/&gt;
然后求出三个 IP 的可用地址数。2^(32-25)-2=126&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;ol start=&quot;7&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;路由表距离更新&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;R1,R2 是一个系统中采用RIP路由协议的两个相邻路由器，R1 的路由表如（a）所示， R1 收到 R2 发送的报文（b）后，R1 更新后的距离值从上到下依次是（ ） &lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/0bb252a5-173f-4df5-a240-7e6806ba704d.png&quot; /&gt;&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/0135653e-bba5-4176-9b28-e87b3b9abca0.png&quot; /&gt;&lt;br/&gt;
步骤为：b距离+1；与a距离比较；更新为距离最小的。则更新后的距离值从上到下依次是 0、4、4、3、2&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;还经常这样考——给出更新后距离值和（a）中的距离，求（b）报文距离的可能值。 &lt;br/&gt;
b的报文距离&gt;=更新后的距离值-1&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;ol start=&quot;8&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;IPv6 地址简化表示&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;例：某地址 FF23:0:0:0:0510:0:0:9C5B，&lt;br/&gt;
 可以简化为 FF23::0510:0:0:9C5B，双冒号替代连续出现的 0 位段， &lt;br/&gt;
 不能简化为 FF23::0510::9C5B，因为双冒号只能使用一次， &lt;br/&gt;
 可以简化为 FF23::510:0:0:9C5B，因为 0510 就是 510 ，&lt;br/&gt;
  不能简化为 FF23::051:0:0:9C5B，因为 0510 不是 51。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;例：下列 IPv6 地址表示中错误的是（ ）&lt;br/&gt;
 A) ::10F:BC:0:0:03DA &lt;br/&gt;
 B) FE::0:45:03/48 &lt;br/&gt;
 C) FE31:0:BC:3E:0:050D:BC::03DA &lt;br/&gt;
 D) FF34:42:BC::3E:50F:21:03D &lt;br/&gt;
 解：IPv6 地址是 128 位划分为 8 段的地址，而 C 项不算双冒号那段已经有了 8 段，双冒号又至少压缩一个 0 位段，所以超了 8 段，是错误的。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;ol start=&quot;9&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;数据包&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;例：下图是 A 发送的数据包通过路由器转发到 B 的过程示意图，求数据包 3 中的目的IP地址和目的MAC地址 &lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/9f3d73ab-71bd-4d2d-a1ad-c10465d5fd3c.png&quot; /&gt;&lt;br/&gt;
解：无论哪个数据包，目的 IP 地址就是 B 的 IP 地址，所以数据包 3 的目的 IP 为 129.42.56.216； 而目的 MAC 地址就是下一个路由器的 MAC 地址，数据包 3 的下一个路由器是 R3，所以数据包 3 的目的 MAC 地址是 00d0.63c3.3c41。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;ol start=&quot;10&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;三种备份&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;备份速度从快到慢：增量备份、差异备份、完全备份（备份越详细越慢） &lt;br/&gt;
恢复速度从快到慢：完全备份、差异备份、增量备份（和上面顺序相反，也好理解，备份时详细的恢复快）&lt;br/&gt;
 空间占用从多到少：完全备份、差异备份、增量备份（备份越详细占用空间越多） &lt;br/&gt;
 题目通常问你其中某一种的顺序。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;大段配置4选1&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;排除法 找不同&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;正确错误四选一&lt;/h4&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;1. 弹性分组环 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;RPR&lt;/strong&gt;&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;每一个节点都执行&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;SRP&lt;/strong&gt;公平算法&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;与FDDI 一样使用&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;双环&lt;/strong&gt;结构&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;传统的 FDDI 环，当源结点向目的节点成功发送一个数据帧之后，这个数据帧由源结点从环中回收&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;而 RPR 环，当源结点向目的节点成功发送一个数据帧之后，这个数据帧由&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;目的结点从环中回收&lt;/strong&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;RPR 采用自愈环设计思路，能在 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;50ms&lt;/strong&gt;时间内隔离故障结点和光纤段&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;两个 RPR 结点间的裸光纤最大长度可达 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;100公里&lt;/strong&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;RPR 的&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;外环&lt;/strong&gt;（顺时针）和&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;内环&lt;/strong&gt;（逆时针）&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;都可以&lt;/strong&gt;用于传输分组和控制分组&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;2. 无线接入技术&lt;/h5&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;主要有 WLAN、WiMAX、WiFi、WMAN 和 Ad hoc ( WiFi 肯定知道，记住无线技术一般是W开头的，但有个特殊的A开头)&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;APON 不是无限传输技术&lt;/strong&gt;，这个经常是迷惑项&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;3. 广域网 QoS&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;考的时候通常只写英文缩写，下面写上中文名是为了方便你记忆（其他的地方也应该养成粗略推测英文缩写的习惯）主要的技术有 资源预留（&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;RSVP&lt;/strong&gt;）、区分服务（&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;DiffServ&lt;/strong&gt;）、多协议标记交换（&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;MPLS&lt;/strong&gt;）&lt;/p&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4. 接入技术特征&lt;/h5&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;ASDL&lt;/strong&gt; 使用一对铜双绞线，具有&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;非对称&lt;/strong&gt;技术特性，&lt;u style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;上行速率 64 kbps~640 kbps&lt;/u&gt;，&lt;u style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;下行速率 500 kbps~7 Mbps&lt;/u&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;采用 ADSL 技术可以通过 PSTN 接入 Internet&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;Cable Modom&lt;/strong&gt;（电缆调制解调器）利用&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;频分复&lt;/strong&gt;用的方法将信道分为上行信道和下行信道，把用户计算机与有线电视同轴电缆连接起来&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;光纤传输距离可达 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;100km&lt;/strong&gt;以上（这个知道光纤很远就行了）&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;5. 服务器技术&lt;/h5&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;热插拔功能允许用户在不切断电源的情况下更换硬盘、板卡等（不能更换主板卡）&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;集群技术中，如果一台主机出现故障，不会影响正常服务，但会影响系统性能&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;磁盘性能表现在储存容量和 I/O 速度（I/O=input/output 即输入/输出，学过计算机应该知道）&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;服务器总体性能取决于 CPU 数量、CPU 主频、系统内存、网络速度&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;6. 综合布线&lt;/h5&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;双绞线&lt;/strong&gt;可以&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;避免电磁干扰&lt;/strong&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;嵌入式插座&lt;/strong&gt;用来连接&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;双绞线&lt;/strong&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;多介质插座&lt;/strong&gt;用来连接&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;铜缆和光纤&lt;/strong&gt;，满足用户&quot;光纤到桌面&quot;的需求&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;建筑群&lt;/strong&gt;子系统可以是多种布线方式的任意组合，&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;地下管道布线是最理想&lt;/strong&gt;的方式，直埋最不利&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;STP 比 UTP 贵、复杂、抗干扰能力强、辐射小&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;水平布线&lt;/strong&gt;子系统电缆长度在 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;90 m&lt;/strong&gt; 以内&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;干线线缆&lt;/strong&gt;铺设经常采用&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;点对点结合和分支结合&lt;/strong&gt;两种方式.&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;7. BGP 协议&lt;/h5&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;BGP&lt;/strong&gt; 是&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;边界网关协议&lt;/strong&gt;，而不是内部网关协议（所以遇到问某两个&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;自治系统AS&lt;/strong&gt;之间使用什么协议，就选 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;BGP&lt;/strong&gt;）  &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;不同&lt;/strong&gt;的自治系统&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;BGP 交换路由信息的节点数不小于自治系统数&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;一个 BGP 发言人使用 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;TCP&lt;/strong&gt;（不是UDP）与&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;其他自治系统&lt;/strong&gt;的 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;BGP&lt;/strong&gt; 发言人交换信息&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;BGP 采用&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;路由向量&lt;/strong&gt;协议，而 RIP 采用距离向量协议&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;BGP 发言人通过 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;update&lt;/strong&gt; 而不是 noticfication &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;分组通知相邻系统&lt;/strong&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;open&lt;/strong&gt; 分组用来与相邻的另一个 BGP 发言人&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;建立关系&lt;/strong&gt;，两个 BGP 发言人需要&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;周期性地交换&lt;/strong&gt; &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;keepalive&lt;/strong&gt; 分组来确认双方的相邻关系&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;8. RIP 协议&lt;/h5&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;RIP&lt;/strong&gt; 是&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;内部网关协议&lt;/strong&gt;中使用最广泛的一种协议，它是一种分布式、基于距离向量的路由选择协议，要求路由器&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;周期性地向外发送路由刷新报文&lt;/strong&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;路由刷新报文&lt;/strong&gt;主要内容是由若干个 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;(V，D）组成的表&lt;/strong&gt; V 标识该路由器可以到达的目标网络（或目的主机）；D 指出该路由器到达目标网络（或目标主机）的距离。&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;距离D对应该路由器上的跳数&lt;/strong&gt;。其他路由器在接收到某个路由器的（V，D）报文后，按照&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;最短路径原则&lt;/strong&gt;对各自的路由表进行刷新&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;使用 RIP v1 路由协议在配置网络地址时无须给定子网掩码&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;9. OSPF 协议&lt;/h5&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;OSPF 是内部网关协议的一种，&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;每个区域有一个 32 位&lt;/strong&gt;的标识符，区域内&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;路由器不超过 200&lt;/strong&gt; 个&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;链路状态数据库保存全网&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;拓扑结构图&lt;/strong&gt;，&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;不知道其他区域的网络拓扑&lt;/strong&gt;（拓扑的意思是链接形式和位置关系之类的）&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;链路状态&quot;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;度量&quot;主要指费用、距离、延时、带宽&lt;/strong&gt;等&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;OSPF 采用&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;洪泛法&lt;/strong&gt;最短优先路径向&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;所有&lt;/strong&gt;路由器发送消息&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;通过&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;区域划分提高收敛速度&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;10. 集线器&lt;/h5&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;工作在&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;物理层&lt;/strong&gt;，连接到一个集线器的所有结点&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;共享一个冲突域&lt;/strong&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;集线器不是基于 MAC 地址完成&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;数据转发&lt;/strong&gt;，而是用&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;广播&lt;/strong&gt;的方法&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;在&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;链路中串接一个集线器&lt;/strong&gt;可以&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;监听&lt;/strong&gt;数据包&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;每次&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;只有一个结点&lt;/strong&gt;能够&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;发送&lt;/strong&gt;数据，而&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;其他的结点&lt;/strong&gt;都处于&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;接收&lt;/strong&gt;数据的状态。这些结点执行&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;CSMA/CD&lt;/strong&gt;介质访问控制方法&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;11. 交换机&lt;/h5&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;是一种工作在数据链路层的网络设备，基本功能是维护一个表示 MAC 地址和交换机端口对应关系的交换表&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;在源端口与目的端口间建立虚链接&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;具有三种交换模式：1.&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;快速转发直通&lt;/strong&gt;式，接收到前 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;14 个字节&lt;/strong&gt;就转发数据；2.&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;碎片丢弃式，缓存前 64&lt;/strong&gt;个字节；3.&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;储存转发式，转发之前读取整个帧&lt;/strong&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;三层交换机是具有部分路由器功能的交换机，用于加快大型局域网内部的数据交换&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;12. 路由器&lt;/h5&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;丢包率&lt;/strong&gt;是衡量路由器&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;超负荷&lt;/strong&gt;工作时的性能指标之一&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;背板&lt;/strong&gt;能力决定路由器&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;吞吐量&lt;/strong&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;吞吐量指包转发能力&lt;/strong&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;传统&lt;/strong&gt;路由器一般采用&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;共享背板&lt;/strong&gt;的结构，&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;高性能&lt;/strong&gt;路由器一般采用&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;交换式&lt;/strong&gt;的结构&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;突发处理能力不是以最小帧间隔值来衡量的&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;语音视频业务对延时抖动要求较高&lt;/strong&gt;高端路由器应达到：无故障连续工作时间大于 10 万小时；故障恢复时间小于 30 分钟；切换时间小于 50 毫秒&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;13. IEEE 802.11&lt;/h5&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;IEEE 802.11 最初定义的三个物理层包括了两个扩频技术和一个红外传播规范，无线频道定义在 2.4GHz ISM频段，传输速度 1~2 Mbps&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;802.11&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;b&lt;/strong&gt; 最大&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;容量 33&lt;/strong&gt; Mbps，将传输速率提高到 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;11&lt;/strong&gt; Mbps，&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;802.11&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;a&lt;/strong&gt; 将传输&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;速率&lt;/strong&gt;提高到 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;54&lt;/strong&gt; Mbps &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;容量  432&lt;/strong&gt; &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;吞吐量28-31&lt;/strong&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;802.11&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;g&lt;/strong&gt; &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;54&lt;/strong&gt;Mbps，工作在&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;ISM频段&lt;/strong&gt; &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;容量  162&lt;/strong&gt; &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;吞吐量28-31&lt;/strong&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;IEEE 802.11d 是当前最流行的 STP（生成树协议）标准&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;IEEE 802.11b 标准使用的是开放的 2.4GHZ 频段，无须申请就可以直接使用&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;14. 蓝牙&lt;/h5&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;同步信道速率 64 kbps，跳频速率为 1600 次/s&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;工作&lt;/strong&gt;在 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;2.402 ~ 2.480&lt;/strong&gt; GHz 的 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;ISM 频段&lt;/strong&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;非对称的异步信道速率&lt;/strong&gt;为 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;723.2 kbps / 57.6&lt;/strong&gt; kbps&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;对称的异步信道速率为 433.9&lt;/strong&gt; kbps&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;发射功率&lt;/strong&gt;   &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;0dbm：1-10m&lt;/strong&gt;     |    &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;20dbm：100m&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;15. Serv-U FTP 服务器&lt;/h5&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;使用动态 IP 地址时，服务器 IP 地址应配置为空，而不是 0.0.0.0。（为空代表全部 IP 地址）&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;每个 Serv-U FTP 服务器中的虚拟服务器由 IP 地址和端口号唯一识别，而不是依靠 IP 地址&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;向服务器中添加&quot;anonymous&quot;，系统自动判定为匿名。而不是创建新域时自动添加一个&quot;anonymous&quot;匿名&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;服务器最大用户数是指服务器允许同时在线的最大用户数量&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;用户上传下载选项要求 FTP 客户端在下载信息的同时也要上传文件&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;16. DNS 服务器&lt;/h5&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;允许客户机在发生更改时动态更新其资源记录(可配置)&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;DNS 服务器中的根服务器被自动加入到系统中，不需管理员手工配置&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;转发器是网络上的 DNS 服务器&lt;/strong&gt;(可配置)，用于外域名的 DNS 查询&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;使用 nslookup 命令可以测试正向和反向查找区域，（可配置）&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;主机记录的生存时间指该记录被客户端查询到，放在缓存中的持续时间.&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;DNS解析，首先&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;查询本地客户机的缓存&lt;/strong&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;动态ip分配只需配DHCP服务器&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;17. DHCP 服务器&lt;/h5&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;负责&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;多个网段 IP 地址分配&lt;/strong&gt;时需配置&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;多个作用域(地址池)&lt;/strong&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;添加保留时需在 DHCP 客户机上获得其 MAC 地址信息（添加排除时不需从客户端获得 MAC 地址）&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;不添加排除和保留时，服务器可将地址池内的 IP 地址动态指派给 DHCP 客户机&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;地址池是作用域应用排除范围之后剩余的 IP 地址&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;保留是指确保 DHCP 客户端永远可以得到同一 IP 地址，客户端可以释放该租约&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;收到非中继转发的&quot;DHCP发现&quot;消息时,选择收到该消息的子网所处的网段分配 IP 地址&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;18. WWW 服务器&lt;/h5&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;Web 站点可以配置&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;静态和动态 IP&lt;/strong&gt;地址&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;访问 Web 站点时可以使用站点的&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;域名或站点的 IP&lt;/strong&gt;地址&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;建立 Web 站点时必须为该站点指定一个主目录好，也可以是虚拟的子目录&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;Web 站点的性能选项包括影响带宽使用的属性和客户端 Web 连接的数量&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;在 Web 站点的主目录选项卡中，可配置主目录的读取和写入等权限&lt;/li&gt;
&lt;/ul&gt;
&lt;ol start=&quot;19&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;Wmail 邮件服务器&lt;/li&gt;
&lt;/ol&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;发送邮件时通常采用 SMTP 协议，接收邮件时通常采用 POP3 或者 IMAP 协议。Winmail 用户使用浏览器查看邮件会使用到 HTTP 协议&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;u style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;邮件服务器可以设置 用户名，域名，用户密码 ，不能设置管理员&lt;/u&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;23. 网络攻击&lt;/h5&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;DDos 攻击&lt;/strong&gt;：利用已经攻占的多个系统向目标攻击，被害设备面对大量&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;请求无法正常处理&lt;/strong&gt;而&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;拒绝服务&lt;/strong&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;SYN Flooding&lt;/strong&gt; 攻击：利用 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;TCP 三次握手&lt;/strong&gt;过程，使受害主机处于会话请求之中，直至连接超时停止响应&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;SQL 注入&lt;/strong&gt;攻击：属于利用系统漏洞，&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;防火墙&lt;/strong&gt;（基于网络的防护系统）&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;无法阻断&lt;/strong&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;Land攻击&lt;/strong&gt;：向某个设备发送&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;数据包&lt;/strong&gt;，并将数据包的源 IP 地址和目的地址都设置成攻击目标的地址&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;基于网络的防护系统也无法阻断 Cookie篡改 和 DNS欺骗&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;Tear doop 、Smurf 攻击可以被路由器阻止&lt;/li&gt;
&lt;/ul&gt;
&lt;ol start=&quot;24&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;无线局域网设备&lt;/li&gt;
&lt;/ol&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;无线接入点（AP）：集合无线或者有线终端（类似于集线器和交换机），负责频段管理和漫游工作（SSID 是客户端设备用来访问接入点的唯一标识）&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;无线路由器&lt;/strong&gt;：具有无线路由功能和 NAT 功能的 AP ，可用来&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;建立小的无线局域网&lt;/strong&gt;。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;无线网桥&lt;/strong&gt;：用于连接几个不同的网段，实现&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;较远距离的无线通信&lt;/strong&gt;（网桥最重要的维护工作是构建和维护 MAC 地址表）&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;无线网卡&lt;/strong&gt;：实现&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;点对点通信&lt;/strong&gt;，安装于各终端节点&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;25. VLAN&lt;/h5&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;VLAN name 用 1~&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;32 个字符&lt;/strong&gt;表示，它可以是&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;字母和数字&lt;/strong&gt;。不给定名字的 VLAN 系统自动&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;按缺省的 VLAN 名（VLAN00xxx）&lt;/strong&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;VLAN ID的取值范围是 1~&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;4094&lt;/strong&gt;。用&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;12bit&lt;/strong&gt;表示。其中无法执行&quot;no vlan 1&quot;命令&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;Ethernet vlanid 1-1000&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;属于&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;数据链路层&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;26. Cisco 路由器上的存储器&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;configure terminal：global configuration&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;privilege&lt;/strong&gt; EXEC 特权模式 在用户模式 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;下输入enable&lt;/strong&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;setup 设置模式刚出厂&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;RXBOOT  维护模式  密码恢复&lt;br/&gt;
监视模式 ：系统映像更新，口令恢复&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;Cisco Aironet 1100快速配置页面&lt;br/&gt;
Broadcast SSID in Beacon:允许设备不指定SSID&lt;br/&gt;
configuration server protocol :自动分配ip&lt;br/&gt;
ip address: 设置接入点ip&lt;br/&gt;
radio server set ID： 输入网络管理员SSID&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;Flash 主要用于存储当前使用的操作系统映像文件和微代码&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;NVRAM 主要存储启动配置文件或备份配置文件&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;RAM 主要存储路由表、快速交换缓存、ARP 缓存、数据分组缓冲区和缓冲队列、运行配置文件等&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;ROM&lt;/strong&gt; 主要用来&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;永久&lt;/strong&gt;保存路由器的开机诊断程序、引导程序和操作系统软件&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;27. 防火墙对应端口的连接方案&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;pix525 在缺省情况下&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;ethernet0 被命名为外部接口 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;outside&lt;/strong&gt;，安全级别是 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;0&lt;/strong&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;ethernet1 被命名为内部接口 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;inside&lt;/strong&gt;，安全级别是 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;100&lt;/strong&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;ethernet2 被命名为中间接口 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;dmz&lt;/strong&gt;，安装级别是 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;50&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;28. STP 生成树结构&lt;/h5&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;STP运行在&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;交换机和网桥上&lt;/strong&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;IEEE802.1D最早的&lt;/strong&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;无论是根的确定，还是树状结构的生成，主要依靠 BPDU 提供的信息&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;Bridge ID 由&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;2个字节的优先级值&lt;/strong&gt;和 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;6 个字节的交换机 MAC 地址&lt;/strong&gt;组成，&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;优先级取值范围是0~61440，增值量是4096&lt;/strong&gt;，优先值越小，优先级越高&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;MAC 地址&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;最小&lt;/strong&gt;的为&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;根网桥&lt;/strong&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;BPDU 数据包有两种类型，&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;配置 BPDU&lt;/strong&gt; 不超过 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;35 个字节&lt;/strong&gt;，&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;拓扑&lt;/strong&gt;变化通知 BPDU 不超过 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;4 个字节&lt;/strong&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;BPDU每隔&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;2秒&lt;/strong&gt;发送一次，&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;故障变化发送新的&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ol start=&quot;29&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;Catelyst 配置命令&lt;/li&gt;
&lt;/ol&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;Catelyst3548 设置时间的格式是：clock set 小时:分钟:秒 日 月 年&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;Catelyst6500 设置时间的格式是：set time 星期 月/日/年 小时 分钟 秒&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;30. windows2003 命令&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;ipconfig：tcp/ip网络配置&lt;br/&gt;
net view：域列表，计算机列表&lt;br/&gt;
nbtstat -a : 远程计算机&lt;br/&gt;
nslookup：internet域名信息，诊断DNS&lt;br/&gt;
netstat：tcp连接，本地地址，外部地址，状态&lt;/p&gt;
&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;大题&lt;/h2&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;填地址&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/c39b1b15-31a1-4d3c-81df-0a0e3b824e3f.png&quot; /&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;已知ip地址和子网掩码求其他&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/b2059bdd-df26-4900-873b-09afda841f29.png&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;主机位前面0的个数就是子网掩码1的个数&lt;/p&gt;
&lt;hr style=&quot;line-height: 160%; box-sizing: content-box; border-top: 1px solid #eee; margin: 16px 0;&quot;/&gt;
&lt;ol start=&quot;2&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;计算子网掩码和 IP 段部分&lt;/li&gt;
&lt;/ol&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;将 192.168.66.128/25 划分为三个子网，子网 1 能容纳 50 台主机，子网 2 和 3 能分别容纳 20 台主机……求他们的子网掩码和可用 IP 地址段&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;题中说多少台主机的具体数字不重要，刚好大于那个数字的 2 的 n 次方的数才重要。&lt;br/&gt;
台&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;数要加2&lt;/strong&gt;，比如 50+2 台，就是 64，是 2 的 6 次方。所以子网掩码后 6 位都是 0 （前面全是 1 ），11111111.11111111.11111111.11000000 ，最后填空写 255.255.255.192 &lt;br/&gt;
同理 20+2 台，就是 32，是 2 的 5次方。所以子网掩码后 5位都是 0，最后填空 2 和 3 的子网掩码都是 255.255.255.224   （ 11100000）&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;可用 IP 地址从题目所给的那个数 +1 开始，本题是 192.168.66.128+1=129， 从 129 开始，因为子网 1 的主机台数要是 64 ，所以到 190 结束（129+64-3=190，不用管为什么，结束都是 -3）   129-190&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;下一段从 193 开始（190+3=193，不用管为什么，开始都是 +3），因为子网 2 的那个数字是 32 ，所以到 222 结束（193+32-3=222）    193-222&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;再下一段从 225 开始（222+3=225），因为子网 3 的那个数字也是 32 ，所以到 254 结束（225+32-3=254）     225-254&lt;/p&gt;
&lt;hr style=&quot;line-height: 160%; box-sizing: content-box; border-top: 1px solid #eee; margin: 16px 0;&quot;/&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;3.综合题2&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/56f63d48-e023-484d-a424-9d632280c2de.png&quot; /&gt;&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;u style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;ip dhcp :exclude-address &lt;/u&gt; 保留地址的两个值&lt;br/&gt;
&lt;u style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;ip dhcp pool &lt;/u&gt;地址池名&lt;br/&gt;
&lt;u style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;network 地址池地址 子网掩码&lt;/u&gt;&lt;br/&gt;
&lt;u style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;default-route 缺省网关地址&lt;/u&gt;&lt;br/&gt;
&lt;u style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;dns-server address  两个域名服务器地址&lt;/u&gt;&lt;br/&gt;
&lt;u style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;lease 租用时间&lt;/u&gt;(天 小时 分钟)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/abe5827f-b025-49b8-b867-c08f3b788821.png&quot; /&gt;&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/df86b003-8c26-4a78-913c-b01bfdb78148.png&quot; /&gt;&lt;/p&gt;
&lt;hr style=&quot;line-height: 160%; box-sizing: content-box; border-top: 1px solid #eee; margin: 16px 0;&quot;/&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/ca1ae1ab-b288-43a8-bf56-ec5e400bb1ac.png&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/9d55abdb-bcda-4d3d-808b-87d0714bfecc.png&quot; /&gt;&lt;/p&gt;
&lt;hr style=&quot;line-height: 160%; box-sizing: content-box; border-top: 1px solid #eee; margin: 16px 0;&quot;/&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/46c3ae46-9ced-4dbd-9a13-3d86d4dc23b5.png&quot; /&gt;&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/e09299f2-1006-4d54-afd2-1930b574bb58.png&quot; /&gt;&lt;/p&gt;
&lt;hr style=&quot;line-height: 160%; box-sizing: content-box; border-top: 1px solid #eee; margin: 16px 0;&quot;/&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4. 综合题3&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;type 后面的 按顺序是release ，discover，offer，request，ack&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/ee10523d-edcf-4959-97f6-b19360ff91e2.png&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/65cda361-2ce8-43a2-b479-cf0512d7c6ce.png&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;第一行是release 代表有ip&lt;br/&gt;
如果第一行是discover代表没有ip 即 0.0.0.0 ,  255.255.255.255&lt;br/&gt;
最后一行是 request IP address对应第一行的第一个ip&lt;br/&gt;
offer对应第二个ip&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;boot record type 2是reply&lt;br/&gt;
boot record type 1是request&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;最后一行是  server IP address 对应第二个ip&lt;/p&gt;
&lt;hr style=&quot;line-height: 160%; box-sizing: content-box; border-top: 1px solid #eee; margin: 16px 0;&quot;/&gt;
&lt;hr style=&quot;line-height: 160%; box-sizing: content-box; border-top: 1px solid #eee; margin: 16px 0;&quot;/&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;5. 综合题4&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/ed4026c6-f2ce-4d7b-8571-4965f5d920c9.png&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;功能一般是路由&lt;br/&gt;
&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;dest address ①处 是它下面一行的第一个ip或域名&lt;/strong&gt;&lt;br/&gt;
&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;source address 就是 第一行第一个ip&lt;/strong&gt;&lt;br/&gt;
destination address 是 ip  域名&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;u style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;执行的命令一般是   &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;tracert 域名&lt;/strong&gt;&lt;/u&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;dns ip一般是第一行第二个ip&lt;/strong&gt;&lt;br/&gt;
&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;protocol : ICMP&lt;/strong&gt;&lt;/p&gt;
&lt;hr style=&quot;line-height: 160%; box-sizing: content-box; border-top: 1px solid #eee; margin: 16px 0;&quot;/&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;6. 应用题&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/681f78a9-e9be-4af8-8c59-df61bb93e855.png&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;3个ip聚合的时候，要满足2n-2&gt;=3,即子网掩码必须要小于32-3=29.(如果算出来是30就变为29)&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/184f4d21-90a0-4df2-8a5a-2e90026ca7a9.png&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;如果算出来的ip和已有的ip重合了，就向左移一位，后面的1变为0，子网掩码因此减一。&lt;/p&gt;
&lt;hr style=&quot;line-height: 160%; box-sizing: content-box; border-top: 1px solid #eee; margin: 16px 0;&quot;/&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;问在某路由器上，最多还可链接的路由器数量是多少。如果所在子网掩码是 /29 就填 3，是 /28 就填 11。&lt;br/&gt;
问串接一种设备能监听路由器之间的流量，写 TAP&lt;br/&gt;
问串接一种设备能提供安全保护，警报阻断攻击，一般是 IPS    RA的E1端口&lt;br/&gt;
问防火墙访问外网设置，分别填 nat 和 global&lt;br/&gt;
访问内网 static&lt;/p&gt;
&lt;hr style=&quot;line-height: 160%; box-sizing: content-box; border-top: 1px solid #eee; margin: 16px 0;&quot;/&gt;
&lt;/div&gt;&lt;center style=&quot;display:none !important;visibility:collapse !important;height:0 !important;white-space:nowrap;width:100%;overflow:hidden&quot;&gt;%23%23%20%E9%80%89%E6%8B%A9%E9%A2%98%0A%23%23%23%23%20%E5%BF%85%E8%80%83%0A1.%20%E9%97%AE%E4%BC%A0%E8%BE%93%E9%80%9F%E5%BA%A6%0A%3E**OC-3**%20%E5%AF%B9%E5%BA%94%20**155**.52%20Mbps%0A%3E**OC-12**%20%E5%AF%B9%E5%BA%94%20**622**.08%20Mbps%C2%A0%0A%3E**OC-48**%E5%AF%B9%E5%BA%94**2.488**GMbps%0A2.%20%20%E6%B1%82%E4%BA%A4%E6%8D%A2%E6%9C%BA%E5%B8%A6%E5%AE%BD%0A%3E*%20%E6%9F%90%E4%BA%A4%E6%8D%A2%E6%9C%BA%E6%9C%89%2012%20%E4%B8%AA%2010%2F100%20Mbps%20%E7%94%B5%E7%AB%AF%E5%8F%A3%E5%92%8C%202%20%E4%B8%AA%201000%20Mbps%20%E5%85%89%E7%AB%AF%E5%8F%A3%EF%BC%8C%E6%89%80%E6%9C%89%E7%AB%AF%E5%8F%A3%E9%83%BD%E5%9C%A8**%E5%85%A8%E5%8F%8C%E5%B7%A5**%E7%8A%B6%E6%80%81%E4%B8%8B%EF%BC%8C%E9%82%A3%E4%B9%88**%E6%80%BB%E5%B8%A6%E5%AE%BD**%E4%B8%BA%EF%BC%88%20%EF%BC%89%C2%A0%0A%3E%E8%A7%A3%EF%BC%9A%E5%BF%BD%E7%95%A5%2010%2F100%20%E4%B8%AD%E7%9A%84%2010%EF%BC%8C%E5%BD%93%E6%88%90%20100%20Mbps%20%E5%B0%B1%E5%A5%BD%E3%80%8212%20*%20100%20%2B%202%20*%201000%20%3D%203200%EF%BC%8C%E5%8F%88%E5%9B%A0%E4%B8%BA%E5%85%A8%E5%8F%8C%E5%B7%A5%E6%89%80%E4%BB%A5%E4%B9%98%E4%BB%A5%202%20%E5%BE%97%206400%20Mbps%20%2C%E5%8D%B3%206.4%20Gbps%0A%3E*%20%E6%9F%90%E4%BA%A4%E6%8D%A2%E6%9C%BA%E6%9C%89%2016%E4%B8%AA100%2F1000%20Mbps%20%E5%85%A8%E5%8F%8C%E5%B7%A5**%E4%B8%8B%E8%81%94%E7%AB%AF%E5%8F%A3**%EF%BC%8C%E9%82%A3%E4%B9%88**%E4%B8%8A%E8%81%94%E7%AB%AF%E5%8F%A3**%E5%B8%A6%E5%AE%BD%E8%87%B3%E5%B0%91%E4%B8%BA%EF%BC%88%20%EF%BC%89%C2%A0%0A%3E%E8%A7%A3%EF%BC%9A16%20*%201000%20*%202%20%3D%2032000%20Mbps%20%3D%2032%20Gbps%EF%BC%8C**%E4%B8%8A%E8%81%94%E4%B8%80%E8%88%AC%E6%98%AF%E4%B8%8B%E8%81%94%E7%9A%84%201%2F20**%C2%A0%EF%BC%8C%E6%89%80%E4%BB%A5%E8%87%B3%E5%B0%91%E4%B8%BA%2032%20%E9%99%A4%E4%BB%A5%2020%20%E5%BE%97%201.6%20Gbps%0A%0A3.%E7%B3%BB%E7%BB%9F%E5%8F%AF%E7%94%A8%E6%80%A7%E4%B8%8E%E5%81%9C%E6%9C%BA%E6%97%B6%E9%97%B4%0A%0A%7C%E5%8F%AF%E7%94%A8%E6%80%A7%7C%E5%81%9C%E6%9C%BA%E6%97%B6%E9%97%B4%7C%0A%7C%20---%20%7C%20---%20%7C%0A%7C99.9%25%7C%E2%89%A48.8%E5%B0%8F%E6%97%B6%7C%0A%7C99.99%25%7C%E2%89%A453%E5%88%86%E9%92%9F%7C%0A%7C99.999%25%7C%E2%89%A45%E5%88%86%E9%92%9F%7C%0A%0A4.%20%E5%86%99%E5%9C%B0%E5%9D%80%E5%9D%97%E7%9A%84%E5%AD%90%E7%BD%91%E6%8E%A9%E7%A0%81%0A%3E*%20%E4%BE%8B%EF%BC%9AIP%20%E5%9C%B0%E5%9D%80%E5%9D%97%2059.67.159.125%2F11%20%E7%9A%84%E5%AD%90%E7%BD%91%E6%8E%A9%E7%A0%81%E5%8F%AF%E5%86%99%E4%B8%BA%EF%BC%88%20%EF%BC%89%0A%3E%E8%A7%A3%EF%BC%9A%E4%B8%8D%E7%94%A8%E7%9C%8B%20IP%20%E5%9C%B0%E5%9D%80%EF%BC%8C%E5%8F%AA%E7%9C%8B%C2%A0%2F11%C2%A0%E5%B0%B1%E5%A4%9F%E4%BA%86%E3%80%82%C2%A011%20%E4%BB%A3%E8%A1%A8%E5%AD%90%E7%BD%91%E6%8E%A9%E7%A0%81%E7%9A%84%E5%89%8D%2011%20%E4%BD%8D%E9%83%BD%E6%98%AF%201%20%EF%BC%8C%E6%89%80%E4%BB%A5%E5%8F%AF%E4%BB%A5%E5%86%99%E5%87%BA%E5%AD%90%E7%BD%91%E6%8E%A9%E7%A0%81%2011111111.11100000.00000000.00000000%20%E8%BD%AC%E6%8D%A2%E4%B8%BA%E5%8D%81%E8%BF%9B%E5%88%B6%E5%8D%B3%E6%98%AF%20255.224.0.0%C2%A0%0A%0A%23%23%23%23%23%205.%20%E7%BD%91%E7%BB%9C%E5%9C%B0%E5%9D%80%E8%BD%AC%E6%8D%A2%20NAT%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/2347a20d-0da4-444f-8233-f881cd6272fe.png.png%5D(en-resource%3A%2F%2Fdatabase%2F489%3A1)%0A%3E*%20%E4%BC%9A%E7%BB%99%E4%BD%A0%E4%B8%80%E4%B8%AA%E8%BF%99%E6%A0%B7%E7%9A%84%E5%9B%BE%EF%BC%8C%E9%97%AE%E4%BD%A0%20%E2%91%A0%20%E2%91%A1%20%E6%98%AF%E4%BB%80%E4%B9%88%C2%A0%E5%8F%AA%E9%9C%80%E8%A6%81%E7%9F%A5%E9%81%93%E2%91%A1%E5%92%8C%E7%B4%A7%E6%8C%A8%E7%9D%80%E5%AE%83%E7%9A%84%20S%20%E6%95%B0%E5%AD%97%E7%9B%B8%E5%90%8C%EF%BC%8C%E6%89%80%E4%BB%A5%E2%91%A1%E5%BA%94%E8%AF%A5%E6%98%AF%20202.0.1.1%2C5001%20%3B%E5%90%8C%E7%90%86%EF%BC%8C%E2%91%A0%E6%98%AF%2010.0.0.1%2C3342%E3%80%82%C2%A0%E8%BF%98%E6%9C%89%E6%97%B6%E5%80%99%E4%BC%9A%E9%97%AE%E6%9F%90%E4%B8%AA%E5%B0%8F%E6%96%B9%E6%A1%86%E9%87%8C%E7%9A%84%20S%2CD%20%E5%88%86%E5%88%AB%E6%98%AF%E4%BB%80%E4%B9%88%EF%BC%8C%E7%9C%8B%E4%B8%8A%E9%9D%A2%E7%9A%84%E5%9B%BE%E4%BD%A0%E4%BC%9A%E5%8F%91%E7%8E%B0%EF%BC%8C%E4%B8%8A%E9%9D%A2%E4%B8%A4%E4%B8%AA%E6%96%B9%E6%A1%86%E5%92%8C%E4%B8%8B%E9%9D%A2%E4%B8%A4%E4%B8%AA%E6%96%B9%E6%A1%86%E9%87%8C%E7%9A%84%E6%95%B0%E5%AD%97%E6%98%AF%E5%AF%B9%E7%A7%B0%E7%9A%84%EF%BC%8C%E5%81%9A%E9%A2%98%E6%97%B6%E5%AF%B9%E7%A7%B0%E4%B8%80%E4%B8%8B%E5%B0%B1%E5%86%99%E5%87%BA%E7%AD%94%E6%A1%88%E4%BA%86%E3%80%82%0A%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/59bbe5a2-1403-4c23-a939-2db1ecd79e7e.png.png%5D(en-resource%3A%2F%2Fdatabase%2F635%3A1)%0A%0A%0A%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/9b9ae9b7-5d1b-46f2-aef8-6bb1e264d189.png.png%5D(en-resource%3A%2F%2Fdatabase%2F627%3A1)%0A%0A--%20-%0A6.%20%C2%A0IP%20%E5%9C%B0%E5%9D%80%E5%9D%97%E8%81%9A%E5%90%88%0A%3E*%20%E7%AC%AC%E4%B8%80%E7%A7%8D%EF%BC%9A%E9%97%AE%E8%81%9A%E5%90%88%E5%90%8E%E7%9A%84%E5%9C%B0%E5%9D%80%E5%9D%97%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/cabe7911-6520-4a9b-8217-760b906017f3.png.png%5D(en-resource%3A%2F%2Fdatabase%2F488%3A1)%0A%E6%AD%A5%E9%AA%A4%E4%B8%BA%EF%BC%9A%E8%BD%AC%E6%88%90%E4%BA%8C%E8%BF%9B%E5%88%B6%EF%BC%9B%E5%AF%B9%E9%BD%90%E6%89%BE%E5%89%8D%E5%A4%9A%E5%B0%91%E4%BD%8D%E6%98%AF%E7%9B%B8%E5%90%8C%E7%9A%84%EF%BC%9B%E8%BD%AC%E5%9B%9E%E5%8D%81%E8%BF%9B%E5%88%B6%E5%86%99%E7%AD%94%E6%A1%88%E3%80%82%C2%A0%0A%0A%3E*%20%E7%AC%AC%E4%BA%8C%E7%A7%8D%EF%BC%9A%E9%97%AE%E8%81%9A%E5%90%88%E5%90%8E%E5%8F%AF%E7%94%A8%20IP%20%E6%95%B0%C2%A0%0A%3E%E3%80%90%E7%AC%AC%E4%B8%80%E7%A7%8D%E6%83%85%E5%86%B5%E3%80%91%E5%A6%82%E6%9C%AA%E6%9D%A5%E6%95%99%E8%82%B2%E4%B8%8A%E6%9C%BA%E8%80%83%E8%AF%95%E7%AC%AC%E4%B8%80%E5%A5%97%E8%AF%95%E9%A2%98%E7%AC%AC10%E9%A2%98%EF%BC%9A%C2%A0%0A%E2%80%9C%20IP%20%E5%9C%B0%E5%9D%80%E5%9D%97%20202.113.79.128%2F27%E3%80%81202.113.79.160%2F27%20%E5%92%8C%20202.113.79.192%2F27%20%E7%BB%8F%E8%BF%87%E8%81%9A%E5%90%88%E5%90%8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P%20%E5%9C%B0%E5%9D%80%E5%9D%97%20202.113.79.0%2F27%E3%80%81202.113.79.32%2F27%E3%80%81202.113.79.64%2F26%20%E7%BB%8F%E8%BF%87%E8%81%9A%E5%90%88%E5%90%8E%E5%8F%AF%E7%94%A8%E7%9A%84%E5%9C%B0%E5%9D%80%E6%95%B0%E4%B8%BA___%E2%80%9D%0A%E6%9C%AC%E9%A2%98%E4%B8%AD%E2%80%9C%2F%E2%80%9D%E5%90%8E%E8%BE%B9%E7%9A%84%E6%95%B0%E5%AD%97%E5%89%8D%E4%B8%A4%E4%B8%AA%E6%98%AF%E7%9B%B8%E5%90%8C%E7%9A%84%EF%BC%8C%E7%AC%AC%E4%B8%89%E4%B8%AA%E4%B8%8E%E5%89%8D%E4%B8%A4%E4%B8%AA%E4%B8%8D%E5%90%8C%E3%80%82%C2%A0%0A%E6%89%80%E4%BB%A5%E9%81%87%E5%88%B0%E8%BF%99%E7%A7%8D%E9%A2%98%EF%BC%8C%E7%9B%B4%E6%8E%A5%E5%B0%86%E4%B8%89%E4%B8%AA%20IP%20%E8%81%9A%E5%90%88%E5%BE%97%E5%88%B0%E5%9C%B0%E5%9D%80%E5%9D%97%EF%BC%8C202.113.79.0%2F25%0A%E7%84%B6%E5%90%8E%E6%B1%82%E5%87%BA%E4%B8%89%E4%B8%AA%20IP%20%E7%9A%84%E5%8F%AF%E7%94%A8%E5%9C%B0%E5%9D%80%E6%95%B0%E3%80%822%5E(32-25)-2%3D126%0A%0A7.%20%E8%B7%AF%E7%94%B1%E8%A1%A8%E8%B7%9D%E7%A6%BB%E6%9B%B4%E6%96%B0%0A%3E%20*%20R1%2CR2%20%E6%98%AF%E4%B8%80%E4%B8%AA%E7%B3%BB%E7%BB%9F%E4%B8%AD%E9%87%87%E7%94%A8RIP%E8%B7%AF%E7%94%B1%E5%8D%8F%E8%AE%AE%E7%9A%84%E4%B8%A4%E4%B8%AA%E7%9B%B8%E9%82%BB%E8%B7%AF%E7%94%B1%E5%99%A8%EF%BC%8CR1%20%E7%9A%84%E8%B7%AF%E7%94%B1%E8%A1%A8%E5%A6%82%EF%BC%88a%EF%BC%89%E6%89%80%E7%A4%BA%EF%BC%8C%C2%A0R1%20%E6%94%B6%E5%88%B0%20R2%20%E5%8F%91%E9%80%81%E7%9A%84%E6%8A%A5%E6%96%87%EF%BC%88b%EF%BC%89%E5%90%8E%EF%BC%8CR1%20%E6%9B%B4%E6%96%B0%E5%90%8E%E7%9A%84%E8%B7%9D%E7%A6%BB%E5%80%BC%E4%BB%8E%E4%B8%8A%E5%88%B0%E4%B8%8B%E4%BE%9D%E6%AC%A1%E6%98%AF%EF%BC%88%20%EF%BC%89%C2%A0%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/0bb252a5-173f-4df5-a240-7e6806ba704d.png.png%5D(en-resource%3A%2F%2Fdatabase%2F490%3A1)%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/0135653e-bba5-4176-9b28-e87b3b9abca0.png.png%5D(en-resource%3A%2F%2Fdatabase%2F491%3A1)%0A%E6%AD%A5%E9%AA%A4%E4%B8%BA%EF%BC%9Ab%E8%B7%9D%E7%A6%BB%2B1%EF%BC%9B%E4%B8%8Ea%E8%B7%9D%E7%A6%BB%E6%AF%94%E8%BE%83%EF%BC%9B%E6%9B%B4%E6%96%B0%E4%B8%BA%E8%B7%9D%E7%A6%BB%E6%9C%80%E5%B0%8F%E7%9A%84%E3%80%82%E5%88%99%E6%9B%B4%E6%96%B0%E5%90%8E%E7%9A%84%E8%B7%9D%E7%A6%BB%E5%80%BC%E4%BB%8E%E4%B8%8A%E5%88%B0%E4%B8%8B%E4%BE%9D%E6%AC%A1%E6%98%AF%200%E3%80%814%E3%80%814%E3%80%813%E3%80%812%0A%0A%3E*%20%E8%BF%98%E7%BB%8F%E5%B8%B8%E8%BF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23%3A%3A510%3A0%3A0%3A9C5B%EF%BC%8C%E5%9B%A0%E4%B8%BA%200510%20%E5%B0%B1%E6%98%AF%20510%20%EF%BC%8C%0A%3E%C2%A0%C2%A0%E4%B8%8D%E8%83%BD%E7%AE%80%E5%8C%96%E4%B8%BA%20FF23%3A%3A051%3A0%3A0%3A9C5B%EF%BC%8C%E5%9B%A0%E4%B8%BA%200510%20%E4%B8%8D%E6%98%AF%2051%E3%80%82%0A%0A%3E*%20%E4%BE%8B%EF%BC%9A%E4%B8%8B%E5%88%97%20IPv6%20%E5%9C%B0%E5%9D%80%E8%A1%A8%E7%A4%BA%E4%B8%AD%E9%94%99%E8%AF%AF%E7%9A%84%E6%98%AF%EF%BC%88%20%EF%BC%89%0A%3E%C2%A0A)%20%3A%3A10F%3ABC%3A0%3A0%3A03DA%C2%A0%0A%3E%C2%A0B)%20FE%3A%3A0%3A45%3A03%2F48%C2%A0%0A%3E%C2%A0C)%20FE31%3A0%3ABC%3A3E%3A0%3A050D%3ABC%3A%3A03DA%C2%A0%0A%3E%C2%A0D)%20FF34%3A42%3ABC%3A%3A3E%3A50F%3A21%3A03D%C2%A0%0A%3E%C2%A0%E8%A7%A3%EF%BC%9AIPv6%20%E5%9C%B0%E5%9D%80%E6%98%AF%20128%20%E4%BD%8D%E5%88%92%E5%88%86%E4%B8%BA%208%20%E6%AE%B5%E7%9A%84%E5%9C%B0%E5%9D%80%EF%BC%8C%E8%80%8C%20C%20%E9%A1%B9%E4%B8%8D%E7%AE%97%E5%8F%8C%E5%86%92%E5%8F%B7%E9%82%A3%E6%AE%B5%E5%B7%B2%E7%BB%8F%E6%9C%89%E4%BA%86%208%20%E6%AE%B5%EF%BC%8C%E5%8F%8C%E5%86%92%E5%8F%B7%E5%8F%88%E8%87%B3%E5%B0%91%E5%8E%8B%E7%BC%A9%E4%B8%80%E4%B8%AA%200%20%E4%BD%8D%E6%AE%B5%EF%BC%8C%E6%89%80%E4%BB%A5%E8%B6%85%E4%BA%86%208%20%E6%AE%B5%EF%BC%8C%E6%98%AF%E9%94%99%E8%AF%AF%E7%9A%84%E3%80%82%C2%A0%0A%0A9.%20%E6%95%B0%E6%8D%AE%E5%8C%85%0A%3E*%20%E4%BE%8B%EF%BC%9A%E4%B8%8B%E5%9B%BE%E6%98%AF%20A%20%E5%8F%91%E9%80%81%E7%9A%84%E6%95%B0%E6%8D%AE%E5%8C%85%E9%80%9A%E8%BF%87%E8%B7%AF%E7%94%B1%E5%99%A8%E8%BD%AC%E5%8F%91%E5%88%B0%20B%20%E7%9A%84%E8%BF%87%E7%A8%8B%E7%A4%BA%E6%84%8F%E5%9B%BE%EF%BC%8C%E6%B1%82%E6%95%B0%E6%8D%AE%E5%8C%85%203%20%E4%B8%AD%E7%9A%84%E7%9B%AE%E7%9A%84IP%E5%9C%B0%E5%9D%80%E5%92%8C%E7%9B%AE%E7%9A%84MAC%E5%9C%B0%E5%9D%80%C2%A0!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/9f3d73ab-71bd-4d2d-a1ad-c10465d5fd3c.png.png%5D(en-resource%3A%2F%2Fdatabase%2F492%3A1)%0A%3E%E8%A7%A3%EF%BC%9A%E6%97%A0%E8%AE%BA%E5%93%AA%E4%B8%AA%E6%95%B0%E6%8D%AE%E5%8C%85%EF%BC%8C%E7%9B%AE%E7%9A%84%20IP%20%E5%9C%B0%E5%9D%80%E5%B0%B1%E6%98%AF%20B%20%E7%9A%84%20IP%20%E5%9C%B0%E5%9D%80%EF%BC%8C%E6%89%80%E4%BB%A5%E6%95%B0%E6%8D%AE%E5%8C%85%203%20%E7%9A%84%E7%9B%AE%E7%9A%84%20IP%20%E4%B8%BA%20129.42.56.216%EF%BC%9B%C2%A0%E8%80%8C%E7%9B%AE%E7%9A%84%20MAC%20%E5%9C%B0%E5%9D%80%E5%B0%B1%E6%98%AF%E4%B8%8B%E4%B8%80%E4%B8%AA%E8%B7%AF%E7%94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8E%AF**%EF%BC%88%E9%A1%BA%E6%97%B6%E9%92%88%EF%BC%89%E5%92%8C**%E5%86%85%E7%8E%AF**%EF%BC%88%E9%80%86%E6%97%B6%E9%92%88%EF%BC%89**%E9%83%BD%E5%8F%AF%E4%BB%A5**%E7%94%A8%E4%BA%8E%E4%BC%A0%E8%BE%93%E5%88%86%E7%BB%84%E5%92%8C%E6%8E%A7%E5%88%B6%E5%88%86%E7%BB%84%0A%0A%23%23%23%23%23%202.%20%E6%97%A0%E7%BA%BF%E6%8E%A5%E5%85%A5%E6%8A%80%E6%9C%AF%0A*%20%E4%B8%BB%E8%A6%81%E6%9C%89%20WLAN%E3%80%81WiMAX%E3%80%81WiFi%E3%80%81WMAN%20%E5%92%8C%20Ad%20hoc%20(%20WiFi%20%E8%82%AF%E5%AE%9A%E7%9F%A5%E9%81%93%EF%BC%8C%E8%AE%B0%E4%BD%8F%E6%97%A0%E7%BA%BF%E6%8A%80%E6%9C%AF%E4%B8%80%E8%88%AC%E6%98%AFW%E5%BC%80%E5%A4%B4%E7%9A%84%EF%BC%8C%E4%BD%86%E6%9C%89%E4%B8%AA%E7%89%B9%E6%AE%8A%E7%9A%84A%E5%BC%80%E5%A4%B4)%0A*%20**APON%20%E4%B8%8D%E6%98%AF%E6%97%A0%E9%99%90%E4%BC%A0%E8%BE%93%E6%8A%80%E6%9C%AF**%EF%BC%8C%E8%BF%99%E4%B8%AA%E7%BB%8F%E5%B8%B8%E6%98%AF%E8%BF%B7%E6%83%91%E9%A1%B9%0A%0A%23%23%23%23%23%203.%20%E5%B9%BF%E5%9F%9F%E7%BD%91%20QoS%0A%E8%80%83%E7%9A%84%E6%97%B6%E5%80%99%E9%80%9A%E5%B8%B8%E5%8F%AA%E5%86%99%E8%8B%B1%E6%96%87%E7%BC%A9%E5%86%99%EF%BC%8C%E4%B8%8B%E9%9D%A2%E5%86%99%E4%B8%8A%E4%B8%AD%E6%96%87%E5%90%8D%E6%98%AF%E4%B8%BA%E4%BA%86%E6%96%B9%E4%BE%BF%E4%BD%A0%E8%AE%B0%E5%BF%86%EF%BC%88%E5%85%B6%E4%BB%96%E7%9A%84%E5%9C%B0%E6%96%B9%E4%B9%9F%E5%BA%94%E8%AF%A5%E5%85%BB%E6%88%90%E7%B2%97%E7%95%A5%E6%8E%A8%E6%B5%8B%E8%8B%B1%E6%96%87%E7%BC%A9%E5%86%99%E7%9A%84%E4%B9%A0%E6%83%AF%EF%BC%89%E4%B8%BB%E8%A6%81%E7%9A%84%E6%8A%80%E6%9C%AF%E6%9C%89%20%E8%B5%84%E6%BA%90%E9%A2%84%E7%95%99%EF%BC%88**RSVP**%EF%BC%89%E3%80%81%E5%8C%BA%E5%88%86%E6%9C%8D%E5%8A%A1%EF%BC%88**DiffServ**%EF%BC%89%E3%80%81%E5%A4%9A%E5%8D%8F%E8%AE%AE%E6%A0%87%E8%AE%B0%E4%BA%A4%E6%8D%A2%EF%BC%88**MPLS**%EF%BC%89%0A%0A%23%23%23%23%23%204.%20%E6%8E%A5%E5%85%A5%E6%8A%80%E6%9C%AF%E7%89%B9%E5%BE%81%0A*%20**ASDL**%20%E4%BD%BF%E7%94%A8%E4%B8%80%E5%AF%B9%E9%93%9C%E5%8F%8C%E7%BB%9E%E7%BA%BF%EF%BC%8C%E5%85%B7%E6%9C%89**%E9%9D%9E%E5%AF%B9%E7%A7%B0**%E6%8A%80%E6%9C%AF%E7%89%B9%E6%80%A7%EF%BC%8C%3Cu%3E%E4%B8%8A%E8%A1%8C%E9%80%9F%E7%8E%87%2064%20kbps~640%20kbps%3C%2Fu%3E%EF%BC%8C%3Cu%3E%E4%B8%8B%E8%A1%8C%E9%80%9F%E7%8E%87%20500%20kbps~7%20Mbps%3C%2Fu%3E%0A*%20%E9%87%87%E7%94%A8%20ADSL%20%E6%8A%80%E6%9C%AF%E5%8F%AF%E4%BB%A5%E9%80%9A%E8%BF%87%20PSTN%20%E6%8E%A5%E5%85%A5%20Internet%0A*%20**Cable%20Modom**%EF%BC%88%E7%94%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81%AF%0A*%20BGP%20%E9%87%87%E7%94%A8**%E8%B7%AF%E7%94%B1%E5%90%91%E9%87%8F**%E5%8D%8F%E8%AE%AE%EF%BC%8C%E8%80%8C%20RIP%20%E9%87%87%E7%94%A8%E8%B7%9D%E7%A6%BB%E5%90%91%E9%87%8F%E5%8D%8F%E8%AE%AE%0A*%20BGP%20%E5%8F%91%E8%A8%80%E4%BA%BA%E9%80%9A%E8%BF%87%20**update**%20%E8%80%8C%E4%B8%8D%E6%98%AF%20noticfication%20**%E5%88%86%E7%BB%84%E9%80%9A%E7%9F%A5%E7%9B%B8%E9%82%BB%E7%B3%BB%E7%BB%9F**%0A*%20**open**%20%E5%88%86%E7%BB%84%E7%94%A8%E6%9D%A5%E4%B8%8E%E7%9B%B8%E9%82%BB%E7%9A%84%E5%8F%A6%E4%B8%80%E4%B8%AA%20BGP%20%E5%8F%91%E8%A8%80%E4%BA%BA**%E5%BB%BA%E7%AB%8B%E5%85%B3%E7%B3%BB**%EF%BC%8C%E4%B8%A4%E4%B8%AA%20BGP%20%E5%8F%91%E8%A8%80%E4%BA%BA%E9%9C%80%E8%A6%81**%E5%91%A8%E6%9C%9F%E6%80%A7%E5%9C%B0%E4%BA%A4%E6%8D%A2**%20**keepalive**%20%E5%88%86%E7%BB%84%E6%9D%A5%E7%A1%AE%E8%AE%A4%E5%8F%8C%E6%96%B9%E7%9A%84%E7%9B%B8%E9%82%BB%E5%85%B3%E7%B3%BB%0A%0A%23%23%23%23%23%208.%20RIP%20%E5%8D%8F%E8%AE%AE%0A*%20**RIP**%20%E6%98%AF**%E5%86%85%E9%83%A8%E7%BD%91%E5%85%B3%E5%8D%8F%E8%AE%AE**%E4%B8%AD%E4%BD%BF%E7%94%A8%E6%9C%80%E5%B9%BF%E6%B3%9B%E7%9A%84%E4%B8%80%E7%A7%8D%E5%8D%8F%E8%AE%AE%EF%BC%8C%E5%AE%83%E6%98%AF%E4%B8%80%E7%A7%8D%E5%88%86%E5%B8%83%E5%BC%8F%E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9F%A5%E9%81%93%E5%85%B6%E4%BB%96%E5%8C%BA%E5%9F%9F%E7%9A%84%E7%BD%91%E7%BB%9C%E6%8B%93%E6%89%91**%EF%BC%88%E6%8B%93%E6%89%91%E7%9A%84%E6%84%8F%E6%80%9D%E6%98%AF%E9%93%BE%E6%8E%A5%E5%BD%A2%E5%BC%8F%E5%92%8C%E4%BD%8D%E7%BD%AE%E5%85%B3%E7%B3%BB%E4%B9%8B%E7%B1%BB%E7%9A%84%EF%BC%89%0A*%20%E9%93%BE%E8%B7%AF%E7%8A%B6%E6%80%81%E2%80%9C**%E5%BA%A6%E9%87%8F%E2%80%9D%E4%B8%BB%E8%A6%81%E6%8C%87%E8%B4%B9%E7%94%A8%E3%80%81%E8%B7%9D%E7%A6%BB%E3%80%81%E5%BB%B6%E6%97%B6%E3%80%81%E5%B8%A6%E5%AE%BD**%E7%AD%89%0A*%20OSPF%20%E9%87%87%E7%94%A8**%E6%B4%AA%E6%B3%9B%E6%B3%95**%E6%9C%80%E7%9F%AD%E4%BC%98%E5%85%88%E8%B7%AF%E5%BE%84%E5%90%91**%E6%89%80%E6%9C%89**%E8%B7%AF%E7%94%B1%E5%99%A8%E5%8F%91%E9%80%81%E6%B6%88%E6%81%AF%0A*%20%E9%80%9A%E8%BF%87**%E5%8C%BA%E5%9F%9F%E5%88%92%E5%88%86%E6%8F%90%E9%AB%98%E6%94%B6%E6%95%9B%E9%80%9F%E5%BA%A6**%0A%0A%0A%23%23%23%23%23%2010.%20%E9%9B%86%E7%BA%BF%E5%99%A8%0A*%20%E5%B7%A5%E4%BD%9C%E5%9C%A8**%E7%89%A9%E7%90%86%E5%B1%82**%EF%BC%8C%E8%BF%9E%E6%8E%A5%E5%88%B0%E4%B8%80%E4%B8%AA%E9%9B%86%E7%BA%BF%E5%99%A8%E7%9A%84%E6%89%80%E6%9C%89%E7%BB%93%E7%82%B9**%E5%85%B1%E4%BA%AB%E4%B8%80%E4%B8%AA%E5%86%B2%E7%AA%81%E5%9F%9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E6%9C%BA%EF%BC%8C%E7%94%A8%E4%BA%8E%E5%8A%A0%E5%BF%AB%E5%A4%A7%E5%9E%8B%E5%B1%80%E5%9F%9F%E7%BD%91%E5%86%85%E9%83%A8%E7%9A%84%E6%95%B0%E6%8D%AE%E4%BA%A4%E6%8D%A2%0A%0A%23%23%23%23%23%2012.%20%E8%B7%AF%E7%94%B1%E5%99%A8%0A*%20**%E4%B8%A2%E5%8C%85%E7%8E%87**%E6%98%AF%E8%A1%A1%E9%87%8F%E8%B7%AF%E7%94%B1%E5%99%A8**%E8%B6%85%E8%B4%9F%E8%8D%B7**%E5%B7%A5%E4%BD%9C%E6%97%B6%E7%9A%84%E6%80%A7%E8%83%BD%E6%8C%87%E6%A0%87%E4%B9%8B%E4%B8%80%0A*%20**%E8%83%8C%E6%9D%BF**%E8%83%BD%E5%8A%9B%E5%86%B3%E5%AE%9A%E8%B7%AF%E7%94%B1%E5%99%A8**%E5%90%9E%E5%90%90%E9%87%8F**%0A*%20**%E5%90%9E%E5%90%90%E9%87%8F%E6%8C%87%E5%8C%85%E8%BD%AC%E5%8F%91%E8%83%BD%E5%8A%9B**%0A*%20**%E4%BC%A0%E7%BB%9F**%E8%B7%AF%E7%94%B1%E5%99%A8%E4%B8%80%E8%88%AC%E9%87%87%E7%94%A8**%E5%85%B1%E4%BA%AB%E8%83%8C%E6%9D%BF**%E7%9A%84%E7%BB%93%E6%9E%84%EF%BC%8C**%E9%AB%98%E6%80%A7%E8%83%BD**%E8%B7%AF%E7%94%B1%E5%99%A8%E4%B8%80%E8%88%AC%E9%87%87%E7%94%A8**%E4%BA%A4%E6%8D%A2%E5%BC%8F**%E7%9A%84%E7%BB%93%E6%9E%84%0A*%20%E7%AA%81%E5%8F%91%E5%A4%84%E7%90%86%E8%83%BD%E5%8A%9B%E4%B8%8D%E6%98%AF%E4%BB%A5%E6%9C%80%E5%B0%8F%E5%B8%A7%E9%97%B4%E9%9A%94%E5%80%BC%E6%9D%A5%E8%A1%A1%E9%87%8F%E7%9A%84%0A*%20**%E8%AF%AD%E9%9F%B3%E8%A7%86%E9%A2%91%E4%B8%9A%E5%8A%A1%E5%AF%B9%E5%BB%B6%E6%97%B6%E6%8A%96%E5%8A%A8%E8%A6%81%E6%B1%82%E8%BE%83%E9%AB%98**%E9%AB%98%E7%AB%AF%E8%B7%AF%E7%94%B1%E5%99%A8%E5%BA%94%E8%BE%BE%E5%88%B0%EF%BC%9A%E6%97%A0%E6%95%85%E9%9A%9C%E8%BF%9E%E7%BB%AD%E5%B7%A5%E4%BD%9C%E6%97%B6%E9%97%B4%E5%A4%A7%E4%BA%8E%2010%20%E4%B8%87%E5%B0%8F%E6%97%B6%EF%BC%9B%E6%95%85%E9%9A%9C%E6%81%A2%E5%A4%8D%E6%97%B6%E9%97%B4%E5%B0%8F%E4%BA%8E%2030%20%E5%88%86%E9%92%9F%EF%BC%9B%E5%88%87%E6%8D%A2%E6%97%B6%E9%97%B4%E5%B0%8F%E4%BA%8E%2050%20%E6%AF%AB%E7%A7%92%0A%0A%23%23%23%23%23%2013.%20IEEE%20802.11%0A*%20IEEE%20802.11%20%E6%9C%80%E5%88%9D%E5%AE%9A%E4%B9%89%E7%9A%84%E4%B8%89%E4%B8%AA%E7%89%A9%E7%90%86%E5%B1%82%E5%8C%85%E6%8B%AC%E4%BA%86%E4%B8%A4%E4%B8%AA%E6%89%A9%E9%A2%91%E6%8A%80%E6%9C%AF%E5%92%8C%E4%B8%80%E4%B8%AA%E7%BA%A2%E5%A4%96%E4%BC%A0%E6%92%AD%E8%A7%84%E8%8C%83%EF%BC%8C%E6%97%A0%E7%BA%BF%E9%A2%91%E9%81%93%E5%AE%9A%E4%B9%89%E5%9C%A8%202.4GHz%20ISM%E9%A2%91%E6%AE%B5%EF%BC%8C%E4%BC%A0%E8%BE%93%E9%80%9F%E5%BA%A6%201~2%20Mbps%0A*%20802.11**b**%C2%A0%E6%9C%80%E5%A4%A7**%E5%AE%B9%E9%87%8F%2033**%20Mbps%EF%BC%8C%E5%B0%86%E4%BC%A0%E8%BE%93%E9%80%9F%E7%8E%87%E6%8F%90%E9%AB%98%E5%88%B0%C2%A0**11**%20Mbps%EF%BC%8C%0A*%20802.11**a**%C2%A0%E5%B0%86%E4%BC%A0%E8%BE%93**%E9%80%9F%E7%8E%87**%E6%8F%90%E9%AB%98%E5%88%B0%C2%A0**54**%20Mbps%20**%E5%AE%B9%E9%87%8F%20%20432**%20**%E5%90%9E%E5%90%90%E9%87%8F28-31**%0A*%20802.11**g**%20**54**Mbps%EF%BC%8C%E5%B7%A5%E4%BD%9C%E5%9C%A8**ISM%E9%A2%91%E6%AE%B5**%20**%E5%AE%B9%E9%87%8F%20%20162**%20**%E5%90%9E%E5%90%90%E9%87%8F28-31**%0A*%20IEEE%20802.11d%20%E6%98%AF%E5%BD%93%E5%89%8D%E6%9C%80%E6%B5%81%E8%A1%8C%E7%9A%84%20STP%EF%BC%88%E7%94%9F%E6%88%90%E6%A0%91%E5%8D%8F%E8%AE%AE%EF%BC%89%E6%A0%87%E5%87%86%0A*%20IEEE%20802.11b%20%E6%A0%87%E5%87%86%E4%BD%BF%E7%94%A8%E7%9A%84%E6%98%AF%E5%BC%80%E6%94%BE%E7%9A%84%202.4GHZ%20%E9%A2%91%E6%AE%B5%EF%BC%8C%E6%97%A0%E9%A1%BB%E7%94%B3%E8%AF%B7%E5%B0%B1%E5%8F%AF%E4%BB%A5%E7%9B%B4%E6%8E%A5%E4%BD%BF%E7%94%A8%0A%0A%23%23%23%23%23%2014.%20%E8%93%9D%E7%89%99%0A*%20%E5%90%8C%E6%AD%A5%E4%BF%A1%E9%81%93%E9%80%9F%E7%8E%87%2064%20kbps%EF%BC%8C%E8%B7%B3%E9%A2%91%E9%80%9F%E7%8E%87%E4%B8%BA%201600%20%E6%AC%A1%2Fs%0A*%20**%E5%B7%A5%E4%BD%9C**%E5%9C%A8%20**2.402%20~%202.480**%20GHz%20%E7%9A%84%20**ISM%20%E9%A2%91%E6%AE%B5**%0A*%20**%E9%9D%9E%E5%AF%B9%E7%A7%B0%E7%9A%84%E5%BC%82%E6%AD%A5%E4%BF%A1%E9%81%93%E9%80%9F%E7%8E%87**%E4%B8%BA%20**723.2%20kbps%20%2F%2057.6**%20kbps%0A*%20**%E5%AF%B9%E7%A7%B0%E7%9A%84%E5%BC%82%E6%AD%A5%E4%BF%A1%E9%81%93%E9%80%9F%E7%8E%87%E4%B8%BA%20433.9**%20kbps%0A*%20**%E5%8F%91%E5%B0%84%E5%8A%9F%E7%8E%87**%20%20%20**0dbm%EF%BC%9A1-10m**%20%20%20%20%20%7C%20%20%20%20**20dbm%EF%BC%9A100m**%0A%0A%23%23%23%23%23%2015.%20Serv-U%20FTP%20%E6%9C%8D%E5%8A%A1%E5%99%A8%0A*%20%E4%BD%BF%E7%94%A8%E5%8A%A8%E6%80%81%20IP%20%E5%9C%B0%E5%9D%80%E6%97%B6%EF%BC%8C%E6%9C%8D%E5%8A%A1%E5%99%A8%20IP%20%E5%9C%B0%E5%9D%80%E5%BA%94%E9%85%8D%E7%BD%AE%E4%B8%BA%E7%A9%BA%EF%BC%8C%E8%80%8C%E4%B8%8D%E6%98%AF%200.0.0.0%E3%80%82%EF%BC%88%E4%B8%BA%E7%A9%BA%E4%BB%A3%E8%A1%A8%E5%85%A8%E9%83%A8%20IP%20%E5%9C%B0%E5%9D%80%EF%BC%89%0A*%20%E6%AF%8F%E4%B8%AA%20Serv-U%20FTP%20%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%AD%E7%9A%84%E8%99%9A%E6%8B%9F%E6%9C%8D%E5%8A%A1%E5%99%A8%E7%94%B1%C2%A0IP%20%E5%9C%B0%E5%9D%80%E5%92%8C%E7%AB%AF%E5%8F%A3%E5%8F%B7%E5%94%AF%E4%B8%80%E8%AF%86%E5%88%AB%EF%BC%8C%E8%80%8C%E4%B8%8D%E6%98%AF%E4%BE%9D%E9%9D%A0%20IP%20%E5%9C%B0%E5%9D%80%0A*%20%E5%90%91%E6%9C%8D%E5%8A%A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E%E4%BB%B6%E6%97%B6%E9%80%9A%E5%B8%B8%E9%87%87%E7%94%A8%20POP3%20%E6%88%96%E8%80%85%20IMAP%20%E5%8D%8F%E8%AE%AE%E3%80%82Winmail%20%E7%94%A8%E6%88%B7%E4%BD%BF%E7%94%A8%E6%B5%8F%E8%A7%88%E5%99%A8%E6%9F%A5%E7%9C%8B%E9%82%AE%E4%BB%B6%E4%BC%9A%E4%BD%BF%E7%94%A8%E5%88%B0%20HTTP%20%E5%8D%8F%E8%AE%AE%0A*%20%3Cu%3E%E9%82%AE%E4%BB%B6%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%8F%AF%E4%BB%A5%E8%AE%BE%E7%BD%AE%20%E7%94%A8%E6%88%B7%E5%90%8D%EF%BC%8C%E5%9F%9F%E5%90%8D%EF%BC%8C%E7%94%A8%E6%88%B7%E5%AF%86%E7%A0%81%20%EF%BC%8C%E4%B8%8D%E8%83%BD%E8%AE%BE%E7%BD%AE%E7%AE%A1%E7%90%86%E5%91%98%3C%2Fu%3E%0A%0A%0A%0A%23%23%23%23%23%2023.%20%E7%BD%91%E7%BB%9C%E6%94%BB%E5%87%BB%0A*%20**DDos%20%E6%94%BB%E5%87%BB**%EF%BC%9A%E5%88%A9%E7%94%A8%E5%B7%B2%E7%BB%8F%E6%94%BB%E5%8D%A0%E7%9A%84%E5%A4%9A%E4%B8%AA%E7%B3%BB%E7%BB%9F%E5%90%91%E7%9B%AE%E6%A0%87%E6%94%BB%E5%87%BB%EF%BC%8C%E8%A2%AB%E5%AE%B3%E8%AE%BE%E5%A4%87%E9%9D%A2%E5%AF%B9%E5%A4%A7%E9%87%8F**%E8%AF%B7%E6%B1%82%E6%97%A0%E6%B3%95%E6%AD%A3%E5%B8%B8%E5%A4%84%E7%90%86**%E8%80%8C**%E6%8B%92%E7%BB%9D%E6%9C%8D%E5%8A%A1**%0A*%20**SYN%20Flooding**%20%E6%94%BB%E5%87%BB%EF%BC%9A%E5%88%A9%E7%94%A8%20**TCP%20%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*%20VLAN%20ID%E7%9A%84%E5%8F%96%E5%80%BC%E8%8C%83%E5%9B%B4%E6%98%AF%201~**4094**%E3%80%82%E7%94%A8**12bit**%E8%A1%A8%E7%A4%BA%E3%80%82%E5%85%B6%E4%B8%AD%E6%97%A0%E6%B3%95%E6%89%A7%E8%A1%8C%E2%80%9Cno%20vlan%201%E2%80%9D%E5%91%BD%E4%BB%A4%0A*%20Ethernet%20vlanid%201-1000%0A*%20%E5%B1%9E%E4%BA%8E**%E6%95%B0%E6%8D%AE%E9%93%BE%E8%B7%AF%E5%B1%82**%0A%0A%23%23%23%23%23%2026.%20Cisco%20%E8%B7%AF%E7%94%B1%E5%99%A8%E4%B8%8A%E7%9A%84%E5%AD%98%E5%82%A8%E5%99%A8%0A%3E*%20configure%20terminal%EF%BC%9Aglobal%20configuration%20%0A%3E*%20**privilege**%20EXEC%20%E7%89%B9%E6%9D%83%E6%A8%A1%E5%BC%8F%20%E5%9C%A8%E7%94%A8%E6%88%B7%E6%A8%A1%E5%BC%8F%20**%E4%B8%8B%E8%BE%93%E5%85%A5enable**%0A%3E*%20setup%20%E8%AE%BE%E7%BD%AE%E6%A8%A1%E5%BC%8F%E5%88%9A%E5%87%BA%E5%8E%82%0A%3E*%20RXBOOT%20%20%E7%BB%B4%E6%8A%A4%E6%A8%A1%E5%BC%8F%20%20%E5%AF%86%E7%A0%81%E6%81%A2%E5%A4%8D%20%0A%3E%E7%9B%91%E8%A7%86%E6%A8%A1%E5%BC%8F%20%EF%BC%9A%E7%B3%BB%E7%BB%9F%E6%98%A0%E5%83%8F%E6%9B%B4%E6%96%B0%EF%BC%8C%E5%8F%A3%E4%BB%A4%E6%81%A2%E5%A4%8D%0A%0A%3ECisco%20Aironet%201100%E5%BF%AB%E9%80%9F%E9%85%8D%E7%BD%AE%E9%A1%B5%E9%9D%A2%0ABroadcast%20SSID%20in%20Beacon%3A%E5%85%81%E8%AE%B8%E8%AE%BE%E5%A4%87%E4%B8%8D%E6%8C%87%E5%AE%9ASSID%0Aconfiguration%20server%20protocol%20%3A%E8%87%AA%E5%8A%A8%E5%88%86%E9%85%8Dip%0Aip%20address%3A%20%E8%AE%BE%E7%BD%AE%E6%8E%A5%E5%85%A5%E7%82%B9ip%0Aradio%20server%20set%20ID%EF%BC%9A%20%E8%BE%93%E5%85%A5%E7%BD%91%E7%BB%9C%E7%AE%A1%E7%90%86%E5%91%98SSID%0A%0A*%20Flash%20%E4%B8%BB%E8%A6%81%E7%94%A8%E4%BA%8E%E5%AD%98%E5%82%A8%E5%BD%93%E5%89%8D%E4%BD%BF%E7%94%A8%E7%9A%84%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E6%98%A0%E5%83%8F%E6%96%87%E4%BB%B6%E5%92%8C%E5%BE%AE%E4%BB%A3%E7%A0%81%0A*%20NVRAM%20%E4%B8%BB%E8%A6%81%E5%AD%98%E5%82%A8%E5%90%AF%E5%8A%A8%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E6%88%96%E5%A4%87%E4%BB%BD%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%0A*%20RAM%20%E4%B8%BB%E8%A6%81%E5%AD%98%E5%82%A8%E8%B7%AF%E7%94%B1%E8%A1%A8%E3%80%81%E5%BF%AB%E9%80%9F%E4%BA%A4%E6%8D%A2%E7%BC%93%E5%AD%98%E3%80%81ARP%20%E7%BC%93%E5%AD%98%E3%80%81%E6%95%B0%E6%8D%AE%E5%88%86%E7%BB%84%E7%BC%93%E5%86%B2%E5%8C%BA%E5%92%8C%E7%BC%93%E5%86%B2%E9%98%9F%E5%88%97%E3%80%81%E8%BF%90%E8%A1%8C%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E7%AD%89%0A*%20**ROM**%20%E4%B8%BB%E8%A6%81%E7%94%A8%E6%9D%A5**%E6%B0%B8%E4%B9%85**%E4%BF%9D%E5%AD%98%E8%B7%AF%E7%94%B1%E5%99%A8%E7%9A%84%E5%BC%80%E6%9C%BA%E8%AF%8A%E6%96%AD%E7%A8%8B%E5%BA%8F%E3%80%81%E5%BC%95%E5%AF%BC%E7%A8%8B%E5%BA%8F%E5%92%8C%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E8%BD%AF%E4%BB%B6%0A%0A%23%23%23%23%23%2027.%20%E9%98%B2%E7%81%AB%E5%A2%99%E5%AF%B9%E5%BA%94%E7%AB%AF%E5%8F%A3%E7%9A%84%E8%BF%9E%E6%8E%A5%E6%96%B9%E6%A1%88%0Apix525%20%E5%9C%A8%E7%BC%BA%E7%9C%81%E6%83%85%E5%86%B5%E4%B8%8B%0A*%20ethernet0%20%E8%A2%AB%E5%91%BD%E5%90%8D%E4%B8%BA%E5%A4%96%E9%83%A8%E6%8E%A5%E5%8F%A3%20**outside**%EF%BC%8C%E5%AE%89%E5%85%A8%E7%BA%A7%E5%88%AB%E6%98%AF%20**0**%0A*%20ethernet1%20%E8%A2%AB%E5%91%BD%E5%90%8D%E4%B8%BA%E5%86%85%E9%83%A8%E6%8E%A5%E5%8F%A3%20**inside**%EF%BC%8C%E5%AE%89%E5%85%A8%E7%BA%A7%E5%88%AB%E6%98%AF%20**100**%0A*%20ethernet2%20%E8%A2%AB%E5%91%BD%E5%90%8D%E4%B8%BA%E4%B8%AD%E9%97%B4%E6%8E%A5%E5%8F%A3%20**dmz**%EF%BC%8C%E5%AE%89%E8%A3%85%E7%BA%A7%E5%88%AB%E6%98%AF%20**50**%0A%0A%23%23%23%23%23%2028.%20STP%20%E7%94%9F%E6%88%90%E6%A0%91%E7%BB%93%E6%9E%84%0A*%20STP%E8%BF%90%E8%A1%8C%E5%9C%A8**%E4%BA%A4%E6%8D%A2%E6%9C%BA%E5%92%8C%E7%BD%91%E6%A1%A5%E4%B8%8A**%0A*%20**IEEE802.1D%E6%9C%80%E6%97%A9%E7%9A%84**%0A*%20%E6%97%A0%E8%AE%BA%E6%98%AF%E6%A0%B9%E7%9A%84%E7%A1%AE%E5%AE%9A%EF%BC%8C%E8%BF%98%E6%98%AF%E6%A0%91%E7%8A%B6%E7%BB%93%E6%9E%84%E7%9A%84%E7%94%9F%E6%88%90%EF%BC%8C%E4%B8%BB%E8%A6%81%E4%BE%9D%E9%9D%A0%20BPDU%20%E6%8F%90%E4%BE%9B%E7%9A%84%E4%BF%A1%E6%81%AF%0A*%20Bridge%20ID%20%E7%94%B1**2%E4%B8%AA%E5%AD%97%E8%8A%82%E7%9A%84%E4%BC%98%E5%85%88%E7%BA%A7%E5%80%BC**%E5%92%8C%20**6%20%E4%B8%AA%E5%AD%97%E8%8A%82%E7%9A%84%E4%BA%A4%E6%8D%A2%E6%9C%BA%20MAC%20%E5%9C%B0%E5%9D%80**%E7%BB%84%E6%88%90%EF%BC%8C**%E4%BC%98%E5%85%88%E7%BA%A7%E5%8F%96%E5%80%BC%E8%8C%83%E5%9B%B4%E6%98%AF0~61440%EF%BC%8C%E5%A2%9E%E5%80%BC%E9%87%8F%E6%98%AF4096**%EF%BC%8C%E4%BC%98%E5%85%88%E5%80%BC%E8%B6%8A%E5%B0%8F%EF%BC%8C%E4%BC%98%E5%85%88%E7%BA%A7%E8%B6%8A%E9%AB%98%0A*%20MAC%20%E5%9C%B0%E5%9D%80**%E6%9C%80%E5%B0%8F**%E7%9A%84%E4%B8%BA**%E6%A0%B9%E7%BD%91%E6%A1%A5**%0A*%20BPDU%20%E6%95%B0%E6%8D%AE%E5%8C%85%E6%9C%89%E4%B8%A4%E7%A7%8D%E7%B1%BB%E5%9E%8B%EF%BC%8C**%E9%85%8D%E7%BD%AE%20BPDU**%20%E4%B8%8D%E8%B6%85%E8%BF%87%20**35%20%E4%B8%AA%E5%AD%97%E8%8A%82**%EF%BC%8C**%E6%8B%93%E6%89%91**%E5%8F%98%E5%8C%96%E9%80%9A%E7%9F%A5%20BPDU%20%E4%B8%8D%E8%B6%85%E8%BF%87%20**4%20%E4%B8%AA%E5%AD%97%E8%8A%82**%0A*%20BPDU%E6%AF%8F%E9%9A%94**2%E7%A7%92**%E5%8F%91%E9%80%81%E4%B8%80%E6%AC%A1%EF%BC%8C**%E6%95%85%E9%9A%9C%E5%8F%98%E5%8C%96%E5%8F%91%E9%80%81%E6%96%B0%E7%9A%84**%0A%0A29.%20Catelyst%20%E9%85%8D%E7%BD%AE%E5%91%BD%E4%BB%A4%0A*%20Catelyst3548%20%E8%AE%BE%E7%BD%AE%E6%97%B6%E9%97%B4%E7%9A%84%E6%A0%BC%E5%BC%8F%E6%98%AF%EF%BC%9Aclock%20set%20%E5%B0%8F%E6%97%B6%3A%E5%88%86%E9%92%9F%3A%E7%A7%92%20%E6%97%A5%20%E6%9C%88%20%E5%B9%B4%0A*%20Catelyst6500%20%E8%AE%BE%E7%BD%AE%E6%97%B6%E9%97%B4%E7%9A%84%E6%A0%BC%E5%BC%8F%E6%98%AF%EF%BC%9Aset%20time%20%E6%98%9F%E6%9C%9F%20%E6%9C%88%2F%E6%97%A5%2F%E5%B9%B4%20%E5%B0%8F%E6%97%B6%20%E5%88%86%E9%92%9F%20%E7%A7%92%0A%0A%23%23%23%23%23%2030.%20windows2003%20%E5%91%BD%E4%BB%A4%0Aipconfig%EF%BC%9Atcp%2Fip%E7%BD%91%E7%BB%9C%E9%85%8D%E7%BD%AE%0Anet%20view%EF%BC%9A%E5%9F%9F%E5%88%97%E8%A1%A8%EF%BC%8C%E8%AE%A1%E7%AE%97%E6%9C%BA%E5%88%97%E8%A1%A8%0Anbtstat%20-a%20%3A%20%E8%BF%9C%E7%A8%8B%E8%AE%A1%E7%AE%97%E6%9C%BA%0Anslookup%EF%BC%9Ainternet%E5%9F%9F%E5%90%8D%E4%BF%A1%E6%81%AF%EF%BC%8C%E8%AF%8A%E6%96%ADDNS%0Anetstat%EF%BC%9Atcp%E8%BF%9E%E6%8E%A5%EF%BC%8C%E6%9C%AC%E5%9C%B0%E5%9C%B0%E5%9D%80%EF%BC%8C%E5%A4%96%E9%83%A8%E5%9C%B0%E5%9D%80%EF%BC%8C%E7%8A%B6%E6%80%81%0A%23%23%20%E5%A4%A7%E9%A2%98%0A1.%20%E5%A1%AB%E5%9C%B0%E5%9D%80%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/c39b1b15-31a1-4d3c-81df-0a0e3b824e3f.png.png%5D(en-resource%3A%2F%2Fdatabase%2F621%3A1)%0A%0A%E5%B7%B2%E7%9F%A5ip%E5%9C%B0%E5%9D%80%E5%92%8C%E5%AD%90%E7%BD%91%E6%8E%A9%E7%A0%81%E6%B1%82%E5%85%B6%E4%BB%96%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/b2059bdd-df26-4900-873b-09afda841f29.png.png%5D(en-resource%3A%2F%2Fdatabase%2F493%3A1)%0A%0A%E4%B8%BB%E6%9C%BA%E4%BD%8D%E5%89%8D%E9%9D%A20%E7%9A%84%E4%B8%AA%E6%95%B0%E5%B0%B1%E6%98%AF%E5%AD%90%E7%BD%91%E6%8E%A9%E7%A0%811%E7%9A%84%E4%B8%AA%E6%95%B0%0A%0A%0A*%20*%20*%0A%0A2.%20%E8%AE%A1%E7%AE%97%E5%AD%90%E7%BD%91%E6%8E%A9%E7%A0%81%E5%92%8C%20IP%20%E6%AE%B5%E9%83%A8%E5%88%86%0A%0A%E5%B0%86%20192.168.66.128%2F25%20%E5%88%92%E5%88%86%E4%B8%BA%E4%B8%89%E4%B8%AA%E5%AD%90%E7%BD%91%EF%BC%8C%E5%AD%90%E7%BD%91%201%20%E8%83%BD%E5%AE%B9%E7%BA%B3%2050%20%E5%8F%B0%E4%B8%BB%E6%9C%BA%EF%BC%8C%E5%AD%90%E7%BD%91%202%20%E5%92%8C%203%20%E8%83%BD%E5%88%86%E5%88%AB%E5%AE%B9%E7%BA%B3%2020%20%E5%8F%B0%E4%B8%BB%E6%9C%BA%E2%80%A6%E2%80%A6%E6%B1%82%E4%BB%96%E4%BB%AC%E7%9A%84%E5%AD%90%E7%BD%91%E6%8E%A9%E7%A0%81%E5%92%8C%E5%8F%AF%E7%94%A8%20IP%20%E5%9C%B0%E5%9D%80%E6%AE%B5%0A%0A%E9%A2%98%E4%B8%AD%E8%AF%B4%E5%A4%9A%E5%B0%91%E5%8F%B0%E4%B8%BB%E6%9C%BA%E7%9A%84%E5%85%B7%E4%BD%93%E6%95%B0%E5%AD%97%E4%B8%8D%E9%87%8D%E8%A6%81%EF%BC%8C%E5%88%9A%E5%A5%BD%E5%A4%A7%E4%BA%8E%E9%82%A3%E4%B8%AA%E6%95%B0%E5%AD%97%E7%9A%84%202%20%E7%9A%84%20n%20%E6%AC%A1%E6%96%B9%E7%9A%84%E6%95%B0%E6%89%8D%E9%87%8D%E8%A6%81%E3%80%82%0A%E5%8F%B0**%E6%95%B0%E8%A6%81%E5%8A%A02**%EF%BC%8C%E6%AF%94%E5%A6%82%2050%2B2%20%E5%8F%B0%EF%BC%8C%E5%B0%B1%E6%98%AF%2064%EF%BC%8C%E6%98%AF%202%20%E7%9A%84%206%20%E6%AC%A1%E6%96%B9%E3%80%82%E6%89%80%E4%BB%A5%E5%AD%90%E7%BD%91%E6%8E%A9%E7%A0%81%E5%90%8E%206%20%E4%BD%8D%E9%83%BD%E6%98%AF%200%20%EF%BC%88%E5%89%8D%E9%9D%A2%E5%85%A8%E6%98%AF%201%20%EF%BC%89%EF%BC%8C11111111.11111111.11111111.11000000%20%EF%BC%8C%E6%9C%80%E5%90%8E%E5%A1%AB%E7%A9%BA%E5%86%99%20255.255.255.192%C2%A0%0A%E5%90%8C%E7%90%86%2020%2B2%20%E5%8F%B0%EF%BC%8C%E5%B0%B1%E6%98%AF%2032%EF%BC%8C%E6%98%AF%202%20%E7%9A%84%205%E6%AC%A1%E6%96%B9%E3%80%82%E6%89%80%E4%BB%A5%E5%AD%90%E7%BD%91%E6%8E%A9%E7%A0%81%E5%90%8E%205%E4%BD%8D%E9%83%BD%E6%98%AF%200%EF%BC%8C%E6%9C%80%E5%90%8E%E5%A1%AB%E7%A9%BA%202%20%E5%92%8C%203%20%E7%9A%84%E5%AD%90%E7%BD%91%E6%8E%A9%E7%A0%81%E9%83%BD%E6%98%AF%20255.255.255.224%20%20%20%EF%BC%88%2011100000%EF%BC%89%0A%0A%0A%E5%8F%AF%E7%94%A8%20IP%20%E5%9C%B0%E5%9D%80%E4%BB%8E%E9%A2%98%E7%9B%AE%E6%89%80%E7%BB%99%E7%9A%84%E9%82%A3%E4%B8%AA%E6%95%B0%20%2B1%20%E5%BC%80%E5%A7%8B%EF%BC%8C%E6%9C%AC%E9%A2%98%E6%98%AF%20192.168.66.128%2B1%3D129%EF%BC%8C%C2%A0%E4%BB%8E%20129%20%E5%BC%80%E5%A7%8B%EF%BC%8C%E5%9B%A0%E4%B8%BA%E5%AD%90%E7%BD%91%201%20%E7%9A%84%E4%B8%BB%E6%9C%BA%E5%8F%B0%E6%95%B0%E8%A6%81%E6%98%AF%2064%20%EF%BC%8C%E6%89%80%E4%BB%A5%E5%88%B0%20190%20%E7%BB%93%E6%9D%9F%EF%BC%88129%2B64-3%3D190%EF%BC%8C%E4%B8%8D%E7%94%A8%E7%AE%A1%E4%B8%BA%E4%BB%80%E4%B9%88%EF%BC%8C%E7%BB%93%E6%9D%9F%E9%83%BD%E6%98%AF%20-3%EF%BC%89%C2%A0%20%20129-190%0A%0A%E4%B8%8B%E4%B8%80%E6%AE%B5%E4%BB%8E%20193%20%E5%BC%80%E5%A7%8B%EF%BC%88190%2B3%3D193%EF%BC%8C%E4%B8%8D%E7%94%A8%E7%AE%A1%E4%B8%BA%E4%BB%80%E4%B9%88%EF%BC%8C%E5%BC%80%E5%A7%8B%E9%83%BD%E6%98%AF%20%2B3%EF%BC%89%EF%BC%8C%E5%9B%A0%E4%B8%BA%E5%AD%90%E7%BD%91%202%20%E7%9A%84%E9%82%A3%E4%B8%AA%E6%95%B0%E5%AD%97%E6%98%AF%2032%20%EF%BC%8C%E6%89%80%E4%BB%A5%E5%88%B0%20222%20%E7%BB%93%E6%9D%9F%EF%BC%88193%2B32-3%3D222%EF%BC%89%C2%A0%20%20%20193-222%0A%0A%0A%E5%86%8D%E4%B8%8B%E4%B8%80%E6%AE%B5%E4%BB%8E%20225%20%E5%BC%80%E5%A7%8B%EF%BC%88222%2B3%3D225%EF%BC%89%EF%BC%8C%E5%9B%A0%E4%B8%BA%E5%AD%90%E7%BD%91%203%20%E7%9A%84%E9%82%A3%E4%B8%AA%E6%95%B0%E5%AD%97%E4%B9%9F%E6%98%AF%2032%20%EF%BC%8C%E6%89%80%E4%BB%A5%E5%88%B0%20254%20%E7%BB%93%E6%9D%9F%EF%BC%88225%2B32-3%3D254%EF%BC%89%C2%A0%20%20%20%20225-254%0A%0A-%20-%20-%20%0A%0A%23%23%23%23%23%203.%E7%BB%BC%E5%90%88%E9%A2%982%0A%20!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/56f63d48-e023-484d-a424-9d632280c2de.png.png%5D(en-resource%3A%2F%2Fdatabase%2F619%3A1)%0A%0A%3E%3Cu%3Eip%20dhcp%20%3Aexclude-address%20%3C%2Fu%3E%20%E4%BF%9D%E7%95%99%E5%9C%B0%E5%9D%80%E7%9A%84%E4%B8%A4%E4%B8%AA%E5%80%BC%0A%3Cu%3Eip%20dhcp%20pool%20%3C%2Fu%3E%E5%9C%B0%E5%9D%80%E6%B1%A0%E5%90%8D%0A%3Cu%3Enetwork%20%E5%9C%B0%E5%9D%80%E6%B1%A0%E5%9C%B0%E5%9D%80%20%E5%AD%90%E7%BD%91%E6%8E%A9%E7%A0%81%3C%2Fu%3E%0A%3Cu%3Edefault-route%20%E7%BC%BA%E7%9C%81%E7%BD%91%E5%85%B3%E5%9C%B0%E5%9D%80%3C%2Fu%3E%0A%3Cu%3Edns-server%20address%20%20%E4%B8%A4%E4%B8%AA%E5%9F%9F%E5%90%8D%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%9C%B0%E5%9D%80%3C%2Fu%3E%0A%3Cu%3Elease%20%E7%A7%9F%E7%94%A8%E6%97%B6%E9%97%B4%3C%2Fu%3E(%E5%A4%A9%20%E5%B0%8F%E6%97%B6%20%E5%88%86%E9%92%9F)%0A%0A%0A%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/abe5827f-b025-49b8-b867-c08f3b788821.png.png%5D(en-resource%3A%2F%2Fdatabase%2F629%3A1)%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/df86b003-8c26-4a78-913c-b01bfdb78148.png.png%5D(en-resource%3A%2F%2Fdatabase%2F631%3A1)%0A--%20-%0A%0A%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/ca1ae1ab-b288-43a8-bf56-ec5e400bb1ac.png.png%5D(en-resource%3A%2F%2Fdatabase%2F645%3A1)%0A%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/9d55abdb-bcda-4d3d-808b-87d0714bfecc.png.png%5D(en-resource%3A%2F%2Fdatabase%2F643%3A1)%0A%0A---%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/46c3ae46-9ced-4dbd-9a13-3d86d4dc23b5.png.png%5D(en-resource%3A%2F%2Fdatabase%2F647%3A1)%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/e09299f2-1006-4d54-afd2-1930b574bb58.png.png%5D(en-resource%3A%2F%2Fdatabase%2F649%3A1)%0A%0A%0A-%20-%20-%20%0A%0A%23%23%23%23%23%204.%20%E7%BB%BC%E5%90%88%E9%A2%983%0Atype%20%E5%90%8E%E9%9D%A2%E7%9A%84%20%E6%8C%89%E9%A1%BA%E5%BA%8F%E6%98%AFrelease%20%EF%BC%8Cdiscover%EF%BC%8Coffer%EF%BC%8Crequest%EF%BC%8Cack%0A%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/ee10523d-edcf-4959-97f6-b19360ff91e2.png.png%5D(en-resource%3A%2F%2Fdatabase%2F623%3A1)%0A%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/65cda361-2ce8-43a2-b479-cf0512d7c6ce.png.png%5D(en-resource%3A%2F%2Fdatabase%2F494%3A1)%0A%0A%E7%AC%AC%E4%B8%80%E8%A1%8C%E6%98%AFrelease%20%E4%BB%A3%E8%A1%A8%E6%9C%89ip%20%20%0A%E5%A6%82%E6%9E%9C%E7%AC%AC%E4%B8%80%E8%A1%8C%E6%98%AFdiscover%E4%BB%A3%E8%A1%A8%E6%B2%A1%E6%9C%89ip%20%E5%8D%B3%200.0.0.0%20%2C%20%20255.255.255.255%0A%E6%9C%80%E5%90%8E%E4%B8%80%E8%A1%8C%E6%98%AF%20request%20IP%20address%E5%AF%B9%E5%BA%94%E7%AC%AC%E4%B8%80%E8%A1%8C%E7%9A%84%E7%AC%AC%E4%B8%80%E4%B8%AAip%0Aoffer%E5%AF%B9%E5%BA%94%E7%AC%AC%E4%BA%8C%E4%B8%AAip%0A%0Aboot%20record%20type%202%E6%98%AFreply%20%0Aboot%20record%20type%201%E6%98%AFrequest%20%0A%0A%E6%9C%80%E5%90%8E%E4%B8%80%E8%A1%8C%E6%98%AF%20%20server%20IP%20address%20%E5%AF%B9%E5%BA%94%E7%AC%AC%E4%BA%8C%E4%B8%AAip%0A%0A%0A*%20*%20*%0A-%20-%20-%0A%0A%23%23%23%23%23%205.%20%E7%BB%BC%E5%90%88%E9%A2%984%0A%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/ed4026c6-f2ce-4d7b-8571-4965f5d920c9.png.png%5D(en-resource%3A%2F%2Fdatabase%2F625%3A1)%0A%0A%E5%8A%9F%E8%83%BD%E4%B8%80%E8%88%AC%E6%98%AF%E8%B7%AF%E7%94%B1%20%0A**dest%20address%20%E2%91%A0%E5%A4%84%20%E6%98%AF%E5%AE%83%E4%B8%8B%E9%9D%A2%E4%B8%80%E8%A1%8C%E7%9A%84%E7%AC%AC%E4%B8%80%E4%B8%AAip%E6%88%96%E5%9F%9F%E5%90%8D**%0A**source%20address%20%E5%B0%B1%E6%98%AF%20%E7%AC%AC%E4%B8%80%E8%A1%8C%E7%AC%AC%E4%B8%80%E4%B8%AAip**%0A%20destination%20address%20%E6%98%AF%20ip%20%20%E5%9F%9F%E5%90%8D%0A%20%0A%20%3Cu%3E%E6%89%A7%E8%A1%8C%E7%9A%84%E5%91%BD%E4%BB%A4%E4%B8%80%E8%88%AC%E6%98%AF%20%20%20**tracert%20%E5%9F%9F%E5%90%8D**%3C%2Fu%3E%0A%20%0A**dns%20ip%E4%B8%80%E8%88%AC%E6%98%AF%E7%AC%AC%E4%B8%80%E8%A1%8C%E7%AC%AC%E4%BA%8C%E4%B8%AAip**%0A**protocol%20%3A%20ICMP**%0A%20%0A%20%0A%0A*%20*%20*%0A%0A%0A%20%23%23%23%23%23%206.%20%E5%BA%94%E7%94%A8%E9%A2%98%0A%20!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/681f78a9-e9be-4af8-8c59-df61bb93e855.png.png%5D(en-resource%3A%2F%2Fdatabase%2F633%3A1)%0A%20%0A%203%E4%B8%AAip%E8%81%9A%E5%90%88%E7%9A%84%E6%97%B6%E5%80%99%EF%BC%8C%E8%A6%81%E6%BB%A1%E8%B6%B32n-2%3E%3D3%2C%E5%8D%B3%E5%AD%90%E7%BD%91%E6%8E%A9%E7%A0%81%E5%BF%85%E9%A1%BB%E8%A6%81%E5%B0%8F%E4%BA%8E32-3%3D29.(%E5%A6%82%E6%9E%9C%E7%AE%97%E5%87%BA%E6%9D%A5%E6%98%AF30%E5%B0%B1%E5%8F%98%E4%B8%BA29)%0A%20!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/db8d2661-ba42-46fd-9180-66c6c3850d3f/184f4d21-90a0-4df2-8a5a-2e90026ca7a9.png.png%5D(en-resource%3A%2F%2Fdatabase%2F637%3A1)%0A%20%0A%20%E5%A6%82%E6%9E%9C%E7%AE%97%E5%87%BA%E6%9D%A5%E7%9A%84ip%E5%92%8C%E5%B7%B2%E6%9C%89%E7%9A%84ip%E9%87%8D%E5%90%88%E4%BA%86%EF%BC%8C%E5%B0%B1%E5%90%91%E5%B7%A6%E7%A7%BB%E4%B8%80%E4%BD%8D%EF%BC%8C%E5%90%8E%E9%9D%A2%E7%9A%841%E5%8F%98%E4%B8%BA0%EF%BC%8C%E5%AD%90%E7%BD%91%E6%8E%A9%E7%A0%81%E5%9B%A0%E6%AD%A4%E5%87%8F%E4%B8%80%E3%80%82%0A%20-%20-%20-%0A%20%0A%20%E9%97%AE%E5%9C%A8%E6%9F%90%E8%B7%AF%E7%94%B1%E5%99%A8%E4%B8%8A%EF%BC%8C%E6%9C%80%E5%A4%9A%E8%BF%98%E5%8F%AF%E9%93%BE%E6%8E%A5%E7%9A%84%E8%B7%AF%E7%94%B1%E5%99%A8%E6%95%B0%E9%87%8F%E6%98%AF%E5%A4%9A%E5%B0%91%E3%80%82%E5%A6%82%E6%9E%9C%E6%89%80%E5%9C%A8%E5%AD%90%E7%BD%91%E6%8E%A9%E7%A0%81%E6%98%AF%20%2F29%20%E5%B0%B1%E5%A1%AB%203%EF%BC%8C%E6%98%AF%20%2F28%20%E5%B0%B1%E5%A1%AB%2011%E3%80%82%0A%E9%97%AE%E4%B8%B2%E6%8E%A5%E4%B8%80%E7%A7%8D%E8%AE%BE%E5%A4%87%E8%83%BD%E7%9B%91%E5%90%AC%E8%B7%AF%E7%94%B1%E5%99%A8%E4%B9%8B%E9%97%B4%E7%9A%84%E6%B5%81%E9%87%8F%EF%BC%8C%E5%86%99%20TAP%0A%E9%97%AE%E4%B8%B2%E6%8E%A5%E4%B8%80%E7%A7%8D%E8%AE%BE%E5%A4%87%E8%83%BD%E6%8F%90%E4%BE%9B%E5%AE%89%E5%85%A8%E4%BF%9D%E6%8A%A4%EF%BC%8C%E8%AD%A6%E6%8A%A5%E9%98%BB%E6%96%AD%E6%94%BB%E5%87%BB%EF%BC%8C%E4%B8%80%E8%88%AC%E6%98%AF%20IPS%20%20%20%20RA%E7%9A%84E1%E7%AB%AF%E5%8F%A3%0A%E9%97%AE%E9%98%B2%E7%81%AB%E5%A2%99%E8%AE%BF%E9%97%AE%E5%A4%96%E7%BD%91%E8%AE%BE%E7%BD%AE%EF%BC%8C%E5%88%86%E5%88%AB%E5%A1%AB%20nat%20%E5%92%8C%20global%20%20%20%0A%E8%AE%BF%E9%97%AE%E5%86%85%E7%BD%91%20static%0A%0A*%20*%20*%0A%0A&lt;/center&gt;&lt;/div&gt;
</content>
  </entry>
  <entry xml:base="http://linzhiteng.postach.io/feed.xml">
    <title type="text">linux操作系统</title>
    <id>https://linzhiteng.postach.io/post/linuxcao-zuo-xi-tong</id>
    <updated>2019-09-19T03:50:22.378000Z</updated>
    <published>2019-03-08T15:04:30Z</published>
    <link href="https://linzhiteng.postach.io/post/linuxcao-zuo-xi-tong" />
    <author>
      <name>linzhi teng</name>
    </author>
    <category term="linux" />
    <content type="html">&lt;div&gt;&lt;div style=&quot;font-size: 14px; margin: 0; padding: 0; width: 100%;&quot;&gt;&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;一. 认识操作系统&lt;/h2&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;1.1 操作系统简介&lt;/h3&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;操作系统（Operation System，简称OS）是管理计算机硬件与软件资源的程序，是计算机系统的内核与基石；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;操作系统本质上是运行在计算机上的软件程序 ；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;为用户提供一个与系统交互的操作界面 ；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;操作系统分内核与外壳（我们可以把外壳理解成围绕着内核的应用程序，而内核就是能操作硬件的程序）。&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/c83827b7-9600-4900-a437-97ff1df93fe7/6422fd56-d646-4426-8bab-8f50be436878.jpg&quot; /&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;1.2 操作系统简单分类.&lt;/h3&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;Windows: 目前最流行的个人桌面操作系统 ，不做多的介绍，大家都清楚。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;Unix： 最早的多用户、多任务操作系统 .按照操作系统的分类，属于分时操作系统。Unix 大多被用在服务器、工作站，现在也有用在个人计算机上。它在创建互联网、计算机网络或客户端/服务器模型方面发挥着非常重要的作用。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;Linux: Linux是一套免费使用和自由传播的类Unix操作系统.Linux存在着许多不同的Linux版本，但它们都使用了 Linux内核。Linux可安装在各种计算机硬件设备中，比如手机、平板电脑、路由器、视频游戏控制台、台式计算机、大型机和超级计算机。严格来讲，Linux这个词本身只表示Linux内核，但实际上人们已经习惯了用Linux来形容整个基于Linux内核，并且使用GNU 工程各种工具和数据库的操作系统。&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;二 初探Linux&lt;/h2&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;2.1 Linux简介&lt;/h3&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;类Unix系统： Linux是一种自由、开放源码的类似Unix的操作系统&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;Linux内核： 严格来说，Linux这个词本身只表示Linux内核&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;2.2 Linux的分类&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;Linux根据原生程度，分为两种：&lt;/p&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;内核版本： Linux不是一个操作系统，严格来讲，Linux只是一个操作系统中的内核。内核是什么？内核建立了计算机软件与硬件之间通讯的平台，内核提供系统服务，比如文件管理、虚拟内存、设备I/O等；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;发行版本： 一些组织或公司在内核版基础上进行二次开发而重新发行的版本。Linux发行版本有很多种（ubuntu和CentOS用的都很多，初学建议选择CentOS）&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;三. Linux文件系统概览&lt;/h2&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;3.1 Linux文件系统简介&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;在Linux操作系统中，所有被操作系统管理的资源，例如网络接口卡、磁盘驱动器、打印机、输入输出设备、普通文件或是目录都被看作是一个文件&lt;/strong&gt;。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;也就是说在LINUX系统中有一个重要的概念：&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;一切都是文件&lt;/strong&gt;。其实这是UNIX哲学的一个体现，而Linux是重写UNIX而来，所以这个概念也就传承了下来。在UNIX系统中，把一切资源都看作是文件，包括硬件设备。UNIX系统把每个硬件都看成是一个文件，通常称为设备文件，这样用户就可以用读写文件的方式实现对硬件的访问。&lt;/p&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;3.2 文件类型与目录结构&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;**Linux支持5种文件类型 ： **&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/c83827b7-9600-4900-a437-97ff1df93fe7/b5a4aa0a-897a-47a6-a01f-a0b6f9af1b48.jpg&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;Linux的目录结构如下：&lt;/strong&gt;&lt;br/&gt;
Linux文件系统的结构层次鲜明，就像一棵倒立的树，最顶层是其根目录： &lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/c83827b7-9600-4900-a437-97ff1df93fe7/2adc97d1-4e08-46c9-bd6f-54efb588a715.jpg&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;常见目录说明：&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;/bin： 存放二进制可执行文件(ls,cat,mkdir等)，常用命令一般都在这里；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;/etc： 存放系统管理和配置文件；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;/home： 存放所有用户文件的根目录，是用户主目录的基点，比如用户user的主目录就是/home/user，可以用~user表示；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;/usr ： 用于存放系统应用程序；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;/opt： 额外安装的可选应用程序包所放置的位置。一般情况下，我们可以把tomcat等都安装到这里；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;/proc： 虚拟文件系统目录，是系统内存的映射。可直接访问这个目录来获取系统信息；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;/root： 超级用户（系统管理员）的主目录（特权阶级^o^）；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;/sbin: 存放二进制可执行文件，只有root才能访问。这里存放的是系统管理员使用的系统级别的管理命令和程序。如ifconfig等；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;/dev： 用于存放设备文件；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;/mnt： 系统管理员安装临时文件系统的安装点，系统提供这个目录是让用户临时挂载其他的文件系统；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;/boot： 存放用于系统引导时使用的各种文件；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;/lib ： 存放着和系统运行相关的库文件 ；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;/tmp： 用于存放各种临时文件，是公用的临时文件存储点；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;/var： 用于存放运行时需要改变数据的文件，也是某些大文件的溢出区，比方说各种服务的日志文件（系统启动日志等。）等；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;/lost+found： 这个目录平时是空的，系统非正常关机而留下&quot;无家可归&quot;的文件（windows下叫什么.chk）就在这里。&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;四. Linux基本命令&lt;/h2&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;4.1 目录切换命令&lt;/h3&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;cd usr： 切换到该目录下usr目录&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;cd ..（或cd../）： 切换到上一层目录&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;cd /： 切换到系统根目录&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;cd ~： 切换到用户主目录&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;cd -： 切换到上一个操作所在目录&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;4.2 目录的操作命令(增删改查)&lt;/h3&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;mkdir 目录名称&lt;/code&gt;： 增加目录&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;ls或者ll&lt;/code&gt;（ll是ls -l的别名，ll命令可以看到该目录下的所有目录和文件的详细信息）：查看目录信息&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;find 目录 参数&lt;/code&gt;： 寻找目录（查）&lt;br/&gt;
示例：
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;列出当前目录及子目录下所有文件和文件夹: &lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;find&lt;/code&gt;.&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;在/home目录下查找以.txt结尾的文件名:&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;find /home -name &quot;*.txt&quot;&lt;/code&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;同上，但忽略大小写: &lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;find /home -iname &quot;*.txt&quot;&lt;/code&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;当前目录及子目录下查找所有以.txt和.pdf结尾的文件:&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;find . \( -name &quot;*.txt&quot; -o -name &quot;*.pdf&quot; \)&lt;/code&gt; 或 &lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;find . -name &quot;*.txt&quot; -o -name &quot;*.pdf&quot;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;mv 目录名称 新目录名称&lt;/code&gt;： 修改目录的名称（改）&lt;br/&gt;
注意：mv的语法不仅可以对目录进行重命名而且也可以对各种文件，压缩包等进行 重命名的操作。mv命令用来对文件或目录重新命名，或者将文件从一个目录移到另一个目录中。后面会介绍到mv命令的另一个用法。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;mv 目录名称 目录的新位置&lt;/code&gt;： 移动目录的位置---剪切（改）&lt;br/&gt;
注意：mv语法不仅可以对目录进行剪切操作，对文件和压缩包等都可执行剪切操作。另外mv与cp的结果不同，mv好像文件&quot;搬家&quot;，文件个数并未增加。而cp对文件进行复制，文件个数增加了。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;cp -r 目录名称 目录拷贝的目标位置&lt;/code&gt;： 拷贝目录（改），-r代表递归拷贝&lt;br/&gt;
注意：cp命令不仅可以拷贝目录还可以拷贝文件，压缩包等，拷贝文件和压缩包时不 用写-r 递归&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;rm [-rf] 目录&lt;/code&gt;: 删除目录（删）注意：rm不仅可以删除目录，也可以删除其他文件或压缩包，为了增强大家的记忆， 无论删除任何目录或文件，都直接使用&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;rm -rf 目录/文件/压缩包&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;4.3 文件的操作命令(增删改查)&lt;/h3&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;touch 文件名称&lt;/code&gt;: 文件的创建（增）&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;cat/more/less/tail 文件名称&lt;/code&gt; : 文件的查看（查）&lt;/li&gt;
&lt;/ol&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;cat： 查看显示文件内容&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;more： 可以显示百分比，回车可以向下一行， 空格可以向下一页，q可以退出查看&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;less： 可以使用键盘上的PgUp和PgDn向上 和向下翻页，q结束查看&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;tail-10 ： 查看文件的后10行，Ctrl+C结束&lt;br/&gt;
注意：命令 tail -f 文件 可以对某个文件进行动态监控，例如tomcat的日志文件， 会随着程序的运行，日志会变化，可以使用tail -f catalina-2016-11-11.log 监控 文 件的变化&lt;/li&gt;
&lt;/ul&gt;
&lt;ol start=&quot;3&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;vim 文件&lt;/code&gt;： 修改文件的内容（改）&lt;br/&gt;
vim编辑器是Linux中的强大组件，是vi编辑器的加强版，vim编辑器的命令和快捷方式有很多，但此处不一一阐述，大家也无需研究的很透彻，使用vim编辑修改文件的方式基本会使用就可以了。&lt;br/&gt;
在实际开发中，使用vim编辑器主要作用就是修改配置文件，下面是一般步骤：vim 文件------&gt;进入文件-----&gt;命令模式------&gt;按i进入编辑模式-----&gt;编辑文件 -------&gt;按Esc进入底行模式-----&gt;输入:wq/q! （输入wq代表写入内容并退出，即保存；输入q!代表强制退出不保存。）&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;rm -rf 文件&lt;/code&gt;： 删除文件（删）&lt;br/&gt;
同目录删除：熟记 rm -rf 文件 即可&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;4.4 压缩文件的操作命令&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;1）   打包并压缩文件：&lt;/strong&gt;&lt;br/&gt;
Linux中的打包文件一般是以.tar结尾的，压缩的命令一般是以.gz结尾的。&lt;br/&gt;
而一般情况下打包和压缩是一起进行的，打包并压缩后的文件的后缀名一般.tar.gz。&lt;br/&gt;
命令：&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;tar -zcvf 打包压缩后的文件名 要打包压缩的文件&lt;/code&gt;   其中：&lt;br/&gt;
z：调用gzip压缩命令进行压缩&lt;br/&gt;
c：打包文件&lt;br/&gt;
v：显示运行过程&lt;br/&gt;
f：指定文件名&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;比如：加入test目录下有三个文件分别是 :aaa.txt bbb.txt ccc.txt,如果我们要打包test目录并指定压缩后的压缩包名称为test.tar.gz可以使用命令：&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;tar -zcvf test.tar.gz aaa.txt bbb.txt ccc.txt&lt;/code&gt;或：&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;tar -zcvf test.tar.gz /test/&lt;/code&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;2）  解压压缩包：&lt;/strong&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;命令：tar [-xvf] 压缩文件&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;其中：x：代表解压&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;示例：&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;1 将/test下的test.tar.gz解压到当前目录下可以使用命令：&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;tar -xvf test.tar.gz&lt;/code&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;2 将/test下的test.tar.gz解压到根目录/usr下:  &lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;tar -xvf xxx.tar.gz -C /usr&lt;/code&gt;（- C代表指定解压的位置）&lt;/p&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;4.5 Linux的权限命令&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;操作系统中每个文件都拥有特定的权限、所属用户和所属组。权限是操作系统用来限制资源访问的机制，在Linux中权限一般分为读(readable)、写(writable)和执行(excutable)，分为三组。分别对应文件的属主(owner)，属组(group)和其他用户(other)，通过这样的机制来限制哪些用户、哪些组可以对特定的文件进行什么样的操作。通过 ls -l 命令我们可以 查看某个目录下的文件或目录的权限&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/c83827b7-9600-4900-a437-97ff1df93fe7/400d38bd-e04f-4d8e-8bcb-74d87aba6b29.jpg&quot; /&gt;&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;文件的类型：&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;d： 代表目录&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;-： 代表文件&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;l： 代表软链接（可以认为是window中的快捷方式）&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;Linux中权限分为以下几种：&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;r：代表权限是可读，r也可以用数字4表示&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;w：代表权限是可写，w也可以用数字2表示&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;x：代表权限是可执行，x也可以用数字1表示&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;文件和目录权限的区别：&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;对文件和目录而言，读写执行表示不同的意义。&lt;br/&gt;
对于文件：&lt;/p&gt;
&lt;table style=&quot;margin: 2px 0 14px; color: #333; width: auto; border-collapse: collapse; box-sizing: border-box;&quot;&gt;&lt;thead style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;权限名称&lt;/th&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;可执行操作&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;r&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;可以使用cat查看文件的内容&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;w&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;可以修改文件的内容&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;x&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;可以将其运行为二进制文件&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;对于目录：&lt;/p&gt;
&lt;table style=&quot;margin: 2px 0 14px; color: #333; width: auto; border-collapse: collapse; box-sizing: border-box;&quot;&gt;&lt;thead style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;权限名称&lt;/th&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;可执行操作&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;r&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;可以查看目录下列表&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;w&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;可以创建和删除目录下文件&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;x&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box; padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;可以使用cd进入目录&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;文件所有者/组&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;需要注意的是超级用户可以无视普通用户的权限，即使文件目录权限是000，依旧可以访问。 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;在linux中的每个用户必须属于一个组，不能独立于组外。在linux中每个文件有所有者、所在组、其它组的概念。&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;drwxr-xr-x   2 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;root root&lt;/strong&gt; 48 2013-11-27 16:34 test/&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;第二个栏位，表示文件个数。如果是文件的话，那这个数目自然是1了，如果是目录的话，那它的数目就是该目录中的文件个数了。&lt;br/&gt;
第三个栏位，表示该文件或目录的拥有者。若使用者目前处于自己的Home,那这一栏大概都是它的账号名称。&lt;br/&gt;
第四个栏位，表示所属的组（group）。每一个使用者都可以拥有一个以上的组，不过大部分的使用者应该都只属于一个组，只有当系统管理员希望给予某使用者特殊权限时，才可能会给他另一个组。&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;所有者 u&lt;br/&gt;
一般为文件的创建者，谁创建了该文件，就天然的成为该文件的所有者，用ls ‐ahl命令可以看到文件的所有者 也可以使用chown 用户名 文件名来修改文件的所有者 。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;文件所在组 g&lt;br/&gt;
当某个用户创建了一个文件后，这个文件的所在组就是该用户所在的组 用ls ‐ahl命令可以看到文件的所有组 也可以使用chgrp 组名 文件名来修改文件所在的组。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;其它组 o&lt;br/&gt;
除开文件的所有者和所在组的用户外，系统的其它用户都是文件的其它组&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;修改文件/目录的权限的命令：&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;chmod&lt;/code&gt;&lt;/p&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;chmod u+x,g+w f01　　//为文件f01设置自己可以执行，组员可以写入的权限
chmod u=rwx,g=rw,o=r f01  //rwxrw-r--
chmod 764 f01   // rwxrw-r--
chmod a+x f01　　//对文件f01的u,g,o都设置可执行属性
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;增加服务并开机启动&lt;/h4&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;服务脚本必须存放在 &lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;/etc/ini.d/&lt;/code&gt; 目录下；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;chkconfig --add servicename&lt;/code&gt;在chkconfig工具服务列表中增加此服务，此时服务会被在/etc/rc.d/rcN.d中赋予K/S入口了；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;chkconfig servicename on&lt;/code&gt;  修改服务的默认启动等级。&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;4.6 Linux 用户管理&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;Linux系统是一个多用户多任务的分时操作系统，任何一个要使用系统资源的用户，都必须首先向系统管理员申请一个账号，然后以这个账号的身份进入系统。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;用户的账号一方面可以帮助系统管理员对使用系统的用户进行跟踪，并控制他们对系统资源的访问；另一方面也可以帮助用户组织文件，并为用户提供安全性保护。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;Linux用户管理相关命令:&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;useradd 选项 用户名&lt;/code&gt;:添加用户账号&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;userdel 选项 用户名&lt;/code&gt;:删除用户帐号&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;usermod 选项 用户名&lt;/code&gt;:修改帐号&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;passwd 用户名&lt;/code&gt;:更改或创建用户的密码&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;passwd -S 用户名&lt;/code&gt; :显示用户账号密码信息&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;passwd -d 用户名&lt;/code&gt;: 清除用户密码&lt;/li&gt;
&lt;/ul&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;使用useradd指令所建立的帐号，实际上是保存在/etc/passwd文本文件中。&lt;br/&gt;
passwd命令用于设置用户的认证信息，包括用户密码、密码过期时间等。系统管理者则能用它管理系统用户的密码。只有管理者可以指定用户名称，一般用户只能变更自己的密码。&lt;/p&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;4.7 Linux系统用户组的管理&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;每个用户都有一个用户组，系统可以对一个用户组中的所有用户进行集中管理。不同Linux 系统对用户组的规定有所不同，如Linux下的用户属于与它同名的用户组，这个用户组在创建用户时同时创建。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;用户组的管理涉及用户组的添加、删除和修改。组的增加、删除和修改实际上就是对/etc/group文件的更新。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;Linux系统用户组的管理相关命令:&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;groupadd 选项 用户组&lt;/code&gt; :增加一个新的用户组&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;groupdel 用户组&lt;/code&gt;:要删除一个已有的用户组&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;groupmod 选项 用户组&lt;/code&gt; : 修改用户组的属性&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;4.8 其他常用命令&lt;/h3&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;pwd： 显示当前所在位置&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;grep 要搜索的字符串 要搜索的文件 --color： 搜索命令，--color代表高亮显示&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;ps -ef/ps -aux： 这两个命令都是查看当前系统正在运行进程，两者的区别是展示格式不同。如果想要查看特定的进程可以使用这样的格式：ps -aux | grep redis （查看包括redis字符串的进程），也可使用 pgrep redis -a。&lt;br/&gt;
注意：如果直接用ps（（Process Status））命令，会显示所有进程的状态，通常结合grep命令查看某进程的状态。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;kill -9 进程的pid： 杀死进程（-9 表示强制终止。）先用ps查找进程，然后用kill杀掉&lt;/li&gt;
&lt;/ul&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;网络通信命令：&lt;/strong&gt;&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;查看当前系统的网卡信息：ifconfig&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;查看与某台机器的连接情况：ping&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;查看当前系统的端口使用：netstat -an&lt;/li&gt;
&lt;/ul&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;系统服务：&lt;/strong&gt;&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;1.启动nfs服务  &lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;systemctl start nfs-server.service&lt;/code&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;2.设置开机自启动 &lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;systemctl enable nfs-server.service&lt;/code&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;3.停止开机自启动  &lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;systemctl disable nfs-server.service&lt;/code&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;4.查看服务当前状态  &lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;systemctl status nfs-server.service&lt;/code&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;5.重新启动某服务  &lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;systemctl restart nfs-server.service&lt;/code&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;6.查看所有已启动的服务  &lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;systemctl list -units --type=service&lt;/code&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;
&lt;ol start=&quot;7&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;彻底关闭防火墙：&lt;br/&gt;
&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;sudo systemctl status firewalld.service&lt;/code&gt;&lt;br/&gt;
&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;sudo systemctl stop firewalld.service&lt;/code&gt;&lt;br/&gt;
&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;sudo systemctl disable firewalld.service&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;&lt;center style=&quot;display:none !important;visibility:collapse !important;height:0 !important;white-space:nowrap;width:100%;overflow:hidden&quot;&gt;%23%23%20%E4%B8%80.%20%E8%AE%A4%E8%AF%86%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%0A%0A%23%23%23%201.1%20%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E7%AE%80%E4%BB%8B%0A%0A*%20%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%EF%BC%88Operation%20System%EF%BC%8C%E7%AE%80%E7%A7%B0OS%EF%BC%89%E6%98%AF%E7%AE%A1%E7%90%86%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%A1%AC%E4%BB%B6%E4%B8%8E%E8%BD%AF%E4%BB%B6%E8%B5%84%E6%BA%90%E7%9A%84%E7%A8%8B%E5%BA%8F%EF%BC%8C%E6%98%AF%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%B3%BB%E7%BB%9F%E7%9A%84%E5%86%85%E6%A0%B8%E4%B8%8E%E5%9F%BA%E7%9F%B3%EF%BC%9B%0A*%20%20%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E6%9C%AC%E8%B4%A8%E4%B8%8A%E6%98%AF%E8%BF%90%E8%A1%8C%E5%9C%A8%E8%AE%A1%E7%AE%97%E6%9C%BA%E4%B8%8A%E7%9A%84%E8%BD%AF%E4%BB%B6%E7%A8%8B%E5%BA%8F%20%EF%BC%9B%0A*%20%E4%B8%BA%E7%94%A8%E6%88%B7%E6%8F%90%E4%BE%9B%E4%B8%80%E4%B8%AA%E4%B8%8E%E7%B3%BB%E7%BB%9F%E4%BA%A4%E4%BA%92%E7%9A%84%E6%93%8D%E4%BD%9C%E7%95%8C%E9%9D%A2%20%EF%BC%9B%0A*%20%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E5%88%86%E5%86%85%E6%A0%B8%E4%B8%8E%E5%A4%96%E5%A3%B3%EF%BC%88%E6%88%91%E4%BB%AC%E5%8F%AF%E4%BB%A5%E6%8A%8A%E5%A4%96%E5%A3%B3%E7%90%86%E8%A7%A3%E6%88%90%E5%9B%B4%E7%BB%95%E7%9D%80%E5%86%85%E6%A0%B8%E7%9A%84%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F%EF%BC%8C%E8%80%8C%E5%86%85%E6%A0%B8%E5%B0%B1%E6%98%AF%E8%83%BD%E6%93%8D%E4%BD%9C%E7%A1%AC%E4%BB%B6%E7%9A%84%E7%A8%8B%E5%BA%8F%EF%BC%89%E3%80%82%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/c83827b7-9600-4900-a437-97ff1df93fe7/6422fd56-d646-4426-8bab-8f50be436878.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F1181%3A1)%0A%0A%23%23%23%201.2%20%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E7%AE%80%E5%8D%95%E5%88%86%E7%B1%BB.%0A%0A1.%20Windows%3A%C2%A0%E7%9B%AE%E5%89%8D%E6%9C%80%E6%B5%81%E8%A1%8C%E7%9A%84%E4%B8%AA%E4%BA%BA%E6%A1%8C%E9%9D%A2%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%20%EF%BC%8C%E4%B8%8D%E5%81%9A%E5%A4%9A%E7%9A%84%E4%BB%8B%E7%BB%8D%EF%BC%8C%E5%A4%A7%E5%AE%B6%E9%83%BD%E6%B8%85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%BF%99%E4%B8%AA%E6%A6%82%E5%BF%B5%E4%B9%9F%E5%B0%B1%E4%BC%A0%E6%89%BF%E4%BA%86%E4%B8%8B%E6%9D%A5%E3%80%82%E5%9C%A8UNIX%E7%B3%BB%E7%BB%9F%E4%B8%AD%EF%BC%8C%E6%8A%8A%E4%B8%80%E5%88%87%E8%B5%84%E6%BA%90%E9%83%BD%E7%9C%8B%E4%BD%9C%E6%98%AF%E6%96%87%E4%BB%B6%EF%BC%8C%E5%8C%85%E6%8B%AC%E7%A1%AC%E4%BB%B6%E8%AE%BE%E5%A4%87%E3%80%82UNIX%E7%B3%BB%E7%BB%9F%E6%8A%8A%E6%AF%8F%E4%B8%AA%E7%A1%AC%E4%BB%B6%E9%83%BD%E7%9C%8B%E6%88%90%E6%98%AF%E4%B8%80%E4%B8%AA%E6%96%87%E4%BB%B6%EF%BC%8C%E9%80%9A%E5%B8%B8%E7%A7%B0%E4%B8%BA%E8%AE%BE%E5%A4%87%E6%96%87%E4%BB%B6%EF%BC%8C%E8%BF%99%E6%A0%B7%E7%94%A8%E6%88%B7%E5%B0%B1%E5%8F%AF%E4%BB%A5%E7%94%A8%E8%AF%BB%E5%86%99%E6%96%87%E4%BB%B6%E7%9A%84%E6%96%B9%E5%BC%8F%E5%AE%9E%E7%8E%B0%E5%AF%B9%E7%A1%AC%E4%BB%B6%E7%9A%84%E8%AE%BF%E9%97%AE%E3%80%82%0A%0A%0A%23%23%23%203.2%20%E6%96%87%E4%BB%B6%E7%B1%BB%E5%9E%8B%E4%B8%8E%E7%9B%AE%E5%BD%95%E7%BB%93%E6%9E%84%0A**Linux%E6%94%AF%E6%8C%815%E7%A7%8D%E6%96%87%E4%BB%B6%E7%B1%BB%E5%9E%8B%20%EF%BC%9A%C2%A0**%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/c83827b7-9600-4900-a437-97ff1df93fe7/b5a4aa0a-897a-47a6-a01f-a0b6f9af1b48.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F1183%3A1)%0A%0A**Linux%E7%9A%84%E7%9B%AE%E5%BD%95%E7%BB%93%E6%9E%84%E5%A6%82%E4%B8%8B%EF%BC%9A**%0ALinux%E6%96%87%E4%BB%B6%E7%B3%BB%E7%BB%9F%E7%9A%84%E7%BB%93%E6%9E%84%E5%B1%82%E6%AC%A1%E9%B2%9C%E6%98%8E%EF%BC%8C%E5%B0%B1%E5%83%8F%E4%B8%80%E6%A3%B5%E5%80%92%E7%AB%8B%E7%9A%84%E6%A0%91%EF%BC%8C%E6%9C%80%E9%A1%B6%E5%B1%82%E6%98%AF%E5%85%B6%E6%A0%B9%E7%9B%AE%E5%BD%95%EF%BC%9A%C2%A0%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/c83827b7-9600-4900-a437-97ff1df93fe7/2adc97d1-4e08-46c9-bd6f-54efb588a715.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F1185%3A1)%0A%0A%E5%B8%B8%E8%A7%81%E7%9B%AE%E5%BD%95%E8%AF%B4%E6%98%8E%EF%BC%9A%0A*%20%2Fbin%EF%BC%9A%C2%A0%E5%AD%98%E6%94%BE%E4%BA%8C%E8%BF%9B%E5%88%B6%E5%8F%AF%E6%89%A7%E8%A1%8C%E6%96%87%E4%BB%B6(ls%2Ccat%2Cmkdir%E7%AD%89)%EF%BC%8C%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4%E4%B8%80%E8%88%AC%E9%83%BD%E5%9C%A8%E8%BF%99%E9%87%8C%EF%BC%9B%0A*%20%2Fetc%EF%BC%9A%C2%A0%E5%AD%98%E6%94%BE%E7%B3%BB%E7%BB%9F%E7%AE%A1%E7%90%86%E5%92%8C%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%EF%BC%9B%0A*%20%2Fhome%EF%BC%9A%C2%A0%E5%AD%98%E6%94%BE%E6%89%80%E6%9C%89%E7%94%A8%E6%88%B7%E6%96%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96%87%E4%BB%B6%E5%92%8C%E6%96%87%E4%BB%B6%E5%A4%B9%3A%C2%A0%60find%20%60.%0A%20%20%20%20*%20%E5%9C%A8%2Fhome%E7%9B%AE%E5%BD%95%E4%B8%8B%E6%9F%A5%E6%89%BE%E4%BB%A5.txt%E7%BB%93%E5%B0%BE%E7%9A%84%E6%96%87%E4%BB%B6%E5%90%8D%3A%60find%20%2Fhome%20-name%20%22*.txt%22%60%0A%20%20%20%20*%20%E5%90%8C%E4%B8%8A%EF%BC%8C%E4%BD%86%E5%BF%BD%E7%95%A5%E5%A4%A7%E5%B0%8F%E5%86%99%3A%C2%A0%60find%20%2Fhome%20-iname%20%22*.txt%22%60%0A%20%20%20%20*%20%E5%BD%93%E5%89%8D%E7%9B%AE%E5%BD%95%E5%8F%8A%E5%AD%90%E7%9B%AE%E5%BD%95%E4%B8%8B%E6%9F%A5%E6%89%BE%E6%89%80%E6%9C%89%E4%BB%A5.txt%E5%92%8C.pdf%E7%BB%93%E5%B0%BE%E7%9A%84%E6%96%87%E4%BB%B6%3A%60find%20.%20%5C(%20-name%20%22*.txt%22%20-o%20-name%20%22*.pdf%22%20%5C)%60%20%E6%88%96%20%60find%20.%20-name%20%22*.txt%22%20-o%20-name%20%22*.pdf%22%60%0A4.%20%60mv%20%E7%9B%AE%E5%BD%95%E5%90%8D%E7%A7%B0%20%E6%96%B0%E7%9B%AE%E5%BD%95%E5%90%8D%E7%A7%B0%60%EF%BC%9A%C2%A0%E4%BF%AE%E6%94%B9%E7%9B%AE%E5%BD%95%E7%9A%84%E5%90%8D%E7%A7%B0%EF%BC%88%E6%94%B9%EF%BC%89%0A%E6%B3%A8%E6%84%8F%EF%BC%9Amv%E7%9A%84%E8%AF%AD%E6%B3%95%E4%B8%8D%E4%BB%85%E5%8F%AF%E4%BB%A5%E5%AF%B9%E7%9B%AE%E5%BD%95%E8%BF%9B%E8%A1%8C%E9%87%8D%E5%91%BD%E5%90%8D%E8%80%8C%E4%B8%94%E4%B9%9F%E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F%E7%94%A8%E5%B0%B1%E5%8F%AF%E4%BB%A5%E4%BA%86%E3%80%82%0A%E5%9C%A8%E5%AE%9E%E9%99%85%E5%BC%80%E5%8F%91%E4%B8%AD%EF%BC%8C%E4%BD%BF%E7%94%A8vim%E7%BC%96%E8%BE%91%E5%99%A8%E4%B8%BB%E8%A6%81%E4%BD%9C%E7%94%A8%E5%B0%B1%E6%98%AF%E4%BF%AE%E6%94%B9%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%EF%BC%8C%E4%B8%8B%E9%9D%A2%E6%98%AF%E4%B8%80%E8%88%AC%E6%AD%A5%E9%AA%A4%EF%BC%9Avim%20%E6%96%87%E4%BB%B6------%3E%E8%BF%9B%E5%85%A5%E6%96%87%E4%BB%B6-----%3E%E5%91%BD%E4%BB%A4%E6%A8%A1%E5%BC%8F------%3E%E6%8C%89i%E8%BF%9B%E5%85%A5%E7%BC%96%E8%BE%91%E6%A8%A1%E5%BC%8F-----%3E%E7%BC%96%E8%BE%91%E6%96%87%E4%BB%B6%20-------%3E%E6%8C%89Esc%E8%BF%9B%E5%85%A5%E5%BA%95%E8%A1%8C%E6%A8%A1%E5%BC%8F-----%3E%E8%BE%93%E5%85%A5%3Awq%2Fq!%20%EF%BC%88%E8%BE%93%E5%85%A5wq%E4%BB%A3%E8%A1%A8%E5%86%99%E5%85%A5%E5%86%85%E5%AE%B9%E5%B9%B6%E9%80%80%E5%87%BA%EF%BC%8C%E5%8D%B3%E4%BF%9D%E5%AD%98%EF%BC%9B%E8%BE%93%E5%85%A5q!%E4%BB%A3%E8%A1%A8%E5%BC%BA%E5%88%B6%E9%80%80%E5%87%BA%E4%B8%8D%E4%BF%9D%E5%AD%98%E3%80%82%EF%BC%89%0A4.%20%60rm%20-rf%20%E6%96%87%E4%BB%B6%60%EF%BC%9A%C2%A0%E5%88%A0%E9%99%A4%E6%96%87%E4%BB%B6%EF%BC%88%E5%88%A0%EF%BC%89%0A%E5%90%8C%E7%9B%AE%E5%BD%95%E5%88%A0%E9%99%A4%EF%BC%9A%E7%86%9F%E8%AE%B0%C2%A0rm%20-rf%C2%A0%E6%96%87%E4%BB%B6%20%E5%8D%B3%E5%8F%AF%0A%0A%23%23%23%204.4%20%E5%8E%8B%E7%BC%A9%E6%96%87%E4%BB%B6%E7%9A%84%E6%93%8D%E4%BD%9C%E5%91%BD%E4%BB%A4%0A**1%EF%BC%89%20%20%20%E6%89%93%E5%8C%85%E5%B9%B6%E5%8E%8B%E7%BC%A9%E6%96%87%E4%BB%B6%EF%BC%9A**%0ALinux%E4%B8%AD%E7%9A%84%E6%89%93%E5%8C%85%E6%96%87%E4%BB%B6%E4%B8%80%E8%88%AC%E6%98%AF%E4%BB%A5.tar%E7%BB%93%E5%B0%BE%E7%9A%84%EF%BC%8C%E5%8E%8B%E7%BC%A9%E7%9A%84%E5%91%BD%E4%BB%A4%E4%B8%80%E8%88%AC%E6%98%AF%E4%BB%A5.gz%E7%BB%93%E5%B0%BE%E7%9A%84%E3%80%82%0A%E8%80%8C%E4%B8%80%E8%88%AC%E6%83%85%E5%86%B5%E4%B8%8B%E6%89%93%E5%8C%85%E5%92%8C%E5%8E%8B%E7%BC%A9%E6%98%AF%E4%B8%80%E8%B5%B7%E8%BF%9B%E8%A1%8C%E7%9A%84%EF%BC%8C%E6%89%93%E5%8C%85%E5%B9%B6%E5%8E%8B%E7%BC%A9%E5%90%8E%E7%9A%84%E6%96%87%E4%BB%B6%E7%9A%84%E5%90%8E%E7%BC%80%E5%90%8D%E4%B8%80%E8%88%AC.tar.gz%E3%80%82%20%0A%E5%91%BD%E4%BB%A4%EF%BC%9A%60tar%20-zcvf%20%E6%89%93%E5%8C%85%E5%8E%8B%E7%BC%A9%E5%90%8E%E7%9A%84%E6%96%87%E4%BB%B6%E5%90%8D%20%E8%A6%81%E6%89%93%E5%8C%85%E5%8E%8B%E7%BC%A9%E7%9A%84%E6%96%87%E4%BB%B6%60%20%20%20%E5%85%B6%E4%B8%AD%EF%BC%9A%0Az%E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%A4%BA%E4%BE%8B%EF%BC%9A%0A%0A1%20%E5%B0%86%2Ftest%E4%B8%8B%E7%9A%84test.tar.gz%E8%A7%A3%E5%8E%8B%E5%88%B0%E5%BD%93%E5%89%8D%E7%9B%AE%E5%BD%95%E4%B8%8B%E5%8F%AF%E4%BB%A5%E4%BD%BF%E7%94%A8%E5%91%BD%E4%BB%A4%EF%BC%9A%60tar%20-xvf%20test.tar.gz%60%0A%0A2%20%E5%B0%86%2Ftest%E4%B8%8B%E7%9A%84test.tar.gz%E8%A7%A3%E5%8E%8B%E5%88%B0%E6%A0%B9%E7%9B%AE%E5%BD%95%2Fusr%E4%B8%8B%3A%20%20%60tar%20-xvf%20xxx.tar.gz%20-C%20%2Fusr%60%EF%BC%88-%20C%E4%BB%A3%E8%A1%A8%E6%8C%87%E5%AE%9A%E8%A7%A3%E5%8E%8B%E7%9A%84%E4%BD%8D%E7%BD%AE%EF%BC%89%0A%0A%23%23%23%204.5%20Linux%E7%9A%84%E6%9D%83%E9%99%90%E5%91%BD%E4%BB%A4%0A%0A%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E4%B8%AD%E6%AF%8F%E4%B8%AA%E6%96%87%E4%BB%B6%E9%83%BD%E6%8B%A5%E6%9C%89%E7%89%B9%E5%AE%9A%E7%9A%84%E6%9D%83%E9%99%90%E3%80%81%E6%89%80%E5%B1%9E%E7%94%A8%E6%88%B7%E5%92%8C%E6%89%80%E5%B1%9E%E7%BB%84%E3%80%82%E6%9D%83%E9%99%90%E6%98%AF%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E7%94%A8%E6%9D%A5%E9%99%90%E5%88%B6%E8%B5%84%E6%BA%90%E8%AE%BF%E9%97%AE%E7%9A%84%E6%9C%BA%E5%88%B6%EF%BC%8C%E5%9C%A8Linux%E4%B8%AD%E6%9D%83%E9%99%90%E4%B8%80%E8%88%AC%E5%88%86%E4%B8%BA%E8%AF%BB(readable)%E3%80%81%E5%86%99(writable)%E5%92%8C%E6%89%A7%E8%A1%8C(excutable)%EF%BC%8C%E5%88%86%E4%B8%BA%E4%B8%89%E7%BB%84%E3%80%82%E5%88%86%E5%88%AB%E5%AF%B9%E5%BA%94%E6%96%87%E4%BB%B6%E7%9A%84%E5%B1%9E%E4%B8%BB(owner)%EF%BC%8C%E5%B1%9E%E7%BB%84(group)%E5%92%8C%E5%85%B6%E4%BB%96%E7%94%A8%E6%88%B7(other)%EF%BC%8C%E9%80%9A%E8%BF%87%E8%BF%99%E6%A0%B7%E7%9A%84%E6%9C%BA%E5%88%B6%E6%9D%A5%E9%99%90%E5%88%B6%E5%93%AA%E4%BA%9B%E7%94%A8%E6%88%B7%E3%80%81%E5%93%AA%E4%BA%9B%E7%BB%84%E5%8F%AF%E4%BB%A5%E5%AF%B9%E7%89%B9%E5%AE%9A%E7%9A%84%E6%96%87%E4%BB%B6%E8%BF%9B%E8%A1%8C%E4%BB%80%E4%B9%88%E6%A0%B7%E7%9A%84%E6%93%8D%E4%BD%9C%E3%80%82%E9%80%9A%E8%BF%87%C2%A0ls%20-l%C2%A0%E5%91%BD%E4%BB%A4%E6%88%91%E4%BB%AC%E5%8F%AF%E4%BB%A5%20%E6%9F%A5%E7%9C%8B%E6%9F%90%E4%B8%AA%E7%9B%AE%E5%BD%95%E4%B8%8B%E7%9A%84%E6%96%87%E4%BB%B6%E6%88%96%E7%9B%AE%E5%BD%95%E7%9A%84%E6%9D%83%E9%99%90%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/c83827b7-9600-4900-a437-97ff1df93fe7/400d38bd-e04f-4d8e-8bcb-74d87aba6b29.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F1227%3A0)%0A%0A%0A%23%23%23%23%20%E6%96%87%E4%BB%B6%E7%9A%84%E7%B1%BB%E5%9E%8B%EF%BC%9A%0A*%20d%EF%BC%9A%20%E4%BB%A3%E8%A1%A8%E7%9B%AE%E5%BD%95%0A*%20-%EF%BC%9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80%85%2F%E7%BB%84%0A%E9%9C%80%E8%A6%81%E6%B3%A8%E6%84%8F%E7%9A%84%E6%98%AF%E8%B6%85%E7%BA%A7%E7%94%A8%E6%88%B7%E5%8F%AF%E4%BB%A5%E6%97%A0%E8%A7%86%E6%99%AE%E9%80%9A%E7%94%A8%E6%88%B7%E7%9A%84%E6%9D%83%E9%99%90%EF%BC%8C%E5%8D%B3%E4%BD%BF%E6%96%87%E4%BB%B6%E7%9B%AE%E5%BD%95%E6%9D%83%E9%99%90%E6%98%AF000%EF%BC%8C%E4%BE%9D%E6%97%A7%E5%8F%AF%E4%BB%A5%E8%AE%BF%E9%97%AE%E3%80%82%C2%A0**%E5%9C%A8linux%E4%B8%AD%E7%9A%84%E6%AF%8F%E4%B8%AA%E7%94%A8%E6%88%B7%E5%BF%85%E9%A1%BB%E5%B1%9E%E4%BA%8E%E4%B8%80%E4%B8%AA%E7%BB%84%EF%BC%8C%E4%B8%8D%E8%83%BD%E7%8B%AC%E7%AB%8B%E4%BA%8E%E7%BB%84%E5%A4%96%E3%80%82%E5%9C%A8linux%E4%B8%AD%E6%AF%8F%E4%B8%AA%E6%96%87%E4%BB%B6%E6%9C%89%E6%89%80%E6%9C%89%E8%80%85%E3%80%81%E6%89%80%E5%9C%A8%E7%BB%84%E3%80%81%E5%85%B6%E5%AE%83%E7%BB%84%E7%9A%84%E6%A6%82%E5%BF%B5%E3%80%82**%0A%0A%3Edrwxr-xr-x%C2%A0%C2%A0%202%20**root%20root**%2048%202013-11-27%2016%3A34%20test%2F%0A%0A%E7%AC%AC%E4%BA%8C%E4%B8%AA%E6%A0%8F%E4%BD%8D%EF%BC%8C%E8%A1%A8%E7%A4%BA%E6%96%87%E4%BB%B6%E4%B8%AA%E6%95%B0%E3%80%82%E5%A6%82%E6%9E%9C%E6%98%AF%E6%96%87%E4%BB%B6%E7%9A%84%E8%AF%9D%EF%BC%8C%E9%82%A3%E8%BF%99%E4%B8%AA%E6%95%B0%E7%9B%AE%E8%87%AA%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%E5%B1%9E%E4%BA%8E%E4%B8%80%E4%B8%AA%E7%BB%84%EF%BC%8C%E5%8F%AA%E6%9C%89%E5%BD%93%E7%B3%BB%E7%BB%9F%E7%AE%A1%E7%90%86%E5%91%98%E5%B8%8C%E6%9C%9B%E7%BB%99%E4%BA%88%E6%9F%90%E4%BD%BF%E7%94%A8%E8%80%85%E7%89%B9%E6%AE%8A%E6%9D%83%E9%99%90%E6%97%B6%EF%BC%8C%E6%89%8D%E5%8F%AF%E8%83%BD%E4%BC%9A%E7%BB%99%E4%BB%96%E5%8F%A6%E4%B8%80%E4%B8%AA%E7%BB%84%E3%80%82%0A%0A*%20%E6%89%80%E6%9C%89%E8%80%85%20u%0A%E4%B8%80%E8%88%AC%E4%B8%BA%E6%96%87%E4%BB%B6%E7%9A%84%E5%88%9B%E5%BB%BA%E8%80%85%EF%BC%8C%E8%B0%81%E5%88%9B%E5%BB%BA%E4%BA%86%E8%AF%A5%E6%96%87%E4%BB%B6%EF%BC%8C%E5%B0%B1%E5%A4%A9%E7%84%B6%E7%9A%84%E6%88%90%E4%B8%BA%E8%AF%A5%E6%96%87%E4%BB%B6%E7%9A%84%E6%89%80%E6%9C%89%E8%80%85%EF%BC%8C%E7%94%A8ls%20%E2%80%90ahl%E5%91%BD%E4%BB%A4%E5%8F%AF%E4%BB%A5%E7%9C%8B%E5%88%B0%E6%96%87%E4%BB%B6%E7%9A%84%E6%89%80%E6%9C%89%E8%80%85%20%E4%B9%9F%E5%8F%AF%E4%BB%A5%E4%BD%BF%E7%94%A8chown%20%E7%94%A8%E6%88%B7%E5%90%8D%20%E6%96%87%E4%BB%B6%E5%90%8D%E6%9D%A5%E4%BF%AE%E6%94%B9%E6%96%87%E4%BB%B6%E7%9A%84%E6%89%80%E6%9C%89%E8%80%85%20%E3%80%82%0A*%20%E6%96%87%E4%BB%B6%E6%89%80%E5%9C%A8%E7%BB%84%20g%0A%E5%BD%93%E6%9F%90%E4%B8%AA%E7%94%A8%E6%88%B7%E5%88%9B%E5%BB%BA%E4%BA%86%E4%B8%80%E4%B8%AA%E6%96%87%E4%BB%B6%E5%90%8E%EF%BC%8C%E8%BF%99%E4%B8%AA%E6%96%87%E4%BB%B6%E7%9A%84%E6%89%80%E5%9C%A8%E7%BB%84%E5%B0%B1%E6%98%AF%E8%AF%A5%E7%94%A8%E6%88%B7%E6%89%80%E5%9C%A8%E7%9A%84%E7%BB%84%20%E7%94%A8ls%20%E2%80%90ahl%E5%91%BD%E4%BB%A4%E5%8F%AF%E4%BB%A5%E7%9C%8B%E5%88%B0%E6%96%87%E4%BB%B6%E7%9A%84%E6%89%80%E6%9C%89%E7%BB%84%20%E4%B9%9F%E5%8F%AF%E4%BB%A5%E4%BD%BF%E7%94%A8chgrp%20%E7%BB%84%E5%90%8D%20%E6%96%87%E4%BB%B6%E5%90%8D%E6%9D%A5%E4%BF%AE%E6%94%B9%E6%96%87%E4%BB%B6%E6%89%80%E5%9C%A8%E7%9A%84%E7%BB%84%E3%80%82%0A*%20%E5%85%B6%E5%AE%83%E7%BB%84%20o%0A%E9%99%A4%E5%BC%80%E6%96%87%E4%BB%B6%E7%9A%84%E6%89%80%E6%9C%89%E8%80%85%E5%92%8C%E6%89%80%E5%9C%A8%E7%BB%84%E7%9A%84%E7%94%A8%E6%88%B7%E5%A4%96%EF%BC%8C%E7%B3%BB%E7%BB%9F%E7%9A%84%E5%85%B6%E5%AE%83%E7%94%A8%E6%88%B7%E9%83%BD%E6%98%AF%E6%96%87%E4%BB%B6%E7%9A%84%E5%85%B6%E5%AE%83%E7%BB%84%0A%0A%0A%23%23%23%23%20%E4%BF%AE%E6%94%B9%E6%96%87%E4%BB%B6%2F%E7%9B%AE%E5%BD%95%E7%9A%84%E6%9D%83%E9%99%90%E7%9A%84%E5%91%BD%E4%BB%A4%EF%BC%9A%0A%60chmod%60%0A%60%60%60%0Achmod%20u%2Bx%2Cg%2Bw%20f01%E3%80%80%E3%80%80%2F%2F%E4%B8%BA%E6%96%87%E4%BB%B6f01%E8%AE%BE%E7%BD%AE%E8%87%AA%E5%B7%B1%E5%8F%AF%E4%BB%A5%E6%89%A7%E8%A1%8C%EF%BC%8C%E7%BB%84%E5%91%98%E5%8F%AF%E4%BB%A5%E5%86%99%E5%85%A5%E7%9A%84%E6%9D%83%E9%99%90%0Achmod%20u%3Drwx%2Cg%3Drw%2Co%3Dr%20f01%20%20%2F%2Frwxrw-r--%0Achmod%20764%20f01%20%20%20%2F%2F%20rwxrw-r--%0Achmod%20a%2Bx%20f01%E3%80%80%E3%80%80%2F%2F%E5%AF%B9%E6%96%87%E4%BB%B6f01%E7%9A%84u%2Cg%2Co%E9%83%BD%E8%AE%BE%E7%BD%AE%E5%8F%AF%E6%89%A7%E8%A1%8C%E5%B1%9E%E6%80%A7%0A%60%60%60%0A%0A%23%23%23%23%20%E5%A2%9E%E5%8A%A0%E6%9C%8D%E5%8A%A1%E5%B9%B6%E5%BC%80%E6%9C%BA%E5%90%AF%E5%8A%A8%0A%0A1.%20%E6%9C%8D%E5%8A%A1%E8%84%9A%E6%9C%AC%E5%BF%85%E9%A1%BB%E5%AD%98%E6%94%BE%E5%9C%A8%20%60%2Fetc%2Fini.d%2F%60%20%E7%9B%AE%E5%BD%95%E4%B8%8B%EF%BC%9B%0A2.%20%60chkconfig%20--add%20servicename%60%E5%9C%A8chkconfig%E5%B7%A5%E5%85%B7%E6%9C%8D%E5%8A%A1%E5%88%97%E8%A1%A8%E4%B8%AD%E5%A2%9E%E5%8A%A0%E6%AD%A4%E6%9C%8D%E5%8A%A1%EF%BC%8C%E6%AD%A4%E6%97%B6%E6%9C%8D%E5%8A%A1%E4%BC%9A%E8%A2%AB%E5%9C%A8%2Fetc%2Frc.d%2FrcN.d%E4%B8%AD%E8%B5%8B%E4%BA%88K%2FS%E5%85%A5%E5%8F%A3%E4%BA%86%EF%BC%9B%0A3.%20%60chkconfig%20servicename%20on%60%20%20%E4%BF%AE%E6%94%B9%E6%9C%8D%E5%8A%A1%E7%9A%84%E9%BB%98%E8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BA%90%E7%9A%84%E8%AE%BF%E9%97%AE%EF%BC%9B%E5%8F%A6%E4%B8%80%E6%96%B9%E9%9D%A2%E4%B9%9F%E5%8F%AF%E4%BB%A5%E5%B8%AE%E5%8A%A9%E7%94%A8%E6%88%B7%E7%BB%84%E7%BB%87%E6%96%87%E4%BB%B6%EF%BC%8C%E5%B9%B6%E4%B8%BA%E7%94%A8%E6%88%B7%E6%8F%90%E4%BE%9B%E5%AE%89%E5%85%A8%E6%80%A7%E4%BF%9D%E6%8A%A4%E3%80%82%0A%0A%0A%23%23%23%23%20Linux%E7%94%A8%E6%88%B7%E7%AE%A1%E7%90%86%E7%9B%B8%E5%85%B3%E5%91%BD%E4%BB%A4%3A%0A*%20%60useradd%20%E9%80%89%E9%A1%B9%20%E7%94%A8%E6%88%B7%E5%90%8D%60%3A%E6%B7%BB%E5%8A%A0%E7%94%A8%E6%88%B7%E8%B4%A6%E5%8F%B7%0A*%20%60userdel%20%E9%80%89%E9%A1%B9%20%E7%94%A8%E6%88%B7%E5%90%8D%60%3A%E5%88%A0%E9%99%A4%E7%94%A8%E6%88%B7%E5%B8%90%E5%8F%B7%0A*%20%60usermod%20%E9%80%89%E9%A1%B9%20%E7%94%A8%E6%88%B7%E5%90%8D%60%3A%E4%BF%AE%E6%94%B9%E5%B8%90%E5%8F%B7%0A*%20%60passwd%20%E7%94%A8%E6%88%B7%E5%90%8D%60%3A%E6%9B%B4%E6%94%B9%E6%88%96%E5%88%9B%E5%BB%BA%E7%94%A8%E6%88%B7%E7%9A%84%E5%AF%86%E7%A0%81%0A*%20%60passwd%20-S%20%E7%94%A8%E6%88%B7%E5%90%8D%60%C2%A0%3A%E6%98%BE%E7%A4%BA%E7%94%A8%E6%88%B7%E8%B4%A6%E5%8F%B7%E5%AF%86%E7%A0%81%E4%BF%A1%E6%81%AF%0A*%20%60passwd%20-d%20%E7%94%A8%E6%88%B7%E5%90%8D%60%3A%20%E6%B8%85%E9%99%A4%E7%94%A8%E6%88%B7%E5%AF%86%E7%A0%81%0A%0A%0A%E4%BD%BF%E7%94%A8useradd%E6%8C%87%E4%BB%A4%E6%89%80%E5%BB%BA%E7%AB%8B%E7%9A%84%E5%B8%90%E5%8F%B7%EF%BC%8C%E5%AE%9E%E9%99%85%E4%B8%8A%E6%98%AF%E4%BF%9D%E5%AD%98%E5%9C%A8%2Fetc%2Fpasswd%E6%96%87%E6%9C%AC%E6%96%87%E4%BB%B6%E4%B8%AD%E3%80%82%0Apasswd%E5%91%BD%E4%BB%A4%E7%94%A8%E4%BA%8E%E8%AE%BE%E7%BD%AE%E7%94%A8%E6%88%B7%E7%9A%84%E8%AE%A4%E8%AF%81%E4%BF%A1%E6%81%AF%EF%BC%8C%E5%8C%85%E6%8B%AC%E7%94%A8%E6%88%B7%E5%AF%86%E7%A0%81%E3%80%81%E5%AF%86%E7%A0%81%E8%BF%87%E6%9C%9F%E6%97%B6%E9%97%B4%E7%AD%89%E3%80%82%E7%B3%BB%E7%BB%9F%E7%AE%A1%E7%90%86%E8%80%85%E5%88%99%E8%83%BD%E7%94%A8%E5%AE%83%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F%E7%94%A8%E6%88%B7%E7%9A%84%E5%AF%86%E7%A0%81%E3%80%82%E5%8F%AA%E6%9C%89%E7%AE%A1%E7%90%86%E8%80%85%E5%8F%AF%E4%BB%A5%E6%8C%87%E5%AE%9A%E7%94%A8%E6%88%B7%E5%90%8D%E7%A7%B0%EF%BC%8C%E4%B8%80%E8%88%AC%E7%94%A8%E6%88%B7%E5%8F%AA%E8%83%BD%E5%8F%98%E6%9B%B4%E8%87%AA%E5%B7%B1%E7%9A%84%E5%AF%86%E7%A0%81%E3%80%82%0A%0A%0A%23%23%23%204.7%20Linux%E7%B3%BB%E7%BB%9F%E7%94%A8%E6%88%B7%E7%BB%84%E7%9A%84%E7%AE%A1%E7%90%86%0A%0A%E6%AF%8F%E4%B8%AA%E7%94%A8%E6%88%B7%E9%83%BD%E6%9C%89%E4%B8%80%E4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%20Linux%E7%B3%BB%E7%BB%9F%E7%94%A8%E6%88%B7%E7%BB%84%E7%9A%84%E7%AE%A1%E7%90%86%E7%9B%B8%E5%85%B3%E5%91%BD%E4%BB%A4%3A%0A*%20%60groupadd%20%E9%80%89%E9%A1%B9%20%E7%94%A8%E6%88%B7%E7%BB%84%60%C2%A0%3A%E5%A2%9E%E5%8A%A0%E4%B8%80%E4%B8%AA%E6%96%B0%E7%9A%84%E7%94%A8%E6%88%B7%E7%BB%84%0A*%20%60groupdel%20%E7%94%A8%E6%88%B7%E7%BB%84%60%3A%E8%A6%81%E5%88%A0%E9%99%A4%E4%B8%80%E4%B8%AA%E5%B7%B2%E6%9C%89%E7%9A%84%E7%94%A8%E6%88%B7%E7%BB%84%0A*%20%60groupmod%20%E9%80%89%E9%A1%B9%20%E7%94%A8%E6%88%B7%E7%BB%84%60%C2%A0%3A%20%E4%BF%AE%E6%94%B9%E7%94%A8%E6%88%B7%E7%BB%84%E7%9A%84%E5%B1%9E%E6%80%A7%0A%0A%0A%23%23%23%204.8%20%E5%85%B6%E4%BB%96%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4%0A%0A*%20pwd%EF%BC%9A%C2%A0%E6%98%BE%E7%A4%BA%E5%BD%93%E5%89%8D%E6%89%80%E5%9C%A8%E4%BD%8D%E7%BD%AE%0A*%20grep%20%E8%A6%81%E6%90%9C%E7%B4%A2%E7%9A%84%E5%AD%97%E7%AC%A6%E4%B8%B2%20%E8%A6%81%E6%90%9C%E7%B4%A2%E7%9A%84%E6%96%87%E4%BB%B6%20--color%EF%BC%9A%C2%A0%E6%90%9C%E7%B4%A2%E5%91%BD%E4%BB%A4%EF%BC%8C--color%E4%BB%A3%E8%A1%A8%E9%AB%98%E4%BA%AE%E6%98%BE%E7%A4%BA%0A*%20ps%20-ef%2Fps%20-aux%EF%BC%9A%C2%A0%E8%BF%99%E4%B8%A4%E4%B8%AA%E5%91%BD%E4%BB%A4%E9%83%BD%E6%98%AF%E6%9F%A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B%E8%BF%9B%E7%A8%8B%EF%BC%88-9%20%E8%A1%A8%E7%A4%BA%E5%BC%BA%E5%88%B6%E7%BB%88%E6%AD%A2%E3%80%82%EF%BC%89%E5%85%88%E7%94%A8ps%E6%9F%A5%E6%89%BE%E8%BF%9B%E7%A8%8B%EF%BC%8C%E7%84%B6%E5%90%8E%E7%94%A8kill%E6%9D%80%E6%8E%89%0A%0A%0A**%E7%BD%91%E7%BB%9C%E9%80%9A%E4%BF%A1%E5%91%BD%E4%BB%A4%EF%BC%9A**%0A*%20%E6%9F%A5%E7%9C%8B%E5%BD%93%E5%89%8D%E7%B3%BB%E7%BB%9F%E7%9A%84%E7%BD%91%E5%8D%A1%E4%BF%A1%E6%81%AF%EF%BC%9Aifconfig%0A*%20%E6%9F%A5%E7%9C%8B%E4%B8%8E%E6%9F%90%E5%8F%B0%E6%9C%BA%E5%99%A8%E7%9A%84%E8%BF%9E%E6%8E%A5%E6%83%85%E5%86%B5%EF%BC%9Aping%0A*%20%E6%9F%A5%E7%9C%8B%E5%BD%93%E5%89%8D%E7%B3%BB%E7%BB%9F%E7%9A%84%E7%AB%AF%E5%8F%A3%E4%BD%BF%E7%94%A8%EF%BC%9Anetstat%20-an%0A%0A**%E7%B3%BB%E7%BB%9F%E6%9C%8D%E5%8A%A1%EF%BC%9A**%0A%0A*%201.%E5%90%AF%E5%8A%A8nfs%E6%9C%8D%E5%8A%A1%20%20%60systemctl%20start%20nfs-server.service%60%0A*%202.%E8%AE%BE%E7%BD%AE%E5%BC%80%E6%9C%BA%E8%87%AA%E5%90%AF%E5%8A%A8%20%60systemctl%20enable%20nfs-server.service%60%20%0A*%203.%E5%81%9C%E6%AD%A2%E5%BC%80%E6%9C%BA%E8%87%AA%E5%90%AF%E5%8A%A8%20%20%60systemctl%20disable%20nfs-server.service%60%0A*%204.%E6%9F%A5%E7%9C%8B%E6%9C%8D%E5%8A%A1%E5%BD%93%E5%89%8D%E7%8A%B6%E6%80%81%20%20%60systemctl%20status%20nfs-server.service%60%0A*%205.%E9%87%8D%E6%96%B0%E5%90%AF%E5%8A%A8%E6%9F%90%E6%9C%8D%E5%8A%A1%20%20%60systemctl%20restart%20nfs-server.service%60%0A*%206.%E6%9F%A5%E7%9C%8B%E6%89%80%E6%9C%89%E5%B7%B2%E5%90%AF%E5%8A%A8%E7%9A%84%E6%9C%8D%E5%8A%A1%20%20%60systemctl%20list%20-units%20--type%3Dservice%60%0A*%20%207.%20%E5%BD%BB%E5%BA%95%E5%85%B3%E9%97%AD%E9%98%B2%E7%81%AB%E5%A2%99%EF%BC%9A%0A%60sudo%20systemctl%20status%20firewalld.service%60%0A%60sudo%20systemctl%20stop%20firewalld.service%20%60%20%20%20%20%20%20%20%20%20%0A%60sudo%20systemctl%20disable%20firewalld.service%60&lt;/center&gt;&lt;/div&gt;
</content>
  </entry>
  <entry xml:base="http://linzhiteng.postach.io/feed.xml">
    <title type="text">线程总结</title>
    <id>https://linzhiteng.postach.io/post/xian-cheng-zong-jie</id>
    <updated>2019-06-09T13:07:54.104000Z</updated>
    <published>2019-03-04T06:42:46Z</published>
    <link href="https://linzhiteng.postach.io/post/xian-cheng-zong-jie" />
    <author>
      <name>linzhi teng</name>
    </author>
    <category term="xian-cheng" />
    <content type="html">&lt;div&gt;&lt;div style=&quot;font-size: 14px; margin: 0; padding: 0; width: 100%;&quot;&gt;&lt;div style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;一.线程入门
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1. 进程和多线程简介
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.1 何为进程？
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.2 何为线程？
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.3 线程和进程的关系
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.4 线程有哪些基本状态？这些状态是如何定义的?
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.5 线程的优先级
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.6 何为多线程？
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.7 为什么多线程是必要的？
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.8 为什么提倡多线程而不是多进程？
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2. 几个重要的概念
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.1 同步和异步
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.2 并发(Concurrency)和并行(Parallelism)
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.3 高并发
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.4 临界区
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.5 阻塞和非阻塞
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3. 多线程
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1 使用多线程常见的三种方式
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.2 Java多线程分类
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.3 如何设置守护线程？
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4. 一些常用方法
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.1 currentThread()
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.2 getId()
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.3 getName()
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.4 getPriority()
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.5 isAlive()
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.6 sleep(long millis)
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.7 interrupt()
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.8 interrupted() 和isInterrupted()
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.9 setName(String name)
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.10 isDaemon()
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.11 setDaemon(boolean on)
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.12 join()
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.13 yield()
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.14 setPriority(int newPriority)
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;二. 线程安全
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;0. 锁
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;0.1 为什么需要锁（并发控制）？
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;0.2 并发控制机制（锁）
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;0.3 两种锁的使用场景
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;0.4 乐观锁的缺点
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;0.5 乐观锁与悲观锁详解
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1. synchronized关键字(1)
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.1 变量安全性
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.2 多个对象对个锁
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.3 synchronized方法与锁对象
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.4 脏读
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.5 synchronized锁重入
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.6  同步不具有继承性
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2. synchronized关键字（2）
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.1 synchronized方法的缺点
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.2 synchronized（this）同步代码块的使用
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.3 synchronized（object）代码块间使用
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.4 synchronized代码块间的同步性
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.5 静态同步synchronized方法与synchronized(class)代码块
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3. volatile关键字
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1 volatile关键字简介
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.2 volatile关键字的可见性
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.3 synchronized关键字和volatile关键字比较
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4. 等待/通知（wait/notify）机制
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.1 等待/通知机制介绍
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;为什么要使用等待/通知机制？
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;概念
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.2 等待/通知机制的实现
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.3 notify()锁不释放
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;三. 线程间通信知识点补充
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1. 管道输入/输出流
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2. Thread.join()的使用
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.  ThreadLocal的使用
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1 ThreadLocal介绍
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.2 ThreadLocal方法
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.3  InheritableThreadLocal
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;四. Lock锁的使用
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1 Lock接口
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.1 Lock接口简介
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.2. Lock的简单使用
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.3. Lock接口的特性和常见方法
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2. Lock接口的实现类：ReentrantLock
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.1 ReentrantLock类常见方法
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.2 第一个ReentrantLock程序
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3. Condition接口简介
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1 使用Condition实现等待/通知机制
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4. 公平锁与非公平锁
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;5. ReadWriteLock接口的实现类：ReentrantReadWriteLock
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;5.1 简介
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;5.2 ReentrantReadWriteLock的特性与常见方法
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;5.3 ReentrantReadWriteLock的使用
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;五. 并发编程中一些问题
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1. 多线程就一定好吗？快吗？？
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2. 上下文切换
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.1 减少上下文切换
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.2 CAS算法
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.3 协程
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3. 避免死锁
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1 如何产生的死锁
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.2 避免死锁的常见方法
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.3 解决资源限制
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;六. 线程池与Executor 框架
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1. 使用线程池的好处
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2. Executor 框架
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.1 Executor 简介
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.2 Executor 框架结构(主要由三大部分组成)
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1 任务
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2 任务的执行
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3 异步计算的结果
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.3 Executor 框架的使用示意图
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3. ThreadPoolExecutor详解
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1 ThreadPoolExecutor类的四个比较重要的属性
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.2 ThreadPoolExecutor类中提供的四个构造方法
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.3 如何创建ThreadPoolExecutor
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.4 FixedThreadPool详解
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;FixedThreadPool被称为可重用固定线程数的线程池。
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;FixedThreadPool的execute()方法运行示意图
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;FixedThreadPool使用无界队列 LinkedBlockingQueue（队列的容量为Intger.MAX_VALUE）作为线程池的工作队列会对线程池带来如下影响：
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.5 SingleThreadExecutor详解
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;SingleThreadExecutor是使用单个worker线程的Executor。
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;SingleThreadExecutor的运行示意图
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.6 CachedThreadPool详解
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;CachedThreadPool的execute()方法的执行示意图
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.7 ThreadPoolExecutor使用示例
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4. ScheduledThreadPoolExecutor详解
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.1 ScheduledThreadPoolExecutor简介
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.2 ScheduledThreadPoolExecutor运行机制
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.3 ScheduledThreadPoolExecutor执行周期任务的步骤
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.4 ScheduledThreadPoolExecutor使用示例
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.4.1 ScheduledExecutorService scheduleAtFixedRate(Runnable command,long initialDelay,long period,TimeUnit unit)方法
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.4.2 ScheduledExecutorService scheduleWithFixedDelay(Runnable command,long initialDelay,long delay,TimeUnit unit)方法
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.4.3 scheduleWithFixedDelay() vs scheduleAtFixedRate()
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;5. 各种线程池的适用场景介绍
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;一.线程入门&lt;/h2&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;1. 进程和多线程简介&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.1 何为进程？&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;进程是程序的一次执行过程，是系统运行程序的基本单位，因此进程是动态的。系统运行一个程序即是一个进程从创建，运行到消亡的过程。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;一个进程就是一个执行中的程序，它在计算机中一个指令接着一个指令地执行着，同时，每个进程还占有某些系统资源如CPU时间，内存空间，文件，文件，输入输出设备的使用权等等。换句话说，当程序在执行时，将会被操作系统载入内存中。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;进程属于操作系统的范畴，主要是同一段时间内，可以同时执行一个以上的程序&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.2 何为线程？&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;线程与进程相似，但线程是一个比进程更小的执行单位。一个进程在其执行的过程中可以产生多个线程。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;与进程不同的是&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;同类的多个线程共享同一块内存空间和一组系统资源&lt;/strong&gt;，所以系统在产生一个线程，或是在各个线程之间作切换工作时，负担要比进程小得多，也正因为如此，线程也被称为轻量级进程。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;线程是在同一程序内几乎同时执行一个以上的程序段。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.3 线程和进程的关系&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;基本上各进程是独立的，而各线程则不一定，因为同一进程中的线程极有可能会相互影响。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;从另一角度来说，&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;进程属于操作系统的范畴&lt;/strong&gt;，主要是同一段时间内，可以同时执行一个以上的程序，而&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;线程&lt;/strong&gt;则是在同一程序内几乎同时执行一个以上的&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;程序段&lt;/strong&gt;。&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;线程上下文的切换比进程上下文切换要快很多&lt;/li&gt;
&lt;/ul&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;进程切换时，涉及到当前进程的CPU环境的保存和新被调度运行进程的CPU环境的设置。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;线程切换仅需要保存和设置少量的寄存器内容，不涉及存储管理方面的操作。&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.4 线程有哪些基本状态？这些状态是如何定义的?&lt;/h4&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;新建(new)：新创建了一个线程对象。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;可运行(runnable)：线程对象创建后，其他线程(比如main线程）调用了该对象的start()方法。该状态的线程位于可运行线程池中，等待被线程调度选中，获 取cpu的使用权。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;运行(running)：可运行状态(runnable)的线程获得了cpu时间片（timeslice），执行程序代码。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;阻塞(block)：阻塞状态是指线程因为某种原因放弃了cpu使用权，也即让出了cpu timeslice（时间片），暂时停止运行。直到线程进入可运行(runnable)状态，才有 机会再次获得cpu timeslice转到运行(running)状态。阻塞的情况分三种：&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;(一). 等待阻塞：运行(running)的线程执行o.wait()方法，JVM会把该线程放 入等待队列(waiting queue)中。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;(二). 同步阻塞：运行(running)的线程在获取对象的同步锁时，若该同步 锁 被别的线程占用，则JVM会把该线程放入锁池(lock pool)中。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;(三). 其他阻塞: 运行(running)的线程执行Thread.sleep(long ms)或t.join()方法，或者发出了I/O请求时，JVM会把该线程置为阻塞状态。当sleep()状态超时join()等待线程终止或者超时、或者I/O处理完毕时，线程重新转入可运行(runnable)状态。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;ol start=&quot;5&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;死亡(dead)：线程run()、main()方法执行结束，或者因异常退出了run()方法，则该线程结束生命周期。死亡的线程不可再次复生。&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/5e6a3bd7-9486-476c-a872-b01559edfd3e.jpg&quot; /&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.5 线程的优先级&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;每个线程都具有各自的优先级，线程的优先级可以在程序中表明该线程的重要性，如果有很多线程处于就绪状态，系统会根据优先级来决定首先使哪个线程进入运行状态。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;线程优先级具有继承特性比如A线程启动B线程，则B线程的优先级和A是一样的。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;线程优先级具有随机性也就是说线程优先级高的不一定每一次都先执行完。&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;Thread类中包含的成员变量代表了线程的某些优先级。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;如Thread.MIN_PRIORITY（常数1），Thread.NORM_PRIORITY（常数5）,&lt;br/&gt;
Thread.MAX_PRIORITY（常数10）。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;其中每个线程的优先级都在Thread.MIN_PRIORITY（常数1） 到Thread.MAX_PRIORITY（常数10） 之间。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;在默认情况下优先级都是Thread.NORM_PRIORITY（常数5）。&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.6 何为多线程？&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;多线程就是多个线程同时运行或交替运行。单核CPU的话是顺序执行，也就是交替运行。多核CPU的话，因为每个CPU有自己的运算器，所以在多个CPU中可以同时运行。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.7 为什么多线程是必要的？&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;开发高并发系统的基础，利用好多线程机制可以大大提高系统整体的并发能力以及性能&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.8 为什么提倡多线程而不是多进程？&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;线程就是轻量级进程，是程序执行的最小单位。使用多线程而不是用多进程去进行并发程序的设计，是因为线程间的切换和调度的成本远远小于进程。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;2. 几个重要的概念&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.1 同步和异步&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;同步和异步通常用来形容一次&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;方法调用&lt;/strong&gt;。&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;同步方法调用一旦开始，调用者必须等到方法调用返回后，才能继续后续的行为。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;异步方法调用更像一个消息传递，一旦开始，方法调用就会立即返回，调用者可以继续后续的操作。&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.2 并发(Concurrency)和并行(Parallelism)&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;它们都可以表示两个或者多个任务一起执行，但是偏重点有些不同。&lt;br/&gt;
并发偏重于多个任务交替执行，而多个任务之间有可能还是串行的。&lt;br/&gt;
而并行是真正意义上的&quot;同时执行&quot;。&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;多线程在单核CPU的话是顺序执行，也就是&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;交替运行（并发）&lt;/strong&gt;。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;多核CPU的话，因为每个CPU有自己的运算器，所以在多个CPU中可以&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;同时运行（并行）&lt;/strong&gt;。&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.3 高并发&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;高并发（High Concurrency）是互联网分布式系统架构设计中必须考虑的因素之一，它通常是指，通过设计保证系统能够同时并行处理很多请求。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;高并发相关常用的一些指标有响应时间（Response Time），吞吐量（Throughput），每秒查询率QPS（Query Per Second），并发用户数等。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.4 临界区&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;临界区用来表示一种公共资源或者说是&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;共享数据&lt;/strong&gt;，可以&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;被多个线程使用&lt;/strong&gt;。&lt;br/&gt;
但是每一次，只能有一个线程使用它，一旦临界区资源被占用，其他线程要想使用这个资源，就必须&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;等待&lt;/strong&gt;。在并行程序中，临界区资源是保护的对象。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.5 阻塞和非阻塞&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;非阻塞指在不能立刻得到结果之前，该函数不会阻塞当前线程，而会立刻返回，而阻塞与之相反。&lt;/p&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;3. 多线程&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.1 使用多线程常见的三种方式&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;继承Thread类&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;实现Runnable接口&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;使用线程池&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.2 Java多线程分类&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;用户线程&lt;/strong&gt;：运行在前台，执行具体的任务，如程序的主线程、连接网络的子线程等都是用户线程&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;守护线程&lt;/strong&gt;：运行在后台，为其他前台线程服务.也可以说守护线程是JVM中非守护线程的 &quot;佣人&quot;。&lt;br/&gt;
特点：一旦所有用户线程都结束运行，守护线程会随JVM一起结束工作&lt;br/&gt;
应用：数据库连接池中的检测线程，JVM虚拟机启动后的检测线程&lt;br/&gt;
最常见的守护线程：垃圾回收线程&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.3 如何设置守护线程？&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;通过调用Thead类的setDaemon(true)方法设置当前的线程为守护线程&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;1. setDaemon(true)必须在start()方法前执行，否则会抛出IllegalThreadStateException异常 
2.  在守护线程中产生的新线程也是守护线程 
3.  不是所有的任务都可以分配给守护线程来执行，比如读写操作或者计算逻辑
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;4. 一些常用方法&lt;/h4&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.1 currentThread()&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;返回对当前正在执行的线程对象的引用。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.2 getId()&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;返回此线程的标识符&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.3 getName()&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;返回此线程的名称&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.4 getPriority()&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;返回此线程的优先级&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.5 isAlive()&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;测试这个线程是否还处于活动状态。&lt;br/&gt;
什么是活动状态呢？&lt;br/&gt;
活动状态就是线程已经启动且尚未终止。线程处于正在运行或准备运行的状态。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.6 sleep(long millis)&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;使当前正在执行的线程以指定的毫秒数&quot;休眠&quot;（暂时停止执行），具体取决于系统定时器和调度程序的精度和准确性。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.7 interrupt()&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;中断这个线程。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.8 interrupted() 和isInterrupted()&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;interrupted()：测试当前线程是否已经是中断状态，执行后具有将状态标志清除为false的功能&lt;br/&gt;
isInterrupted()： 测试线程Thread对相关是否已经是中断状态，但部清楚状态标志&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.9 setName(String name)&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;将此线程的名称更改为等于参数 name 。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.10 isDaemon()&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;测试这个线程是否是守护线程。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.11 setDaemon(boolean on)&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;将此线程标记为 daemon线程或用户线程。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.12 join()&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;在很多情况下，主线程生成并起动了子线程，如果子线程里要进行大量的耗时的运算，主线程往往将于子线程之前结束，但是如果主线程处理完其他的事务后，需要用到子线程的处理结果，也就是&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;主线程需要等待子线程执行完成之后再结束&lt;/strong&gt;，这个时候就要用到join()方法了。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;join()的作用是：&quot;等待该线程终止&quot;，这里需要理解的就是该线程是指的主线程等待子线程的终止。也就是在子线程调用了join()方法后面的代码，只有等到子线程结束了才能执行&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.13 yield()&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;yield()方法的作用是放弃当前的CPU资源，将它让给其他的任务去占用CPU时间。注意：放弃的时间不确定，可能一会就会重新获得CPU时间片。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.14 setPriority(int newPriority)&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;更改此线程的优先级&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;二. 线程安全&lt;/h2&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;0. 锁&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;0.1 为什么需要锁（并发控制）？&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;在多用户环境中，在同一时间可能会有多个用户更新相同的记录，这会产生&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;冲突&lt;/strong&gt;。这就是著名的并发性问题。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0;&quot;&gt;典型的冲突有：&lt;/p&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;丢失更新：一个事务的更新覆盖了其它事务的更新结果，就是所谓的更新丢失。例如：用户A把值从6改为2，用户B把值从2改为6，则用户A丢失了他的更新。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;脏读：当一个事务读取其它完成一半事务的记录时，就会发生脏读取。例如：用户A,B看到的值都是6，用户B把值改为2，用户A读到的值仍为6。&lt;/li&gt;
&lt;/ol&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;为了解决这些并发带来的问题。 我们需要引入并发控制机制。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;0.2 并发控制机制（锁）&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;悲观锁&lt;/li&gt;
&lt;/ul&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;总是假设最坏的情况，每次去拿数据的时候都认为别人会修改，所以每次在拿数据的时候都会上锁，这样别人想拿这个数据就会阻塞直到它拿到锁（共享资源每次只给一个线程使用，其它线程阻塞，用完后再把资源转让给其它线程）。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;传统的关系型数据库里边就用到了很多这种锁机制，比如行锁，表锁等，读锁，写锁等，都是在做操作之前先上锁。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;Java中synchronized和ReentrantLock等独占锁就是悲观锁思想的实现。&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;乐观锁&lt;/li&gt;
&lt;/ul&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;总是假设最好的情况，每次去拿数据的时候都认为别人不会修改，所以不会上锁，但是在更新的时候会判断一下在此期间别人有没有去更新这个数据，可以使用版本号机制和CAS算法实现。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;乐观锁适用于多读的应用类型，这样可以提高吞吐量，像数据库提供的类似于write_condition机制，其实都是提供的乐观锁。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;在Java中java.util.concurrent.atomic包下面的原子变量类就是使用了乐观锁的一种实现方式CAS实现的。&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;0.3 两种锁的使用场景&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;乐观锁适用于写比较少的情况下（多读场景），即冲突真的很少发生的时候，这样可以省去了锁的开销，加大了系统的整个吞吐量。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;但如果是多写的情况，一般会经常产生冲突，这就会导致上层应用会不断的进行retry，这样反倒是降低了性能，所以一般多写的场景下用悲观锁就比较合适。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;0.4 乐观锁的缺点&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;ABA 问题&lt;/strong&gt;&lt;br/&gt;
如果一个变量V初次读取的时候是A值，并且在准备赋值的时候检查到它仍然是A值，那我们就能说明它的值没有被其他线程修改过了吗？很明显是不能的，因为在这段时间它的值可能被改为其他值，然后又改回A，那CAS操作就会误认为它从来没有被修改过。这个问题被称为CAS操作的 &quot;ABA&quot;问题。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;循环时间长开销大&lt;/strong&gt;&lt;br/&gt;
自旋CAS（也就是不成功就一直循环执行直到成功）如果长时间不成功，会给CPU带来非常大的执行开销。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;只能保证一个共享变量的原子操作&lt;/strong&gt;&lt;br/&gt;
CAS 只对单个共享变量有效，当操作涉及跨多个共享变量时 CAS 无效。&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;0.5 乐观锁与悲观锁详解&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;a href=&quot;https://blog.csdn.net/qq_34337272/article/details/81072874&quot; style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;乐观锁与悲观锁详解&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;hr style=&quot;line-height: 160%; box-sizing: content-box; border-top: 1px solid #eee; margin: 16px 0;&quot;/&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;1. synchronized关键字(1)&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/d8793a70-f006-4121-9ada-0d69a9d827b4.jpg&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;a href=&quot;https://blog.csdn.net/qq_34337272/article/details/79655194&quot; style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;synchronized关键字1&lt;/a&gt;&lt;/p&gt;
&lt;hr style=&quot;line-height: 160%; box-sizing: content-box; border-top: 1px solid #eee; margin: 16px 0;&quot;/&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;synchronized&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;Java并发编程这个领域中synchronized关键字一直都是元老级的角色，很久之前很多人都会称它为 &quot;重量级锁&quot; 。&lt;br/&gt;
但是，在JavaSE 1.6之后进行了主要包括为了减少获得锁和释放锁带来的性能消耗而引入的 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;偏向锁&lt;/strong&gt;和 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;轻量级锁&lt;/strong&gt; 以及其它各种优化之后变得在某些情况下并不是那么重了。synchronized的底层实现主要依靠 Lock-Free 的队列，基本思路是 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;自旋后阻塞&lt;/strong&gt;，&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;竞争切换后继续竞争锁&lt;/strong&gt;，稍微牺牲了公平性，但获得了高吞吐量。在线程冲突较少的情况下，可以获得和CAS类似的性能；而线程冲突严重的情况下，性能远高于CAS。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.1 变量安全性&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&quot;非线程安全&quot;(线程不安全) 问题存在于&quot;实例变量&quot;中，如果是方法内部的私有变量，则不存在&quot;非线程安全&quot;，所得结果也就是&quot;线程安全&quot;的了。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;如果两个线程同时操作对象中的实例变量，则会出现&quot;&lt;u style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;非线程安全&lt;/u&gt;&quot;，解决办法就是在方法前加上&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;synchronized&lt;/strong&gt;关键字即可。&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.2 多个对象对个锁&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;synchronized取得的锁都是&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;对象锁&lt;/strong&gt;，而不是把一段代码或方法当做锁。所以在上面的实例中，哪个线程先执行带synchronized关键字的方法，则哪个线程就持有该方法所属对象的锁Lock，那么其他线程只能呈等待状态，前提是多个线程访问的是&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;同一个对象&lt;/strong&gt;。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.3 synchronized方法与锁对象&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;synchronized取得的锁都是对象锁，而不是把一段代码或方法当做锁。如果多个线程访问的是同一个对象，哪个线程先执行带synchronized关键字的方法，则哪个线程就持有该方法，那么其他线程只能呈等待状态。&lt;br/&gt;
如果多个线程访问的是多个对象则不一定，因为多个对象会产生多个锁。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.4 脏读&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;发生脏读的情况是在读取实例变量时，此值已经被其他线程更改过。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;代码没有做同步，虽然set方法同步，但是由于get方法一般都会忘了，导致读的值是被写过的&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.5 synchronized锁重入&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;可重入锁&quot;概念是：自己可以再次获取自己的内部锁。比如一个线程获得了某个对象的锁，此时这个对象锁还没有释放，当其再次想要获取这个对象的锁的时候还是可以获取的，如果不可锁重入的话，就会造成死锁。&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.6  同步不具有继承性&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;如果父类有一个带synchronized关键字的方法，子类继承并重写了这个方法。 但是同步不能继承，所以还是需要在子类方法中添加synchronized关键字。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;2. synchronized关键字（2）&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/0f8be4bb-b892-4198-8904-963482ade8f8.jpg&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;a href=&quot;https://blog.csdn.net/qq_34337272/article/details/79670775&quot; style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;synchronized关键字2&lt;/a&gt;&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.1 synchronized方法的缺点&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;使用synchronized关键字声明方法有些时候是有很大的弊端的，比如我们有两个线程一个线程A调用同步方法后获得锁，那么另一个线程B就需要等待A执行完，但是如果说A执行的是一个很费时间的任务的话这样就会很耗时。&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;可以使用&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;synchronized同步块&lt;/strong&gt;来解决这个问题。但是要注意synchronized同步块的使用方式，如果synchronized同步块使用不好的话并不会带来效率的提升。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.2 synchronized（this）同步代码块的使用&lt;/h4&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;Task&lt;/span&gt; &lt;/span&gt;{

    &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;private&lt;/span&gt; String getData1;
    &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;private&lt;/span&gt; String getData2;

    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;doLongTimeTask&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;try&lt;/span&gt; {
            System.out.println(&lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;begin task&quot;&lt;/span&gt;);
            Thread.sleep(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;3000&lt;/span&gt;);

            String privateGetData1 = &lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;长时间处理任务后从远程返回的值1 threadName=&quot;&lt;/span&gt;
                    + Thread.currentThread().getName();
            String privateGetData2 = &lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;长时间处理任务后从远程返回的值2 threadName=&quot;&lt;/span&gt;
                    + Thread.currentThread().getName();

            &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;synchronized&lt;/span&gt; (&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;this&lt;/span&gt;) {
                getData1 = privateGetData1;
                getData2 = privateGetData2;
            }

            System.out.println(getData1);
            System.out.println(getData2);
            System.out.println(&lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;end task&quot;&lt;/span&gt;);
        } &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;catch&lt;/span&gt; (InterruptedException e) {
            &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;// TODO Auto-generated catch block&lt;/span&gt;
            e.printStackTrace();
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;当一个线程访问一个对象的synchronized同步代码块时，另一个线程任然可以访问该对象非synchronized同步代码块。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;不在synchronized代码块中就异步执行，在synchronized代码块中就是同步执行。&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.3 synchronized（object）代码块间使用&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;两个线程使用了同一个&quot;对象监视器&quot;,所以运行结果是同步的。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;两个线程使用了不同的&quot;对象监视器&quot;,所以运行结果不是同步的了。&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.4 synchronized代码块间的同步性&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;当一个对象访问synchronized(this)代码块时，其他线程对同一个对象中所有其他synchronized(this)代码块代码块的访问将被阻塞，这说明synchronized(this)代码块使用的&quot;对象监视器&quot;是同一个。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;和synchronized方法一样，synchronized(this)代码块也是锁定当前对象。&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;其他线程执行对象中synchronized同步方法和synchronized(this)代码块时呈现同步效果;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;如果两个线程使用了同一个&quot;对象监视器&quot;,运行结果同步，否则不同步.&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.5 静态同步synchronized方法与synchronized(class)代码块&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;synchronized关键字加到static静态方法和synchronized(class)代码块上都是是&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;给Class类上锁&lt;/strong&gt;，而synchronized关键字加到&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;非静态方法&lt;/strong&gt;上是给&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;对象上锁&lt;/strong&gt;。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;静态同步synchronized方法与synchronized(class)代码块持有的锁一样，都是Class锁，Class锁对对象的所有实例起作用。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;3. volatile关键字&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/e6fb41c0-7e51-49af-8a93-15eb018adb0b.jpg&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;a href=&quot;https://blog.csdn.net/qq_34337272/article/details/79680771&quot; style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;volatile关键字&lt;/a&gt;&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.1 volatile关键字简介&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;volatile关键字可以用来提醒编译器它后面所定义的变量随时有可能改变，因此编译后的程序每次需要存储或读取这个变量的时候，都会直接从变量地址中读取数。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;如果没有volatile关键字，则编译器可能优化读取和存储，可能暂时使用寄存器中的值，如果这个变量由别的程序更新了的话，将出现不一致的现象。&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.2 volatile关键字的可见性&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;volatile 修饰的成员变量在每次被线程访问时，都强迫从主存（共享内存）中重读该成员变量的值。而且，当成员变量发生变化时，强迫线程将变化值回写到主存（共享内存）。这样在任何时刻，两个不同的线程总是看到某个成员变量的同一个值，这样也就保证了同步数据的可见性。&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/58194c29-083b-40ee-a3b8-4a1eba18ab33.jpg&quot; /&gt;&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/411ee538-1a11-4cc5-a04d-c547f2f44d03.jpg&quot; /&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.3 synchronized关键字和volatile关键字比较&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;volatile关键字是&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;线程同步的轻量级实现&lt;/strong&gt;，所以volatile性能肯定比synchronized关键字要好。但是&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;volatile关键字只能用于变量&lt;/strong&gt;而synchronized关键字可以修饰方法以及代码块。synchronized关键字在JavaSE1.6之后进行了主要包括为了减少获得锁和释放锁带来的性能消耗而引入的偏向锁和轻量级锁以及其它各种优化之后执行效率有了显著提升，实际开发中使用synchronized关键字还是更多一些。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;多线程访问volatile关键字不会发生阻塞，而synchronized关键字可能会发生阻塞&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;volatile关键字能保证数据的可见性，但不能保证数据的原子性。synchronized关键字两者都能保证。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;volatile关键字用于解决变量在多个线程之间的可见性，而ynchronized关键字解决的是多个线程之间访问资源的同步性。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;4. 等待/通知（wait/notify）机制&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;4.1 等待/通知机制介绍&lt;/h4&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;为什么要使用等待/通知机制？&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;当两个线程之间存在生产和消费者关系，也就是说第一个线程（生产者）做相应的操作然后第二个线程（消费者）感知到了变化又进行相应的操作。&lt;br/&gt;
第二个语句不停过通过轮询机制来检测判断条件是否成立。如果轮询时间的间隔太小会浪费CPU资源，轮询时间的间隔太大，就可能取不到自己想要的数据。所以这里就需要我们今天讲到的等待/通知（wait/notify）机制来解决这两个矛盾。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;概念&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;等待/通知机制，是指一个线程A调用了对象O的wait()方法进入等待状态，而另一个线程B调用了对象O的notify()/notifyAll()方法，线程A收到通知后退出等待队列，进入可运行状态，进而执行后续操作。上诉两个线程通过对象O来完成交互，而对象上的wait()方法和notify()/notifyAll()方法的关系就如同开关信号一样，用来完成等待方和通知方之间的交互工作。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;4.2 等待/通知机制的实现&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;notify()执行后并不会立即释放锁&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;synchronized关键字可以将任何一个Object对象作为同步对象来看待，而Java为每个Object都实现了等待/通知（wait/notify）机制的相关方法，它们必须用在synchronized关键字同步的Object的临界区内。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;通过调用wait()方法可以使处于临界区内的线程进入等待状态，同时释放被同步对象的锁。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;而notify()方法可以唤醒一个因调用wait操作而处于阻塞状态中的线程，使其进入就绪状态。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;被重新唤醒的线程会试图重新获得临界区的控制权也就是锁，并继续执行wait方法之后的代码。&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;4.3 notify()锁不释放&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;当方法wait()被执行后，锁自动被释放，但执行完notify()方法后，锁不会自动释放。必须&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;执行完notify()方法所在的synchronized代码块后&lt;/strong&gt;才释放。&lt;/p&gt;
&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;三. 线程间通信知识点补充&lt;/h2&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/bd785765-9ac1-4b0a-a11f-366ae86fbdcf.jpg&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;a href=&quot;https://blog.csdn.net/qq_34337272/article/details/79694226&quot; style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;线程通信知识补充&lt;/a&gt;&lt;/p&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;1. 管道输入/输出流&lt;/h3&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;管道输入/输出流主要用于线程之间的数据传输，而且传输的媒介为内存。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;管道输入/输出流主要包括下列两类的实现：&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;面向字节： PipedOutputStream、 PipedInputStream&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;面向字符: PipedWriter、 PipedReader&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;2. Thread.join()的使用&lt;/h3&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;在很多情况下，主线程生成并起动了子线程，如果子线程里要进行大量的耗时的运算，主线程往往将于子线程之前结束，但是如果主线程处理完其他的事务后，需要用到子线程的处理结果，也就是主线程需要等待子线程执行完成之后再结束，这个时候就要用到join()方法了。另外，一个线程需要等待另一个线程也需要用到join()方法。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;Thread类除了提供join()方法之外，还提供了join(long millis)、join(long millis, int nanos)两个具有超时特性的方法。这两个超时方法表示，如果线程thread在指定的超时时间没有终止，那么将会从该超时方法中返回。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;Thread.sleep(2000)不会释放锁，threadTest.join(2000)会释放锁 。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;3.  ThreadLocal的使用&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.1 ThreadLocal介绍&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;变量值的共享可以使用public static变量的形式，所有线程都使用一个public static变量。如果想实现&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;每一个线程都有自己的共享变量&lt;/strong&gt;该如何解决呢？&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;JDK中提供的ThreadLocal类正是为了解决这样的问题。ThreadLocal类主要解决的就是让&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;每个线程绑定自己的值&lt;/strong&gt;，可以将ThreadLocal类形象的比喻成存放数据的盒子，盒子中可以存储每个线程的私有数据。&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.2 ThreadLocal方法&lt;/h4&gt;
&lt;table style=&quot;margin: 2px 0 14px; color: #333; width: auto; border-collapse: collapse; box-sizing: border-box;&quot;&gt;&lt;thead style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;方法名称&lt;/th&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;描述&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;get()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;返回当前线程的此线程局部变量的副本中的值。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;set(T value)&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;将当前线程的此线程局部变量的副本设置为指定的值&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;remove()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;删除此线程局部变量的当前线程的值&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;initialValue()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;返回此线程局部变量的当前线程的&quot;初始值&quot;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.3  InheritableThreadLocal&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;ThreadLocal类固然很好，但是子线程并不能取到父线程的ThreadLocal类的变量，InheritableThreadLocal类就是解决这个问题的。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;在使用InheritableThreadLocal类需要注意的一点是：如果子线程在取得值的同时，主线程将InheritableThreadLocal中的值进行更改，那么子线程取到的还是旧值。&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;四. Lock锁的使用&lt;/h2&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/7174644d-315f-47ad-be23-1431f3b7a2b4.jpg&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;a href=&quot;https://blog.csdn.net/qq_34337272/article/details/79714196&quot; style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;lock锁的使用&lt;/a&gt;&lt;/p&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;1 Lock接口&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.1 Lock接口简介&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;锁是用于通过多个线程&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;控制对共享资源的访问&lt;/strong&gt;的工具。&lt;br/&gt;
通常，锁提供对&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;共享资源的独占访问&lt;/strong&gt;：一次只能有一个线程可以获取锁，并且对共享资源的所有访问都要求首先获取锁。&lt;br/&gt;
但是，一些锁可能允许并发访问共享资源，如ReadWriteLock的读写锁。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;在Lock接口出现之前，Java程序是靠synchronized关键字实现锁功能的。JDK1.5之后并发包中新增了Lock接口以及相关实现类来实现锁功能。&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0;&quot;&gt;Lock接口的实现类：&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;ReentrantLock&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;ReentrantReadWriteLock.ReadLock&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;ReentrantReadWriteLock.WriteLock&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.2. Lock的简单使用&lt;/h4&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt; Lock lock = &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; ReentrantLock()； 
 lock.lock(); 
 &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;try&lt;/span&gt;{ 
 }&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;finally&lt;/span&gt;{ 
 lock.unlock(); 
 }
&lt;/code&gt;&lt;/pre&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;因为Lock是接口所以使用时要结合它的实现类，另外在finall语句块中释放锁的目的是保证获取到锁之后，最终能够被释放。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;注意： 最好不要把获取锁的过程写在try语句块中，因为如果在获取锁时发生了异常，异常抛出的同时也会导致锁无法被释放。&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.3. Lock接口的特性和常见方法&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;Lock接口提供的synchronized关键字不具备的主要特性：&lt;/li&gt;
&lt;/ul&gt;
&lt;table style=&quot;margin: 2px 0 14px; color: #333; width: auto; border-collapse: collapse; box-sizing: border-box;&quot;&gt;&lt;thead style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;特性&lt;/th&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;描述&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;尝试非阻塞地获取锁&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;当前线程尝试获取锁，如果这一时刻锁没有被其他线程获取到，则成功获取并持有锁&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;能被中断地获取锁&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;获取到锁的线程能够响应中断，当获取到锁的线程被中断时，中断异常将会被抛出，同时锁会被释放&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;超时获取锁&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;在指定的截止时间之前获取锁， 超过截止时间后仍旧无法获取则返回&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;Lock接口基本的方法：&lt;/li&gt;
&lt;/ul&gt;
&lt;table style=&quot;margin: 2px 0 14px; color: #333; width: auto; border-collapse: collapse; box-sizing: border-box;&quot;&gt;&lt;thead style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;方法名称&lt;/th&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;描述&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;void lock()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;获得锁。如果锁不可用，则当前线程将被禁用以进行线程调度，并处于休眠状态，直到获取锁。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;void lockInterruptibly()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;获取锁，如果可用并立即返回。如果锁不可用，那么当前线程将被禁用以进行线程调度，并且处于休眠状态，和lock()方法不同的是在锁的获取中可以中断当前线程（相应中断）。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;Condition newCondition()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;获取等待通知组件，该组件和当前的锁绑定，当前线程只有获得了锁，才能调用该组件的wait()方法，而调用后，当前线程将释放锁。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;boolean tryLock()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;只有在调用时才可以获得锁。如果可用，则获取锁定，并立即返回值为true；如果锁不可用，则此方法将立即返回值为false 。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;boolean tryLock(long time, TimeUnit unit)&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;超时获取锁，当前线程在一下三种情况下会返回： 1. 当前线程在超时时间内获得了锁；2.当前线程在超时时间内被中断；3.超时时间结束，返回false.&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;void unlock()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;释放锁。&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;2. Lock接口的实现类：ReentrantLock&lt;/h3&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;ReentrantLock和synchronized关键字一样可以用来实现线程之间的同步互斥，但是在功能是比synchronized关键字更强大而且更灵活。&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.1 ReentrantLock类常见方法&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;构造方法：&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;table style=&quot;margin: 2px 0 14px; color: #333; width: auto; border-collapse: collapse; box-sizing: border-box;&quot;&gt;&lt;thead style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;方法名称&lt;/th&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;描述&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;ReentrantLock()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;创建一个 ReentrantLock的实例。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;ReentrantLock(boolean fair)&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;创建一个特定锁类型（公平锁/非公平锁）的ReentrantLock的实例&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;ReentrantLock类常见方法(Lock接口已有方法这里没加上)：&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;table style=&quot;margin: 2px 0 14px; color: #333; width: auto; border-collapse: collapse; box-sizing: border-box;&quot;&gt;&lt;thead style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;方法名称&lt;/th&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;描述&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;int getHoldCount()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;查询当前线程保持此锁定的个数，也就是调用lock()方法的次数。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;protected Thread getOwner()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;返回当前拥有此锁的线程，如果不拥有，则返回 null&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;protected Collection getQueuedThreads()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;返回包含可能正在等待获取此锁的线程的集合&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;int getQueueLength()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;返回等待获取此锁的线程数的估计。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;protected Collection getWaitingThreads(Condition condition)&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;返回包含可能在与此锁相关联的给定条件下等待的线程的集合。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;int getWaitQueueLength(Condition condition)&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;返回与此锁相关联的给定条件等待的线程数的估计。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;boolean hasQueuedThread(Thread thread)&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;查询给定线程是否等待获取此锁。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;boolean hasQueuedThreads()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;查询是否有线程正在等待获取此锁。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;boolean hasWaiters(Condition condition)&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;查询任何线程是否等待与此锁相关联的给定条件&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;boolean isFair()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;如果此锁的公平设置为true，则返回 true 。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;boolean isHeldByCurrentThread()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;查询此锁是否由当前线程持有。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;boolean isLocked()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;查询此锁是否由任何线程持有。&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.2 第一个ReentrantLock程序&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;当一个线程运行完毕后才把锁释放，其他线程才能执行，其他线程的执行顺序是不确定的。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;3. Condition接口简介&lt;/h3&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;synchronized关键字与wait()和notify/notifyAll()方法相结合可以实现等待/通知机制，ReentrantLock类当然也可以实现，但是需要借助于Condition接口与newCondition() 方法。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;Condition是JDK1.5之后才有的，它具有很好的灵活性，比如可以实现&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;多路通知功&lt;/strong&gt;能，也就是在一个Lock对象中可以创建多个Condition实例（即对象监视器），线程对象可以注册在指定的Condition中，从而可以有选择性的进行线程通知，在调度线程上更加灵活。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;在使用notify/notifyAll()方法进行通知时，被通知的线程是有JVM选择的，使用ReentrantLock类结合Condition实例可以实现&quot;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;选择性通知&lt;/strong&gt;&quot;，这个功能非常重要，而且是Condition接口默认提供的。&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;Condition接口的常见方法：&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;table style=&quot;margin: 2px 0 14px; color: #333; width: auto; border-collapse: collapse; box-sizing: border-box;&quot;&gt;&lt;thead style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;方法名称&lt;/th&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;描述&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;void await()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;相当于Object类的wait方法&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;boolean await(long time, TimeUnit unit)&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;相当于Object类的wait(long timeout)方法&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;signal()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;相当于Object类的notify方法&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;signalAll()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;相当于Object类的notifyAll方法&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;synchronized关键字就相当于整个Lock对象中只有一个Condition实例，所有的线程都注册在它一个身上。如果执行notifyAll()方法的话就会通知所有处于等待状态的线程这样会造成很大的效率问题，而Condition实例的signalAll()方法 只会唤醒注册在该Condition实例中的所有等待线程&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.1 使用Condition实现等待/通知机制&lt;/h4&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;使用单个Condition实例实现等待/通知机制：&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;必须执行完signal所在的try语句块之后才释放锁，condition.await()后的语句才能被执行。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;注意： 必须在condition.await()方法调用之前调用lock.lock()代码获得同步监视器，不然会报错。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;ol start=&quot;2&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;使用多个Condition实例实现等待/通知机制：&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;实现&quot;选择性通知&quot;,只会唤醒注册在指定Condition实例中的所有等待线程&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;ol start=&quot;3&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;使用Condition实现顺序执行&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;在一个线程运行完之后通过condition.signal()/condition.signalAll()方法通知下一个特定的线程运行，就这样循环往复即可。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;注意： 默认情况下ReentranLock类使用的是非公平锁&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;4. 公平锁与非公平锁&lt;/h3&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;Lock锁分为：公平锁 和 非公平锁。&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;公平锁表示线程获取锁的顺序是按照线程加锁的顺序来分配的，即先来先得的FIFO先进先出顺序。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;而非公平锁就是一种获取锁的抢占机制，是随机获取锁的，和公平锁不一样的就是先来的不一定先的到锁，这样可能造成某些线程一直拿不到锁，结果也就是不公平的了。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;5. ReadWriteLock接口的实现类：ReentrantReadWriteLock&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;5.1 简介&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;ReentrantLock（排他锁）具有完全互斥排他的效果，即同一时刻只允许一个线程访问，这样做虽然虽然保证了实例变量的线程安全性，但效率非常低下。&lt;br/&gt;
ReadWriteLock接口的实现类-ReentrantReadWriteLock读写锁就是为了解决这个问题。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;读写锁维护了两个锁，一个是&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;读操作&lt;/strong&gt;相关的锁也成为&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;共享锁&lt;/strong&gt;，&lt;br/&gt;
一个是&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;写操作&lt;/strong&gt;相关的锁也称为&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;排他锁&lt;/strong&gt;。&lt;br/&gt;
通过分离读锁和写锁，其并发性比一般排他锁有了很大提升。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;多个读锁之间不互斥，读锁与写锁互斥，写锁与写锁互斥（只要出现写操作的过程就是互斥的）&lt;br/&gt;
在没有线程Thread进行写入操作时，进行读取操作的多个Thread都可以获取读锁，&lt;br/&gt;
而进行写入操作的Thread只有在获取写锁后才能进行写入操作。&lt;br/&gt;
即多个Thread可以&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;同时进行读取操作&lt;/strong&gt;,但是同一时刻&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;只允许一个Thread进行写入操作&lt;/strong&gt;。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;5.2 ReentrantReadWriteLock的特性与常见方法&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;ReentrantReadWriteLock的特性：&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;table style=&quot;margin: 2px 0 14px; color: #333; width: auto; border-collapse: collapse; box-sizing: border-box;&quot;&gt;&lt;thead style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;特性&lt;/th&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;说明&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;公平性选择&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;支持非公平（默认）和公平的锁获取方式，吞吐量上来看还是非公平优于公平&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;重进入&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;该锁支持重进入，以读写线程为例：读线程在获取了读锁之后，能够再次获取读锁。而写线程在获取了写锁之后能够再次获取写锁也能够同时获取读锁&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;锁降级&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;遵循获取写锁、获取读锁再释放写锁的次序，写锁能够降级称为读锁&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;ReentrantReadWriteLock常见方法：&lt;br/&gt;
 构造方法&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;table style=&quot;margin: 2px 0 14px; color: #333; width: auto; border-collapse: collapse; box-sizing: border-box;&quot;&gt;&lt;thead style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;方法名称&lt;/th&gt;&lt;th style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #72777b; border-top: 0; background-color: #7b8184; font-weight: 300; color: #fff; padding-top: 6px;&quot;&gt;描述&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;ReentrantReadWriteLock()&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;创建一个 ReentrantReadWriteLock()的实例&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;ReentrantReadWriteLock(boolean fair)&lt;/td&gt;&lt;td style=&quot;line-height: 160%; box-sizing: content-box;  padding: 5px 14px 5px 12px; border: 1px solid #eaeaea;&quot;&gt;创建一个特定锁类型（公平锁/非公平锁）的ReentrantReadWriteLock的实例&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;常见方法： &lt;br/&gt;
和ReentrantLock类 类似&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;5.3 ReentrantReadWriteLock的使用&lt;/h4&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;读读共享
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;两个线程同时运行read方法，你会发现两个线程可以同时或者说是几乎同时运行lock()方法后面的代码，输出的两句话显示的时间一样。这样提高了程序的运行效率。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;写写互斥
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;两个线程同时运行write方法，你会发现同一时间只允许一个线程执行lock()方法后面的代码&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;读写互斥（读写互斥）
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0;&quot;&gt;运行两个使用同一个Service对象实例的线程a,b，线程a执行上面的read方法，线程b执行上面的write方法。你会发现同一时间只允许一个线程执行lock()方法后面的代码。&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;记住：只要出现写操作的过程就是互斥的。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;五. 并发编程中一些问题&lt;/h2&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/1c7d6d29-4444-4622-a12d-4f1d48fb4f6a.jpg&quot; /&gt;&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;a href=&quot;https://blog.csdn.net/qq_34337272/article/details/79844051&quot; style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;并发编程的问题&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;1. 多线程就一定好吗？快吗？？&lt;/h3&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;并发编程的目的就是为了能提高程序的执行效率提高程序运行速度，但是并发编程并不总是能提高程序运行速度的，而且并发编程可能会遇到很多问题，&lt;br/&gt;
比如：内存泄漏、&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;上下文切换&lt;/strong&gt;、&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;死锁&lt;/strong&gt;还有受限于硬件和软件的资源闲置问题。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;多线程就是几乎同时执行多个线程（一个处理器在某一个时间点上永远都只能是一个线程！即使这个处理器是多核的，除非有多个处理器才能实现多个线程同时运行）。CPU通过给每个线程分配CPU时间片来实现伪同时运行，因为CPU时间片一般很短很短，所以给人一种同时运行的感觉。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;2. 上下文切换&lt;/h3&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;当前任务在执行完CPU时间片切换到另一个任务之前会先保存自己的状态，以便下次再切换会这个任务时，可以再加载这个任务的状态。任务从&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;保存到再加载的过程&lt;/strong&gt;就是一次上下文切换。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;上下文切换通常是计算密集型的。也就是说，它需要相当可观的处理器时间，在每秒几十上百次的切换中，每次切换都需要纳秒量级的时间。所以，上下文切换对系统来说意味着消耗大量的 CPU 时间，事实上，可能是操作系统中时间消耗最大的操作。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.1 减少上下文切换&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;上下文切换又分为2种：&lt;/li&gt;
&lt;/ul&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;让步式上下文切换&lt;br/&gt;
指执行线程主动释放CPU，与锁竞争严重程度成正比，可通过&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;减少锁竞争&lt;/strong&gt;和使用&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;CAS算法&lt;/strong&gt;来避免；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;抢占式上下文切换。&lt;br/&gt;
指线程因分配的时间片用尽而被迫放弃CPU或者被其他优先级更高的线程所抢占，一般由于线程数大于CPU可用核心数引起，可通过适当&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;减少线程数&lt;/strong&gt;和使用&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;协程&lt;/strong&gt;来避免。&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;总结一下：&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;减少锁的使用。因为多线程竞争锁时会引起上下文切换。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;使用CAS算法。这种算法也是为了减少锁的使用。CAS算法是一种无锁算法。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;减少线程的使用。人物很少的时候创建大量线程会导致大量线程都处于等待状态。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;使用协程。&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.2 CAS算法&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;CAS（比较与交换，Compare and swap） 是一种有名的无锁算法。无锁编程，即不使用锁的情况下实现多线程之间的变量同步，也就是在没有线程被阻塞的情况下实现变量的同步，所以也叫非阻塞同步（Non-blocking Synchronization）。&lt;br/&gt;
实现非阻塞同步的方案称为&quot;无锁编程算法&quot;（ Non-blocking algorithm）。 属于乐观锁。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;CAS算法涉及到三个操作数&lt;/strong&gt;&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;需要读写的内存值V&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;进行比较的值A&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;拟写入的新值B&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;当且仅当 V 的值等于 A时，CAS通过原子方式用新值B来更新V的值，否则不会执行任何操作（比较和替换是一个原子操作）。一般情况下是一个自旋操作，即不断的重试。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.3 协程&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;协程也可以说是微线程或者说是轻量级的线程，它占用的内存更少并且更灵活。很多编程语言中都有协程。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;3. 避免死锁&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.1 如何产生的死锁&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;在操作系统中，死锁是指两个或两个以上的进程在执行过程中，由于竞争资源或者由于彼此通信而造成的一种阻塞的现象，若无外力作用，它们都将无法推进下去。此时称系统处于死锁状态或系统产生了死锁，这些永远在互相等待的进程称为死锁进程。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;在线程中，如果两个线程同时等待对方释放锁也会产生死锁。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.2 避免死锁的常见方法&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;避免一个线程同时获得多个锁&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;避免一个线程在锁内同时占用多个资源，尽量保证每个锁只占用一个资源&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;尝试使用定时锁，使用lock.tryLock(timeout)来替代使用内部锁机制&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;对于数据库锁，加锁和解锁必须在一个数据库连接里，否则会出现解锁失败的情况&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.3 解决资源限制&lt;/h4&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;什么是资源限制？&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;所谓资源限制就是我们在进行并发编程时，程序的运行速度受限于计算机硬件资源比如CPU,内存等等或软件资源比如软件的质量、性能等等。举个例子：如果说服务器的带宽只有2MB/s，某个资源的下载速度是1MB/s，系统启动10个线程下载该资源并不会导致下载速度编程10MB/s，所以在并发编程时，需要考虑这些资源的限制。硬件资源限制有：带宽的上传和下载速度、硬盘读写速度和CPU处理速度；软件资源限制有数据库的连接数、socket连接数、软件质量和性能等等。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ol start=&quot;2&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;资源限制引发的问题&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;在并发编程中，程序运行加快的原因是运行方式从串行运行变为并发运行，但是如果某段程序的并发执行由于资源限制仍然在串行执行的话，这时候程序的运行不仅不会加快，反而会更慢，因为可能增加了上下文切换和资源调度的时间。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;3.&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;如何解决资源限制的问题&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;对于硬件资源限制，可以考虑使用集群并行执行程序。既然单机的资源有限制，那么就让程序在多机上运行。比如使用Hadoop或者自己搭建服务器集群。&lt;br/&gt;
对于软件资源的限制，可以考虑使用资源池将资源复用。比如使用连接池将数据库和Socket复用，或者在调用对方webservice接口获取数据时，只建立一个连接。另外还可以考虑使用良好的开源软件。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ol start=&quot;4&quot; style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;在资源限制的情况下如何进行并发编程&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;根据不同的资源限制调整程序的并发度，比如下载文件程序依赖于两个资源-带宽和硬盘读写速度。有数据库操作时，设计数据库练连接数，如果SQL语句执行非常快，而线程的数量比数据库连接数大很多，则某些线程会被阻塞，等待数据库连接。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;六. 线程池与Executor 框架&lt;/h2&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/c9c32249-a785-4ff3-bde9-0395dafc2608.jpg&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;a href=&quot;https://blog.csdn.net/qq_34337272/article/details/79959271&quot; style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;线程池与Executor框架&lt;/a&gt;&lt;/p&gt;
&lt;hr style=&quot;line-height: 160%; box-sizing: content-box; border-top: 1px solid #eee; margin: 16px 0;&quot;/&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;1. 使用线程池的好处&lt;/h3&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;线程池提供了一种限制和管理资源（包括执行一个任务）。 每个线程池还维护一些基本统计信息&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0;&quot;&gt;使用线程池的好处&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;降低资源消耗。通过重复利用已创建的线程降低线程创建和销毁造成的消耗。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;提高响应速度。当任务到达时，任务可以不需要的等到线程创建就能立即执行。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;提高线程的可管理性。线程是稀缺资源，如果无限制的创建，不仅会消耗系统资源，还会降低系统的稳定性，使用线程池可以进行统一的分配，调优和监控。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;2. Executor 框架&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.1 Executor 简介&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;Executor 框架是Java5之后引进的，在Java 5之后，通过 Executor 来启动线程比使用 Thread 的 start 方法更好，除了更易管理，效率更好（用线程池实现，节约开销）外，还有关键的一点：有助于避免 this 逃逸问题。&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;this逃逸是指在构造函数返回之前其他线程就持有该对象的引用. 调用尚未构造完全的对象的方法可能引发令人疑惑的错误。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.2 Executor 框架结构(主要由三大部分组成)&lt;/h4&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;1 任务&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;执行任务需要实现的Runnable接口或Callable接口。Runnable接口或Callable接口实现类都可以被ThreadPoolExecutor或ScheduledThreadPoolExecutor执行。&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0;&quot;&gt;两者的区别：&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;Runnable接口不会返回结果,但是Callable接口可以返回结果。后面介绍Executors类的一些方法的时候会介绍到两者的相互转换。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;2 任务的执行&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/9842f2cd-109b-4af6-af9e-ea3f706f0e88.jpg&quot; /&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;包括任务执行机制的核心接口Executor ，以及继承自Executor 接口的ExecutorService接口。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;ScheduledThreadPoolExecutor和ThreadPoolExecutor这两个关键类实现了ExecutorService接口。&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;3 异步计算的结果&lt;/h5&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;Future接口以及Future接口的实现类FutureTask类。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;当我们把Runnable接口或Callable接口的实现类提交（调用submit方法）给ThreadPoolExecutor或ScheduledThreadPoolExecutor时，会返回一个FutureTask对象。&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.3 Executor 框架的使用示意图&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/bd80c263-6e11-4ff1-8845-e9016e7905e3.jpg&quot; /&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;主线程首先要&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;创建实现Runnable或者Callable接口的任务对象&lt;/strong&gt;。&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;备注： 工具类Executors可以实现Runnable对象和Callable对象之间的相互转换。（Executors.callable（Runnable task）或Executors.callable（Runnable task，Object resule））&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;然后可以把创建完成的&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;Runnable对象直接交给ExecutorService执行&lt;/strong&gt;（ExecutorService.execute（Runnable command））；或者也可以把Runnable对象或Callable对象提交给ExecutorService执行（ExecutorService.submit（Runnable task）或ExecutorService.submit（Callable task））&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;执行execute()方法和submit()方法的区别是什么呢？&lt;br/&gt;
1)execute()方法用于提交不需要返回值的任务，所以无法判断任务是否被线程池执行成功与否；&lt;br/&gt;
2)submit()方法用于提交需要返回值的任务。线程池会返回一个future类型的对象，通过这个future对象可以判断任务是否执行成功，并且可以通过future的get()方法来获取返回值，get()方法会阻塞当前线程直到任务完成，而使用get（long timeout，TimeUnit unit）方法则会阻塞当前线程一段时间后立即返回，这时候有可能任务没有执行完&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;如果&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;执行ExecutorService.submit&lt;/strong&gt;（…），ExecutorService将&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;返回一个实现Future接口的对象&lt;/strong&gt;（我们刚刚也提到过了执行execute()方法和submit()方法的区别，到目前为止的JDK中，返回的是FutureTask对象）。由于FutureTask实现了Runnable，程序员也可以创建FutureTask，然后直接交给ExecutorService执行。&lt;/p&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;最后，主线程可以&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;执行FutureTask.get()方法来等待任务执行完成&lt;/strong&gt;。主线程也可以执行FutureTask.cancel（boolean mayInterruptIfRunning）来取消此任务的执行。&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;3. ThreadPoolExecutor详解&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;线程池实现类ThreadPoolExecutor是Executor 框架最核心的类&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.1 ThreadPoolExecutor类的四个比较重要的属性&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/0b0da91f-259e-4770-a179-e8598b489ffc.jpg&quot; /&gt;&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.2 ThreadPoolExecutor类中提供的四个构造方法&lt;/h4&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt; &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;/**
     * 用给定的初始参数创建一个新的ThreadPoolExecutor。
     
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@param&lt;/span&gt; corePoolSize 核心线程池大小
     
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@param&lt;/span&gt; maximumPoolSize 最大线程池的大小
     
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@param&lt;/span&gt; keepAliveTime 当线程池中的线程数量大于corePoolSize的时候，如果这时没有新的任务提交，
     *核心线程外的线程不会立即销毁，而是会等待，直到等待的时间超过了keepAliveTime；
     
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@param&lt;/span&gt; unit  keepAliveTime参数的时间单位
     
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@param&lt;/span&gt; workQueue 等待队列，当任务提交时，如果线程池中的线程数量大于等于corePoolSize的时候，把该任务封装成一个Worker对象放入等待队列；
     * 
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@param&lt;/span&gt; threadFactory 执行者创建新线程时使用的工厂
     
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@param&lt;/span&gt; handler RejectedExecutionHandler类型的变量，表示线程池的饱和策略。
     * 如果阻塞队列满了并且没有空闲的线程，这时如果继续提交任务，就需要采取一种策略处理该任务。
     * 线程池提供了4种策略：
        1.AbortPolicy：直接抛出异常，这是默认策略；
        2.CallerRunsPolicy：用调用者所在的线程来执行任务；
        3.DiscardOldestPolicy：丢弃阻塞队列中靠最前的任务，并执行当前任务；
        4.DiscardPolicy：直接丢弃任务；
     */&lt;/span&gt;
    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;ThreadPoolExecutor&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; corePoolSize,
                              &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; maximumPoolSize,
                              &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;long&lt;/span&gt; keepAliveTime,
                              TimeUnit unit,
                              BlockingQueue&lt;Runnable&gt; workQueue,
                              ThreadFactory threadFactory,
                              RejectedExecutionHandler handler)&lt;/span&gt; &lt;/span&gt;{
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;if&lt;/span&gt; (corePoolSize &lt; &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0&lt;/span&gt; ||
            maximumPoolSize &lt;= &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0&lt;/span&gt; ||
            maximumPoolSize &lt; corePoolSize ||
            keepAliveTime &lt; &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0&lt;/span&gt;)
            &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;throw&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; IllegalArgumentException();
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;if&lt;/span&gt; (workQueue == &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;null&lt;/span&gt; || threadFactory == &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;null&lt;/span&gt; || handler == &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;null&lt;/span&gt;)
            &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;throw&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; NullPointerException();
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;this&lt;/span&gt;.corePoolSize = corePoolSize;
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;this&lt;/span&gt;.maximumPoolSize = maximumPoolSize;
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;this&lt;/span&gt;.workQueue = workQueue;
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;this&lt;/span&gt;.keepAliveTime = unit.toNanos(keepAliveTime);
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;this&lt;/span&gt;.threadFactory = threadFactory;
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;this&lt;/span&gt;.handler = handler;
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.3 如何创建ThreadPoolExecutor&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;在《阿里巴巴Java开发手册》&quot;并发处理&quot;这一章节，明确指出线程资源必须通过线程池提供，不允许在应用中自行显示创建线程。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;为什么呢？&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;使用线程池的好处是减少在创建和销毁线程上所消耗的时间以及系统资源开销，解决资源不足的问题。如果不使用线程池，有可能会造成系统创建大量同类线程而导致消耗完内存或者&quot;过度切换&quot;的问题。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;另外《阿里巴巴Java开发手册》中&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;强制线程池不允许使用 Executors 去创建，而是通过 ThreadPoolExecutor 的方式&lt;/strong&gt;，这样的处理方式让写的同学更加明确线程池的运行规则，规避资源耗尽的风险&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;Executors 返回线程池对象的弊端如下：&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;FixedThreadPool 和 SingleThreadExecutor ： 允许请求的队列长度为 Integer.MAX_VALUE,可能堆积大量的请求，从而导致OOM。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;CachedThreadPool 和 ScheduledThreadPool ： 允许创建的线程数量为 Integer.MAX_VALUE ，可能会创建大量线程，从而导致OOM。&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;方式一：通过构造方法实现&lt;/strong&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;方式二：通过Executor 框架的工具类Executors来实现&lt;/strong&gt;&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;我们可以创建三种类型的ThreadPoolExecutor：
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; color: #333; margin-top: 0; margin-bottom: 0; margin: 0;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;FixedThreadPool&lt;/strong&gt;&lt;br/&gt;
&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;SingleThreadExecutor&lt;/strong&gt;&lt;br/&gt;
&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;CachedThreadPool&lt;/strong&gt;&lt;br/&gt;
底层都是调用的ThreadPoolExecutor的构造方法&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.4 FixedThreadPool详解&lt;/h4&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;FixedThreadPool被称为可重用固定线程数的线程池。&lt;/h5&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt; &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;/**
     * 创建一个可重用固定数量线程的线程池
	 *在任何时候至多有n个线程处于活动状态
	 *如果在所有线程处于活动状态时提交其他任务，则它们将在队列中等待，
	 *直到线程可用。 如果任何线程在关闭之前的执行期间由于失败而终止，
	 *如果需要执行后续任务，则一个新的线程将取代它。池中的线程将一直存在
	 *知道调用shutdown方法
     
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@param&lt;/span&gt; nThreads 线程池中的线程数
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@param&lt;/span&gt; threadFactory 创建新线程时使用的factory
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@return&lt;/span&gt; 新创建的线程池
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@throws&lt;/span&gt; NullPointerException 如果threadFactory为null
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@throws&lt;/span&gt; IllegalArgumentException if {&lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@code&lt;/span&gt; nThreads &lt;= 0}
     */&lt;/span&gt;
    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;static&lt;/span&gt; ExecutorService &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;newFixedThreadPool&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; nThreads, ThreadFactory threadFactory)&lt;/span&gt; &lt;/span&gt;{
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; ThreadPoolExecutor(nThreads, nThreads,
                                      &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0L&lt;/span&gt;, TimeUnit.MILLISECONDS,
                                      &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; LinkedBlockingQueue&lt;Runnable&gt;(),
                                      threadFactory);
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;static&lt;/span&gt; ExecutorService &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;newFixedThreadPool&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; nThreads)&lt;/span&gt; &lt;/span&gt;{
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; ThreadPoolExecutor(nThreads, nThreads,
                                      &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0L&lt;/span&gt;, TimeUnit.MILLISECONDS,
                                      &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; LinkedBlockingQueue&lt;Runnable&gt;());
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;新创建的FixedThreadPool的corePoolSize和maximumPoolSize都被设置为nThreads。&lt;/strong&gt;&lt;/p&gt;
&lt;hr style=&quot;line-height: 160%; box-sizing: content-box; border-top: 1px solid #eee; margin: 16px 0;&quot;/&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;FixedThreadPool的execute()方法运行示意图&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/35a191dc-67f0-4c67-b824-699c247c1c6f.jpg&quot; /&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;上图说明：&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;如果当前运行的线程数小于corePoolSize，则创建新的线程来执行任务；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;当前运行的线程数等于corePoolSize后，将任务加入LinkedBlockingQueue；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;线程执行完1中的任务后，会在循环中反复从LinkedBlockingQueue中获取任务来执行；&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;FixedThreadPool使用无界队列 LinkedBlockingQueue（队列的容量为Intger.MAX_VALUE）作为线程池的工作队列会对线程池带来如下影响：&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;当线程池中的线程数达到corePoolSize后，新任务将在无界队列中等待，因此线程池中的线程数不会超过corePoolSize；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;由于1，使用无界队列时maximumPoolSize将是一个无效参数；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;由于1和2，使用无界队列时keepAliveTime将是一个无效参数；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;运行中的FixedThreadPool（未执行shutdown()或shutdownNow()方法）不会拒绝任务&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.5 SingleThreadExecutor详解&lt;/h4&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;SingleThreadExecutor是使用单个worker线程的Executor。&lt;/h5&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;/**
     *创建使用单个worker线程运行无界队列的Executor
	 *并使用提供的ThreadFactory在需要时创建新线程
     *
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@param&lt;/span&gt; threadFactory 创建新线程时使用的factory
     *
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@return&lt;/span&gt; 新创建的单线程Executor
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@throws&lt;/span&gt; NullPointerException 如果ThreadFactory为空
     */&lt;/span&gt;
    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;static&lt;/span&gt; ExecutorService &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;newSingleThreadExecutor&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(ThreadFactory threadFactory)&lt;/span&gt; &lt;/span&gt;{
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; FinalizableDelegatedExecutorService
            (&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; ThreadPoolExecutor(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1&lt;/span&gt;,
                                    &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0L&lt;/span&gt;, TimeUnit.MILLISECONDS,
                                    &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; LinkedBlockingQueue&lt;Runnable&gt;(),
                                    threadFactory));
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;static&lt;/span&gt; ExecutorService &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;newSingleThreadExecutor&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; FinalizableDelegatedExecutorService
            (&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; ThreadPoolExecutor(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1&lt;/span&gt;,
                                    &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0L&lt;/span&gt;, TimeUnit.MILLISECONDS,
                                    &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; LinkedBlockingQueue&lt;Runnable&gt;()));
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;新创建的SingleThreadExecutor的corePoolSize和maximumPoolSize都被设置为1.&lt;br/&gt;
其他参数和FixedThreadPool相同。SingleThreadExecutor使用无界队列LinkedBlockingQueue作为线程池的工作队列（队列的容量为Intger.MAX_VALUE）&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;SingleThreadExecutor使用无界队列作为线程池的工作队列会对线程池带来的影响与FixedThreadPool相同。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;SingleThreadExecutor的运行示意图&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/4876c176-bb08-445c-ba2b-449e11ef37a8.jpg&quot; /&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;上图说明:&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;如果当前运行的线程数少于corePoolSize，则创建一个新的线程执行任务；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;当前线程池中有一个运行的线程后，将任务加入LinkedBlockingQueue&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;线程执行完1中的任务后，会在循环中反复从LinkedBlockingQueue中获取任务来执行；&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.6 CachedThreadPool详解&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;CachedThreadPool是一个会根据需要创建新线程的线程池。&lt;/p&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;/**
     * 创建一个线程池，根据需要创建新线程，但会在先前构建的线程可用时重用它，
	 *并在需要时使用提供的ThreadFactory创建新线程。
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@param&lt;/span&gt; threadFactory 创建新线程使用的factory
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@return&lt;/span&gt; 新创建的线程池
     * &lt;span style=&quot;color: #608b4e; line-height: 160%; box-sizing: content-box;&quot;&gt;@throws&lt;/span&gt; NullPointerException 如果threadFactory为空
     */&lt;/span&gt;
    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;static&lt;/span&gt; ExecutorService &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;newCachedThreadPool&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(ThreadFactory threadFactory)&lt;/span&gt; &lt;/span&gt;{
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; ThreadPoolExecutor(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0&lt;/span&gt;, Integer.MAX_VALUE,
                                      &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;60L&lt;/span&gt;, TimeUnit.SECONDS,
                                      &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; SynchronousQueue&lt;Runnable&gt;(),
                                      threadFactory);
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;static&lt;/span&gt; ExecutorService &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;newCachedThreadPool&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; ThreadPoolExecutor(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0&lt;/span&gt;, Integer.MAX_VALUE,
                                      &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;60L&lt;/span&gt;, TimeUnit.SECONDS,
                                      &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; SynchronousQueue&lt;Runnable&gt;());
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;CachedThreadPool的corePoolSize被设置为空（0），maximumPoolSize被设置为Integer.MAX.VALUE，即它是无界的，这也就意味着如果主线程提交任务的速度高于maximumPool中线程处理任务的速度时，CachedThreadPool会不断创建新的线程&lt;/strong&gt;&lt;br/&gt;
极端情况下，这样会导致耗尽cpu和内存资源。&lt;/p&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;CachedThreadPool的execute()方法的执行示意图&lt;/h5&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/ea5fa959-786e-4c25-a604-ec226a27e230.jpg&quot; /&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;上图说明：&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;首先执行SynchronousQueue.offer(Runnable task)。如果当前maximumPool中有闲线程正在执行SynchronousQueue.poll(keepAliveTime,TimeUnit.NANOSECONDS)，那么主线程执行offer操作与空闲线程执行的poll操作配对成功，主线程把任务交给空闲线程执行，execute()方法执行完成，否则执行下面的步骤2；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;当初始maximumPool为空，或者maximumPool中没有空闲线程时，将没有线程执行SynchronousQueue.poll(keepAliveTime,TimeUnit.NANOSECONDS)。这种情况下，步骤1将失败，此时CachedThreadPool会创建新线程执行任务，execute方法执行完成；&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.7 ThreadPoolExecutor使用示例&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;首先创建一个Runnable接口的实现类WorkerThread&lt;/p&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;ThreadPoolExecutorDemo&lt;/span&gt; &lt;/span&gt;{

   &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;main&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(String[] args)&lt;/span&gt; &lt;/span&gt;{
       &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//创建一个FixedThreadPool对象&lt;/span&gt;
       ExecutorService executor = Executors.newFixedThreadPool(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;5&lt;/span&gt;);
       &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; i = &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0&lt;/span&gt;; i &lt; &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;10&lt;/span&gt;; i++) {
           &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//创建WorkerThread对象（WorkerThread类实现了Runnable 接口）&lt;/span&gt;
           Runnable worker = &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; WorkerThread(&lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;&quot;&lt;/span&gt; + i);
           &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//执行Runnable&lt;/span&gt;
           executor.execute(worker);
       }
       &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//终止线程池&lt;/span&gt;
       executor.shutdown();
       &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;while&lt;/span&gt; (!executor.isTerminated()) {
       }
       System.out.println(&lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;Finished all threads&quot;&lt;/span&gt;);
   }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;hr style=&quot;line-height: 160%; box-sizing: content-box; border-top: 1px solid #eee; margin: 16px 0;&quot;/&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;shutdown（）VS shutdownNow（）&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;shutdown（）方法表明关闭已在Executor上调用，因此不会再向DelayedPool添加任何其他任务（由ScheduledThreadPoolExecutor类在内部使用）, 但是，已经在队列中提交的任务将被允许完成。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;shutdownNow（）方法试图终止当前正在运行的任务，并停止处理排队的任务并返回正在等待执行的List。&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;isTerminated() Vs isShutdown()&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;isShutDown当调用shutdown()方法后返回为true。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;isTerminated当调用shutdown()方法后，并且所有提交的任务完成后返回为true&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;4. ScheduledThreadPoolExecutor详解&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;4.1 ScheduledThreadPoolExecutor简介&lt;/h4&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;ScheduledThreadPoolExecutor主要用来在给定的&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;延迟后运行任务&lt;/strong&gt;，或者&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;定期执行&lt;/strong&gt;任务。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;ScheduledThreadPoolExecutor使用的&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;任务队列DelayQueue封装了一个PriorityQueue&lt;/strong&gt;，PriorityQueue会对队列中的任务进行排序，执行所需时间短的放在前面先被执行(ScheduledFutureTask的time变量小的先执行)，如果执行所需时间相同则先提交的任务将被先执行(ScheduledFutureTask的squenceNumber变量小的先执行)。&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;4.2 ScheduledThreadPoolExecutor运行机制&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/d5242572-6958-4e78-a1e6-536026680d7f.jpg&quot; /&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;ScheduledThreadPoolExecutor的执行主要分为两大部分：&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;当调用ScheduledThreadPoolExecutor的 scheduleAtFixedRate() 方法或者scheduleWirhFixedDelay() 方法时，会向ScheduledThreadPoolExecutor的 DelayQueue 添加一个实现了 RunnableScheduledFutur 接口的 ScheduledFutureTask 。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;线程池中的线程从DelayQueue中获取ScheduledFutureTask，然后执行任务。&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;ScheduledThreadPoolExecutor为了实现周期性的执行任务，对ThreadPoolExecutor做了如下修改：&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;使用 DelayQueue 作为任务队列；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;获取任务的方不同&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;执行周期任务后，增加了额外的处理&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;4.3 ScheduledThreadPoolExecutor执行周期任务的步骤&lt;/h4&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/f408d157-54c7-4689-8dd3-0860daea27d4.jpg&quot; /&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;线程1从DelayQueue中获取已到期的ScheduledFutureTask（DelayQueue.take()）。到期任务是指ScheduledFutureTask的time大于等于当前系统的时间；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;线程1执行这个ScheduledFutureTask；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;线程1修改ScheduledFutureTask的time变量为下次将要被执行的时间；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;线程1把这个修改time之后的ScheduledFutureTask放回DelayQueue中（DelayQueue.add())。&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;4.4 ScheduledThreadPoolExecutor使用示例&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;创建一个简单的实现Runnable接口的类&lt;br/&gt;
测试程序使用ScheduledExecutorService和Executors.newScheduledThreadPool实现的java调度&lt;/p&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.4.1 ScheduledExecutorService scheduleAtFixedRate(Runnable command,long initialDelay,long period,TimeUnit unit)方法&lt;/h5&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//可以使用ScheduledExecutorService scheduleAtFixedRate方法来安排任务在初始延迟后运行，然后在给定的时间段内运行。&lt;/span&gt;

scheduledThreadPool.scheduleAtFixedRate(worker, &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;10&lt;/span&gt;, TimeUnit.SECONDS);
&lt;/code&gt;&lt;/pre&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.4.2 ScheduledExecutorService scheduleWithFixedDelay(Runnable command,long initialDelay,long delay,TimeUnit unit)方法&lt;/h5&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//ScheduledExecutorService scheduleWithFixedDelay方法可用于以初始延迟启动周期性执行，然后以给定延迟执行。 延迟时间是线程完成执行的时间。&lt;/span&gt;

scheduledThreadPool.scheduleWithFixedDelay(worker, &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1&lt;/span&gt;, TimeUnit.SECONDS);
&lt;/code&gt;&lt;/pre&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.4.3 scheduleWithFixedDelay() vs scheduleAtFixedRate()&lt;/h5&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;scheduleAtFixedRate&lt;/strong&gt;（…）将延迟视为两个任务&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;开始之间的差异&lt;/strong&gt;（即定期调用）&lt;br/&gt;
不管是否执行完&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;scheduleWithFixedDelay&lt;/strong&gt;（…）将延迟视为&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;一个任务结束与下一个任务开始&lt;/strong&gt;之间的差异，执行完才开始下一个。&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;scheduleAtFixedRate()&lt;/strong&gt;: 在给定的初始延迟之后创建并执行，随后以给定的时间段首先启用的周期性动作; 那就是执行将在initialDelay之后开始，然后initialDelay+period ，然后是initialDelay + 2 * period ，等等。 如果任务的执行遇到异常，则后续的执行被抑制。 否则，任务将仅通过取消或终止执行人终止。 如果任务执行时间比其周期长，则后续执行可能会迟到，但不会同时执行。&lt;br/&gt;
&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;scheduleWithFixedDelay()&lt;/strong&gt; : 在给定的初始延迟之后创建并执行，首先启用的定期动作，随后在一个执行的终止和下一个执行的开始之间给定的延迟。 如果任务的执行遇到异常，则后续的执行被抑制。 否则，任务将仅通过取消或终止执行终止。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;5. 各种线程池的适用场景介绍&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;FixedThreadPool&lt;/strong&gt;： 适用于为了满足资源管理需求，而需要限制当前线程数量的应用场景。它适用于负载比较重的服务器；&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;SingleThreadExecutor&lt;/strong&gt;： 适用于需要保证顺序地执行各个任务并且在任意时间点，不会有多个线程是活动的应用场景。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;CachedThreadPool&lt;/strong&gt;： 适用于执行很多的短期异步任务的小程序，或者是负载较轻的服务器；&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;ScheduledThreadPoolExecutor&lt;/strong&gt;： 适用于需要多个后台执行周期任务，同时为了满足资源管理需求而需要限制后台线程的数量的应用场景，&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;SingleThreadScheduledExecutor&lt;/strong&gt;： 适用于需要单个后台线程执行周期任务，同时保证顺序地执行各个任务的应用场景。&lt;/p&gt;
&lt;/div&gt;&lt;center style='display:none !important;visibility:collapse !important;height:0 !important;white-space:nowrap;width:100%;overflow:hidden'&gt;%5Btoc%5D%0A%23%23%20%E4%B8%80.%E7%BA%BF%E7%A8%8B%E5%85%A5%E9%97%A8%0A%23%23%23%201.%20%E8%BF%9B%E7%A8%8B%E5%92%8C%E5%A4%9A%E7%BA%BF%E7%A8%8B%E7%AE%80%E4%BB%8B%0A%23%23%23%23%201.1%20%E4%BD%95%E4%B8%BA%E8%BF%9B%E7%A8%8B%EF%BC%9F%0A%3E*%20%E8%BF%9B%E7%A8%8B%E6%98%AF%E7%A8%8B%E5%BA%8F%E7%9A%84%E4%B8%80%E6%AC%A1%E6%89%A7%E8%A1%8C%E8%B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%E7%BA%BF%E7%A8%8B%E5%9B%A0%E4%B8%BA%E6%9F%90%E7%A7%8D%E5%8E%9F%E5%9B%A0%E6%94%BE%E5%BC%83%E4%BA%86cpu%E4%BD%BF%E7%94%A8%E6%9D%83%EF%BC%8C%E4%B9%9F%E5%8D%B3%E8%AE%A9%E5%87%BA%E4%BA%86cpu%20timeslice%EF%BC%88%E6%97%B6%E9%97%B4%E7%89%87%EF%BC%89%EF%BC%8C%E6%9A%82%E6%97%B6%E5%81%9C%E6%AD%A2%E8%BF%90%E8%A1%8C%E3%80%82%E7%9B%B4%E5%88%B0%E7%BA%BF%E7%A8%8B%E8%BF%9B%E5%85%A5%E5%8F%AF%E8%BF%90%E8%A1%8C(runnable)%E7%8A%B6%E6%80%81%EF%BC%8C%E6%89%8D%E6%9C%89%20%E6%9C%BA%E4%BC%9A%E5%86%8D%E6%AC%A1%E8%8E%B7%E5%BE%97cpu%20timeslice%E8%BD%AC%E5%88%B0%E8%BF%90%E8%A1%8C(running)%E7%8A%B6%E6%80%81%E3%80%82%E9%98%BB%E5%A1%9E%E7%9A%84%E6%83%85%E5%86%B5%E5%88%86%E4%B8%89%E7%A7%8D%EF%BC%9A%0A%3E*%20(%E4%B8%80).%20%E7%AD%89%E5%BE%85%E9%98%BB%E5%A1%9E%EF%BC%9A%E8%BF%90%E8%A1%8C(running)%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%89%A7%E8%A1%8Co.wait()%E6%96%B9%E6%B3%95%EF%BC%8CJVM%E4%BC%9A%E6%8A%8A%E8%AF%A5%E7%BA%BF%E7%A8%8B%E6%94%BE%20%E5%85%A5%E7%AD%89%E5%BE%85%E9%98%9F%E5%88%97(waiting%20queue)%E4%B8%AD%E3%80%82%0A%3E*%20(%E4%BA%8C).%20%E5%90%8C%E6%AD%A5%E9%98%BB%E5%A1%9E%EF%BC%9A%E8%BF%90%E8%A1%8C(running)%E7%9A%84%E7%BA%BF%E7%A8%8B%E5%9C%A8%E8%8E%B7%E5%8F%96%E5%AF%B9%E8%B1%A1%E7%9A%84%E5%90%8C%E6%AD%A5%E9%94%81%E6%97%B6%EF%BC%8C%E8%8B%A5%E8%AF%A5%E5%90%8C%E6%AD%A5%20%E9%94%81%20%E8%A2%AB%E5%88%AB%E7%9A%84%E7%BA%BF%E7%A8%8B%E5%8D%A0%E7%94%A8%EF%BC%8C%E5%88%99JVM%E4%BC%9A%E6%8A%8A%E8%AF%A5%E7%BA%BF%E7%A8%8B%E6%94%BE%E5%85%A5%E9%94%81%E6%B1%A0(lock%20pool)%E4%B8%AD%E3%80%82%0A%3E*%20(%E4%B8%89).%20%E5%85%B6%E4%BB%96%E9%98%BB%E5%A1%9E%3A%20%E8%BF%90%E8%A1%8C(running)%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%89%A7%E8%A1%8CThread.sleep(long%20ms)%E6%88%96t.join()%E6%96%B9%E6%B3%95%EF%BC%8C%E6%88%96%E8%80%85%E5%8F%91%E5%87%BA%E4%BA%86I%2FO%E8%AF%B7%E6%B1%82%E6%97%B6%EF%BC%8CJVM%E4%BC%9A%E6%8A%8A%E8%AF%A5%E7%BA%BF%E7%A8%8B%E7%BD%AE%E4%B8%BA%E9%98%BB%E5%A1%9E%E7%8A%B6%E6%80%81%E3%80%82%E5%BD%93sleep()%E7%8A%B6%E6%80%81%E8%B6%85%E6%97%B6join()%E7%AD%89%E5%BE%85%E7%BA%BF%E7%A8%8B%E7%BB%88%E6%AD%A2%E6%88%96%E8%80%85%E8%B6%85%E6%97%B6%E3%80%81%E6%88%96%E8%80%85I%2FO%E5%A4%84%E7%90%86%E5%AE%8C%E6%AF%95%E6%97%B6%EF%BC%8C%E7%BA%BF%E7%A8%8B%E9%87%8D%E6%96%B0%E8%BD%AC%E5%85%A5%E5%8F%AF%E8%BF%90%E8%A1%8C(runnable)%E7%8A%B6%E6%80%81%E3%80%82%0A5.%20%E6%AD%BB%E4%BA%A1(dead)%EF%BC%9A%E7%BA%BF%E7%A8%8Brun()%E3%80%81main()%E6%96%B9%E6%B3%95%E6%89%A7%E8%A1%8C%E7%BB%93%E6%9D%9F%EF%BC%8C%E6%88%96%E8%80%85%E5%9B%A0%E5%BC%82%E5%B8%B8%E9%80%80%E5%87%BA%E4%BA%86run()%E6%96%B9%E6%B3%95%EF%BC%8C%E5%88%99%E8%AF%A5%E7%BA%BF%E7%A8%8B%E7%BB%93%E6%9D%9F%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E3%80%82%E6%AD%BB%E4%BA%A1%E7%9A%84%E7%BA%BF%E7%A8%8B%E4%B8%8D%E5%8F%AF%E5%86%8D%E6%AC%A1%E5%A4%8D%E7%94%9F%E3%80%82%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/5e6a3bd7-9486-476c-a872-b01559edfd3e.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F614%3A1)%0A%0A%23%23%23%23%201.5%20%E7%BA%BF%E7%A8%8B%E7%9A%84%E4%BC%98%E5%85%88%E7%BA%A7%0A%3E%E6%AF%8F%E4%B8%AA%E7%BA%BF%E7%A8%8B%E9%83%BD%E5%85%B7%E6%9C%89%E5%90%84%E8%87%AA%E7%9A%84%E4%BC%98%E5%85%88%E7%BA%A7%EF%BC%8C%E7%BA%BF%E7%A8%8B%E7%9A%84%E4%BC%98%E5%85%88%E7%BA%A7%E5%8F%AF%E4%BB%A5%E5%9C%A8%E7%A8%8B%E5%BA%8F%E4%B8%AD%E8%A1%A8%E6%98%8E%E8%AF%A5%E7%BA%BF%E7%A8%8B%E7%9A%84%E9%87%8D%E8%A6%81%E6%80%A7%EF%BC%8C%E5%A6%82%E6%9E%9C%E6%9C%89%E5%BE%88%E5%A4%9A%E7%BA%BF%E7%A8%8B%E5%A4%84%E4%BA%8E%E5%B0%B1%E7%BB%AA%E7%8A%B6%E6%80%81%EF%BC%8C%E7%B3%BB%E7%BB%9F%E4%BC%9A%E6%A0%B9%E6%8D%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EF%BC%89%2C%0AThread.MAX_PRIORITY%EF%BC%88%E5%B8%B8%E6%95%B010%EF%BC%89%E3%80%82%0A*%20%E5%85%B6%E4%B8%AD%E6%AF%8F%E4%B8%AA%E7%BA%BF%E7%A8%8B%E7%9A%84%E4%BC%98%E5%85%88%E7%BA%A7%E9%83%BD%E5%9C%A8Thread.MIN_PRIORITY%EF%BC%88%E5%B8%B8%E6%95%B01%EF%BC%89%20%E5%88%B0Thread.MAX_PRIORITY%EF%BC%88%E5%B8%B8%E6%95%B010%EF%BC%89%20%E4%B9%8B%E9%97%B4%E3%80%82%0A*%20%E5%9C%A8%E9%BB%98%E8%AE%A4%E6%83%85%E5%86%B5%E4%B8%8B%E4%BC%98%E5%85%88%E7%BA%A7%E9%83%BD%E6%98%AFThread.NORM_PRIORITY%EF%BC%88%E5%B8%B8%E6%95%B05%EF%BC%89%E3%80%82%0A%0A%23%23%23%23%201.6%20%E4%BD%95%E4%B8%BA%E5%A4%9A%E7%BA%BF%E7%A8%8B%EF%BC%9F%0A%3E%E5%A4%9A%E7%BA%BF%E7%A8%8B%E5%B0%B1%E6%98%AF%E5%A4%9A%E4%B8%AA%E7%BA%BF%E7%A8%8B%E5%90%8C%E6%97%B6%E8%BF%90%E8%A1%8C%E6%88%96%E4%BA%A4%E6%9B%BF%E8%BF%90%E8%A1%8C%E3%80%82%E5%8D%95%E6%A0%B8CPU%E7%9A%84%E8%AF%9D%E6%98%AF%E9%A1%BA%E5%BA%8F%E6%89%A7%E8%A1%8C%EF%BC%8C%E4%B9%9F%E5%B0%B1%E6%98%AF%E4%BA%A4%E6%9B%BF%E8%BF%90%E8%A1%8C%E3%80%82%E5%A4%9A%E6%A0%B8CPU%E7%9A%84%E8%AF%9D%EF%BC%8C%E5%9B%A0%E4%B8%BA%E6%AF%8F%E4%B8%AACPU%E6%9C%89%E8%87%AA%E5%B7%B1%E7%9A%84%E8%BF%90%E7%AE%97%E5%99%A8%EF%BC%8C%E6%89%80%E4%BB%A5%E5%9C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E4%BA%9B%E6%8C%87%E6%A0%87%E6%9C%89%E5%93%8D%E5%BA%94%E6%97%B6%E9%97%B4%EF%BC%88Response%20Time%EF%BC%89%EF%BC%8C%E5%90%9E%E5%90%90%E9%87%8F%EF%BC%88Throughput%EF%BC%89%EF%BC%8C%E6%AF%8F%E7%A7%92%E6%9F%A5%E8%AF%A2%E7%8E%87QPS%EF%BC%88Query%20Per%20Second%EF%BC%89%EF%BC%8C%E5%B9%B6%E5%8F%91%E7%94%A8%E6%88%B7%E6%95%B0%E7%AD%89%E3%80%82%0A%0A%23%23%23%23%202.4%20%E4%B8%B4%E7%95%8C%E5%8C%BA%0A%E4%B8%B4%E7%95%8C%E5%8C%BA%E7%94%A8%E6%9D%A5%E8%A1%A8%E7%A4%BA%E4%B8%80%E7%A7%8D%E5%85%AC%E5%85%B1%E8%B5%84%E6%BA%90%E6%88%96%E8%80%85%E8%AF%B4%E6%98%AF**%E5%85%B1%E4%BA%AB%E6%95%B0%E6%8D%AE**%EF%BC%8C%E5%8F%AF%E4%BB%A5**%E8%A2%AB%E5%A4%9A%E4%B8%AA%E7%BA%BF%E7%A8%8B%E4%BD%BF%E7%94%A8**%E3%80%82%0A%E4%BD%86%E6%98%AF%E6%AF%8F%E4%B8%80%E6%AC%A1%EF%BC%8C%E5%8F%AA%E8%83%BD%E6%9C%89%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%E4%BD%BF%E7%94%A8%E5%AE%83%EF%BC%8C%E4%B8%80%E6%97%A6%E4%B8%B4%E7%95%8C%E5%8C%BA%E8%B5%84%E6%BA%90%E8%A2%AB%E5%8D%A0%E7%94%A8%EF%BC%8C%E5%85%B6%E4%BB%96%E7%BA%BF%E7%A8%8B%E8%A6%81%E6%83%B3%E4%BD%BF%E7%94%A8%E8%BF%99%E4%B8%AA%E8%B5%84%E6%BA%90%EF%BC%8C%E5%B0%B1%E5%BF%85%E9%A1%BB**%E7%AD%89%E5%BE%85**%E3%80%82%E5%9C%A8%E5%B9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5%E6%B1%A0%E4%B8%AD%E7%9A%84%E6%A3%80%E6%B5%8B%E7%BA%BF%E7%A8%8B%EF%BC%8CJVM%E8%99%9A%E6%8B%9F%E6%9C%BA%E5%90%AF%E5%8A%A8%E5%90%8E%E7%9A%84%E6%A3%80%E6%B5%8B%E7%BA%BF%E7%A8%8B%0A%E6%9C%80%E5%B8%B8%E8%A7%81%E7%9A%84%E5%AE%88%E6%8A%A4%E7%BA%BF%E7%A8%8B%EF%BC%9A%E5%9E%83%E5%9C%BE%E5%9B%9E%E6%94%B6%E7%BA%BF%E7%A8%8B%0A%0A%23%23%23%23%203.3%20%E5%A6%82%E4%BD%95%E8%AE%BE%E7%BD%AE%E5%AE%88%E6%8A%A4%E7%BA%BF%E7%A8%8B%EF%BC%9F%0A%3E*%20%E9%80%9A%E8%BF%87%E8%B0%83%E7%94%A8Thead%E7%B1%BB%E7%9A%84setDaemon(true)%E6%96%B9%E6%B3%95%E8%AE%BE%E7%BD%AE%E5%BD%93%E5%89%8D%E7%9A%84%E7%BA%BF%E7%A8%8B%E4%B8%BA%E5%AE%88%E6%8A%A4%E7%BA%BF%E7%A8%8B%0A%60%60%60%0A1.%20setDaemon(true)%E5%BF%85%E9%A1%BB%E5%9C%A8start()%E6%96%B9%E6%B3%95%E5%89%8D%E6%89%A7%E8%A1%8C%EF%BC%8C%E5%90%A6%E5%88%99%E4%BC%9A%E6%8A%9B%E5%87%BAIllegalThreadStateException%E5%BC%82%E5%B8%B8%20%0A2.%20%20%E5%9C%A8%E5%AE%88%E6%8A%A4%E7%BA%BF%E7%A8%8B%E4%B8%AD%E4%BA%A7%E7%94%9F%E7%9A%84%E6%96%B0%E7%BA%BF%E7%A8%8B%E4%B9%9F%E6%98%AF%E5%AE%88%E6%8A%A4%E7%BA%BF%E7%A8%8B%20%0A3.%20%20%E4%B8%8D%E6%98%AF%E6%89%80%E6%9C%89%E7%9A%84%E4%BB%BB%E5%8A%A1%E9%83%BD%E5%8F%AF%E4%BB%A5%E5%88%86%E9%85%8D%E7%BB%99%E5%AE%88%E6%8A%A4%E7%BA%BF%E7%A8%8B%E6%9D%A5%E6%89%A7%E8%A1%8C%EF%BC%8C%E6%AF%94%E5%A6%82%E8%AF%BB%E5%86%99%E6%93%8D%E4%BD%9C%E6%88%96%E8%80%85%E8%AE%A1%E7%AE%97%E9%80%BB%E8%BE%91%0A%60%60%60%0A%0A%23%23%23%23%204.%20%E4%B8%80%E4%BA%9B%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%95%0A%23%23%23%23%23%204.1%20currentThread()%0A%3E%20%E8%BF%94%E5%9B%9E%E5%AF%B9%E5%BD%93%E5%89%8D%E6%AD%A3%E5%9C%A8%E6%89%A7%E8%A1%8C%E7%9A%84%E7%BA%BF%E7%A8%8B%E5%AF%B9%E8%B1%A1%E7%9A%84%E5%BC%95%E7%94%A8%E3%80%82%0A%0A%23%23%23%23%23%204.2%20getId()%0A%3E%E8%BF%94%E5%9B%9E%E6%AD%A4%E7%BA%BF%E7%A8%8B%E7%9A%84%E6%A0%87%E8%AF%86%E7%AC%A6%0A%0A%23%23%23%23%23%204.3%20getName()%0A%3E%E8%BF%94%E5%9B%9E%E6%AD%A4%E7%BA%BF%E7%A8%8B%E7%9A%84%E5%90%8D%E7%A7%B0%0A%0A%23%23%23%23%23%204.4%20getPriority()%0A%3E%E8%BF%94%E5%9B%9E%E6%AD%A4%E7%BA%BF%E7%A8%8B%E7%9A%84%E4%BC%98%E5%85%88%E7%BA%A7%0A%0A%23%23%23%23%23%204.5%20isAlive()%0A%3E%E6%B5%8B%E8%AF%95%E8%BF%99%E4%B8%AA%E7%BA%BF%E7%A8%8B%E6%98%AF%E5%90%A6%E8%BF%98%E5%A4%84%E4%BA%8E%E6%B4%BB%E5%8A%A8%E7%8A%B6%E6%80%81%E3%80%82%0A%E4%BB%80%E4%B9%88%E6%98%AF%E6%B4%BB%E5%8A%A8%E7%8A%B6%E6%80%81%E5%91%A2%EF%BC%9F%0A%E6%B4%BB%E5%8A%A8%E7%8A%B6%E6%80%81%E5%B0%B1%E6%98%AF%E7%BA%BF%E7%A8%8B%E5%B7%B2%E7%BB%8F%E5%90%AF%E5%8A%A8%E4%B8%94%E5%B0%9A%E6%9C%AA%E7%BB%88%E6%AD%A2%E3%80%82%E7%BA%BF%E7%A8%8B%E5%A4%84%E4%BA%8E%E6%AD%A3%E5%9C%A8%E8%BF%90%E8%A1%8C%E6%88%96%E5%87%86%E5%A4%87%E8%BF%90%E8%A1%8C%E7%9A%84%E7%8A%B6%E6%80%81%E3%80%82%0A%0A%23%23%23%23%23%204.6%20sleep(long%20millis)%0A%3E%E4%BD%BF%E5%BD%93%E5%89%8D%E6%AD%A3%E5%9C%A8%E6%89%A7%E8%A1%8C%E7%9A%84%E7%BA%BF%E7%A8%8B%E4%BB%A5%E6%8C%87%E5%AE%9A%E7%9A%84%E6%AF%AB%E7%A7%92%E6%95%B0%E2%80%9C%E4%BC%91%E7%9C%A0%E2%80%9D%EF%BC%88%E6%9A%82%E6%97%B6%E5%81%9C%E6%AD%A2%E6%89%A7%E8%A1%8C%EF%BC%89%EF%BC%8C%E5%85%B7%E4%BD%93%E5%8F%96%E5%86%B3%E4%BA%8E%E7%B3%BB%E7%BB%9F%E5%AE%9A%E6%97%B6%E5%99%A8%E5%92%8C%E8%B0%83%E5%BA%A6%E7%A8%8B%E5%BA%8F%E7%9A%84%E7%B2%BE%E5%BA%A6%E5%92%8C%E5%87%86%E7%A1%AE%E6%80%A7%E3%80%82%0A%0A%23%23%23%23%23%204.7%20interrupt()%0A%3E%E4%B8%AD%E6%96%AD%E8%BF%99%E4%B8%AA%E7%BA%BF%E7%A8%8B%E3%80%82%0A%0A%23%23%23%23%23%204.8%20interrupted()%20%E5%92%8CisInterrupted()%0A%3Einterrupted()%EF%BC%9A%E6%B5%8B%E8%AF%95%E5%BD%93%E5%89%8D%E7%BA%BF%E7%A8%8B%E6%98%AF%E5%90%A6%E5%B7%B2%E7%BB%8F%E6%98%AF%E4%B8%AD%E6%96%AD%E7%8A%B6%E6%80%81%EF%BC%8C%E6%89%A7%E8%A1%8C%E5%90%8E%E5%85%B7%E6%9C%89%E5%B0%86%E7%8A%B6%E6%80%81%E6%A0%87%E5%BF%97%E6%B8%85%E9%99%A4%E4%B8%BAfalse%E7%9A%84%E5%8A%9F%E8%83%BD%0AisInterrupted()%EF%BC%9A%20%E6%B5%8B%E8%AF%95%E7%BA%BF%E7%A8%8BThread%E5%AF%B9%E7%9B%B8%E5%85%B3%E6%98%AF%E5%90%A6%E5%B7%B2%E7%BB%8F%E6%98%AF%E4%B8%AD%E6%96%AD%E7%8A%B6%E6%80%81%EF%BC%8C%E4%BD%86%E9%83%A8%E6%B8%85%E6%A5%9A%E7%8A%B6%E6%80%81%E6%A0%87%E5%BF%97%0A%0A%23%23%23%23%23%204.9%20setName(String%20name)%0A%3E%E5%B0%86%E6%AD%A4%E7%BA%BF%E7%A8%8B%E7%9A%84%E5%90%8D%E7%A7%B0%E6%9B%B4%E6%94%B9%E4%B8%BA%E7%AD%89%E4%BA%8E%E5%8F%82%E6%95%B0%20name%20%E3%80%82%0A%0A%23%23%23%23%23%204.10%20isDaemon()%0A%3E%E6%B5%8B%E8%AF%95%E8%BF%99%E4%B8%AA%E7%BA%BF%E7%A8%8B%E6%98%AF%E5%90%A6%E6%98%AF%E5%AE%88%E6%8A%A4%E7%BA%BF%E7%A8%8B%E3%80%82%0A%0A%23%23%23%23%23%204.11%20setDaemon(boolean%20on)%0A%3E%E5%B0%86%E6%AD%A4%E7%BA%BF%E7%A8%8B%E6%A0%87%E8%AE%B0%E4%B8%BA%20daemon%E7%BA%BF%E7%A8%8B%E6%88%96%E7%94%A8%E6%88%B7%E7%BA%BF%E7%A8%8B%E3%80%82%0A%0A%23%23%23%23%23%204.12%20join()%0A%3E%E5%9C%A8%E5%BE%88%E5%A4%9A%E6%83%85%E5%86%B5%E4%B8%8B%EF%BC%8C%E4%B8%BB%E7%BA%BF%E7%A8%8B%E7%94%9F%E6%88%90%E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%EF%BC%8C%E8%BF%99%E9%87%8C%E9%9C%80%E8%A6%81%E7%90%86%E8%A7%A3%E7%9A%84%E5%B0%B1%E6%98%AF%E8%AF%A5%E7%BA%BF%E7%A8%8B%E6%98%AF%E6%8C%87%E7%9A%84%E4%B8%BB%E7%BA%BF%E7%A8%8B%E7%AD%89%E5%BE%85%E5%AD%90%E7%BA%BF%E7%A8%8B%E7%9A%84%E7%BB%88%E6%AD%A2%E3%80%82%E4%B9%9F%E5%B0%B1%E6%98%AF%E5%9C%A8%E5%AD%90%E7%BA%BF%E7%A8%8B%E8%B0%83%E7%94%A8%E4%BA%86join()%E6%96%B9%E6%B3%95%E5%90%8E%E9%9D%A2%E7%9A%84%E4%BB%A3%E7%A0%81%EF%BC%8C%E5%8F%AA%E6%9C%89%E7%AD%89%E5%88%B0%E5%AD%90%E7%BA%BF%E7%A8%8B%E7%BB%93%E6%9D%9F%E4%BA%86%E6%89%8D%E8%83%BD%E6%89%A7%E8%A1%8C%0A%0A%23%23%23%23%23%204.13%20yield()%0A%3Eyield()%E6%96%B9%E6%B3%95%E7%9A%84%E4%BD%9C%E7%94%A8%E6%98%AF%E6%94%BE%E5%BC%83%E5%BD%93%E5%89%8D%E7%9A%84CPU%E8%B5%84%E6%BA%90%EF%BC%8C%E5%B0%86%E5%AE%83%E8%AE%A9%E7%BB%99%E5%85%B6%E4%BB%96%E7%9A%84%E4%BB%BB%E5%8A%A1%E5%8E%BB%E5%8D%A0%E7%94%A8CPU%E6%97%B6%E9%97%B4%E3%80%82%E6%B3%A8%E6%84%8F%EF%BC%9A%E6%94%BE%E5%BC%83%E7%9A%84%E6%97%B6%E9%97%B4%E4%B8%8D%E7%A1%AE%E5%AE%9A%EF%BC%8C%E5%8F%AF%E8%83%BD%E4%B8%80%E4%BC%9A%E5%B0%B1%E4%BC%9A%E9%87%8D%E6%96%B0%E8%8E%B7%E5%BE%97CPU%E6%97%B6%E9%97%B4%E7%89%87%E3%80%82%0A%0A%23%23%23%23%23%204.14%20setPriority(int%20newPriority)%0A%3E%E6%9B%B4%E6%94%B9%E6%AD%A4%E7%BA%BF%E7%A8%8B%E7%9A%84%E4%BC%98%E5%85%88%E7%BA%A7%0A%0A%0A%23%23%20%E4%BA%8C.%20%E7%BA%BF%E7%A8%8B%E5%AE%89%E5%85%A8%0A%0A%23%23%23%200.%20%E9%94%81%0A%23%23%23%23%200.1%20%E4%B8%BA%E4%BB%80%E4%B9%88%E9%9C%80%E8%A6%81%E9%94%81%EF%BC%88%E5%B9%B6%E5%8F%91%E6%8E%A7%E5%88%B6%EF%BC%89%EF%BC%9F%0A%3E%E5%9C%A8%E5%A4%9A%E7%94%A8%E6%88%B7%E7%8E%AF%E5%A2%83%E4%B8%AD%EF%BC%8C%E5%9C%A8%E5%90%8C%E4%B8%80%E6%97%B6%E9%97%B4%E5%8F%AF%E8%83%BD%E4%BC%9A%E6%9C%89%E5%A4%9A%E4%B8%AA%E7%94%A8%E6%88%B7%E6%9B%B4%E6%96%B0%E7%9B%B8%E5%90%8C%E7%9A%84%E8%AE%B0%E5%BD%95%EF%BC%8C%E8%BF%99%E4%BC%9A%E4%BA%A7%E7%94%9F**%E5%86%B2%E7%AA%81**%E3%80%82%E8%BF%99%E5%B0%B1%E6%98%AF%E8%91%97%E5%90%8D%E7%9A%84%E5%B9%B6%E5%8F%91%E6%80%A7%E9%97%AE%E9%A2%98%E3%80%82%0A%0A%3E%E5%85%B8%E5%9E%8B%E7%9A%84%E5%86%B2%E7%AA%81%E6%9C%89%EF%BC%9A%0A%3E1.%20%E4%B8%A2%E5%A4%B1%E6%9B%B4%E6%96%B0%EF%BC%9A%E4%B8%80%E4%B8%AA%E4%BA%8B%E5%8A%A1%E7%9A%84%E6%9B%B4%E6%96%B0%E8%A6%86%E7%9B%96%E4%BA%86%E5%85%B6%E5%AE%83%E4%BA%8B%E5%8A%A1%E7%9A%84%E6%9B%B4%E6%96%B0%E7%BB%93%E6%9E%9C%EF%BC%8C%E5%B0%B1%E6%98%AF%E6%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E7%A8%8B%EF%BC%89%E3%80%82%0A%3E2.%20%E4%BC%A0%E7%BB%9F%E7%9A%84%E5%85%B3%E7%B3%BB%E5%9E%8B%E6%95%B0%E6%8D%AE%E5%BA%93%E9%87%8C%E8%BE%B9%E5%B0%B1%E7%94%A8%E5%88%B0%E4%BA%86%E5%BE%88%E5%A4%9A%E8%BF%99%E7%A7%8D%E9%94%81%E6%9C%BA%E5%88%B6%EF%BC%8C%E6%AF%94%E5%A6%82%E8%A1%8C%E9%94%81%EF%BC%8C%E8%A1%A8%E9%94%81%E7%AD%89%EF%BC%8C%E8%AF%BB%E9%94%81%EF%BC%8C%E5%86%99%E9%94%81%E7%AD%89%EF%BC%8C%E9%83%BD%E6%98%AF%E5%9C%A8%E5%81%9A%E6%93%8D%E4%BD%9C%E4%B9%8B%E5%89%8D%E5%85%88%E4%B8%8A%E9%94%81%E3%80%82%0A%3E3.%20Java%E4%B8%ADsynchronized%E5%92%8CReentrantLock%E7%AD%89%E7%8B%AC%E5%8D%A0%E9%94%81%E5%B0%B1%E6%98%AF%E6%82%B2%E8%A7%82%E9%94%81%E6%80%9D%E6%83%B3%E7%9A%84%E5%AE%9E%E7%8E%B0%E3%80%82%0A%0A%3E*%20%E4%B9%90%E8%A7%82%E9%94%81%0A%3E1.%20%E6%80%BB%E6%98%AF%E5%81%87%E8%AE%BE%E6%9C%80%E5%A5%BD%E7%9A%84%E6%83%85%E5%86%B5%EF%BC%8C%E6%AF%8F%E6%AC%A1%E5%8E%BB%E6%8B%BF%E6%95%B0%E6%8D%AE%E7%9A%84%E6%97%B6%E5%80%99%E9%83%BD%E8%AE%A4%E4%B8%BA%E5%88%AB%E4%BA%BA%E4%B8%8D%E4%BC%9A%E4%BF%AE%E6%94%B9%EF%BC%8C%E6%89%80%E4%BB%A5%E4%B8%8D%E4%BC%9A%E4%B8%8A%E9%94%81%EF%BC%8C%E4%BD%86%E6%98%AF%E5%9C%A8%E6%9B%B4%E6%96%B0%E7%9A%84%E6%97%B6%E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%20CAS%20%E6%97%A0%E6%95%88%E3%80%82%0A%0A%23%23%23%23%200.5%20%E4%B9%90%E8%A7%82%E9%94%81%E4%B8%8E%E6%82%B2%E8%A7%82%E9%94%81%E8%AF%A6%E8%A7%A3%0A%3E%5B%E4%B9%90%E8%A7%82%E9%94%81%E4%B8%8E%E6%82%B2%E8%A7%82%E9%94%81%E8%AF%A6%E8%A7%A3%5D(https%3A%2F%2Fblog.csdn.net%2Fqq_34337272%2Farticle%2Fdetails%2F81072874)%0A%0A---%0A%23%23%23%201.%20synchronized%E5%85%B3%E9%94%AE%E5%AD%97(1)%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/d8793a70-f006-4121-9ada-0d69a9d827b4.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F615%3A1)%0A%5Bsynchronized%E5%85%B3%E9%94%AE%E5%AD%971%5D(https%3A%2F%2Fblog.csdn.net%2Fqq_34337272%2Farticle%2Fdetails%2F79655194)%0A-%20-%20-%0A*%20synchronized%0A%3EJava%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B%E8%BF%99%E4%B8%AA%E9%A2%86%E5%9F%9F%E4%B8%ADsynchronized%E5%85%B3%E9%94%AE%E5%AD%97%E4%B8%80%E7%9B%B4%E9%83%BD%E6%98%AF%E5%85%83%E8%80%81%E7%BA%A7%E7%9A%84%E8%A7%92%E8%89%B2%EF%BC%8C%E5%BE%88%E4%B9%85%E4%B9%8B%E5%89%8D%E5%BE%88%E5%A4%9A%E4%BA%BA%E9%83%BD%E4%BC%9A%E7%A7%B0%E5%AE%83%E4%B8%BA%20%E2%80%9C%E9%87%8D%E9%87%8F%E7%BA%A7%E9%94%81%E2%80%9D%20%E3%80%82%0A%3E%E4%BD%86%E6%98%AF%EF%BC%8C%E5%9C%A8JavaSE%201.6%E4%B9%8B%E5%90%8E%E8%BF%9B%E8%A1%8C%E4%BA%86%E4%B8%BB%E8%A6%81%E5%8C%85%E6%8B%AC%E4%B8%BA%E4%BA%86%E5%87%8F%E5%B0%91%E8%8E%B7%E5%BE%97%E9%94%81%E5%92%8C%E9%87%8A%E6%94%BE%E9%94%81%E5%B8%A6%E6%9D%A5%E7%9A%84%E6%80%A7%E8%83%BD%E6%B6%88%E8%80%97%E8%80%8C%E5%BC%95%E5%85%A5%E7%9A%84%20**%E5%81%8F%E5%90%91%E9%94%81**%E5%92%8C%20**%E8%BD%BB%E9%87%8F%E7%BA%A7%E9%94%81**%20%E4%BB%A5%E5%8F%8A%E5%85%B6%E5%AE%83%E5%90%84%E7%A7%8D%E4%BC%98%E5%8C%96%E4%B9%8B%E5%90%8E%E5%8F%98%E5%BE%97%E5%9C%A8%E6%9F%90%E4%BA%9B%E6%83%85%E5%86%B5%E4%B8%8B%E5%B9%B6%E4%B8%8D%E6%98%AF%E9%82%A3%E4%B9%88%E9%87%8D%E4%BA%86%E3%80%82synchronized%E7%9A%84%E5%BA%95%E5%B1%82%E5%AE%9E%E7%8E%B0%E4%B8%BB%E8%A6%81%E4%BE%9D%E9%9D%A0%20Lock-Free%20%E7%9A%84%E9%98%9F%E5%88%97%EF%BC%8C%E5%9F%BA%E6%9C%AC%E6%80%9D%E8%B7%AF%E6%98%AF%20**%E8%87%AA%E6%97%8B%E5%90%8E%E9%98%BB%E5%A1%9E**%EF%BC%8C**%E7%AB%9E%E4%BA%89%E5%88%87%E6%8D%A2%E5%90%8E%E7%BB%A7%E7%BB%AD%E7%AB%9E%E4%BA%89%E9%94%81**%EF%BC%8C%E7%A8%8D%E5%BE%AE%E7%89%BA%E7%89%B2%E4%BA%86%E5%85%AC%E5%B9%B3%E6%80%A7%EF%BC%8C%E4%BD%86%E8%8E%B7%E5%BE%97%E4%BA%86%E9%AB%98%E5%90%9E%E5%90%90%E9%87%8F%E3%80%82%E5%9C%A8%E7%BA%BF%E7%A8%8B%E5%86%B2%E7%AA%81%E8%BE%83%E5%B0%91%E7%9A%84%E6%83%85%E5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%AE%9E%E4%BE%8B%E5%8F%98%E9%87%8F%EF%BC%8C%E5%88%99%E4%BC%9A%E5%87%BA%E7%8E%B0%E2%80%9C%3Cu%3E%E9%9D%9E%E7%BA%BF%E7%A8%8B%E5%AE%89%E5%85%A8%3C%2Fu%3E%E2%80%9D%EF%BC%8C%E8%A7%A3%E5%86%B3%E5%8A%9E%E6%B3%95%E5%B0%B1%E6%98%AF%E5%9C%A8%E6%96%B9%E6%B3%95%E5%89%8D%E5%8A%A0%E4%B8%8A**synchronized**%E5%85%B3%E9%94%AE%E5%AD%97%E5%8D%B3%E5%8F%AF%E3%80%82%0A%23%23%23%23%201.2%20%E5%A4%9A%E4%B8%AA%E5%AF%B9%E8%B1%A1%E5%AF%B9%E4%B8%AA%E9%94%81%0A%3Esynchronized%E5%8F%96%E5%BE%97%E7%9A%84%E9%94%81%E9%83%BD%E6%98%AF**%E5%AF%B9%E8%B1%A1%E9%94%81**%EF%BC%8C%E8%80%8C%E4%B8%8D%E6%98%AF%E6%8A%8A%E4%B8%80%E6%AE%B5%E4%BB%A3%E7%A0%81%E6%88%96%E6%96%B9%E6%B3%95%E5%BD%93%E5%81%9A%E9%94%81%E3%80%82%E6%89%80%E4%BB%A5%E5%9C%A8%E4%B8%8A%E9%9D%A2%E7%9A%84%E5%AE%9E%E4%BE%8B%E4%B8%AD%EF%BC%8C%E5%93%AA%E4%B8%AA%E7%BA%BF%E7%A8%8B%E5%85%88%E6%89%A7%E8%A1%8C%E5%B8%A6synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E7%9A%84%E6%96%B9%E6%B3%95%EF%BC%8C%E5%88%99%E5%93%AA%E4%B8%AA%E7%BA%BF%E7%A8%8B%E5%B0%B1%E6%8C%81%E6%9C%89%E8%AF%A5%E6%96%B9%E6%B3%95%E6%89%80%E5%B1%9E%E5%AF%B9%E8%B1%A1%E7%9A%84%E9%94%81Lock%EF%BC%8C%E9%82%A3%E4%B9%88%E5%85%B6%E4%BB%96%E7%BA%BF%E7%A8%8B%E5%8F%AA%E8%83%BD%E5%91%88%E7%AD%89%E5%BE%85%E7%8A%B6%E6%80%81%EF%BC%8C%E5%89%8D%E6%8F%90%E6%98%AF%E5%A4%9A%E4%B8%AA%E7%BA%BF%E7%A8%8B%E8%AE%BF%E9%97%AE%E7%9A%84%E6%98%AF**%E5%90%8C%E4%B8%80%E4%B8%AA%E5%AF%B9%E8%B1%A1**%E3%80%82%0A%0A%23%23%23%23%201.3%20synchronized%E6%96%B9%E6%B3%95%E4%B8%8E%E9%94%81%E5%AF%B9%E8%B1%A1%0A%3Esynchronized%E5%8F%96%E5%BE%97%E7%9A%84%E9%94%81%E9%83%BD%E6%98%AF%E5%AF%B9%E8%B1%A1%E9%94%81%EF%BC%8C%E8%80%8C%E4%B8%8D%E6%98%AF%E6%8A%8A%E4%B8%80%E6%AE%B5%E4%BB%A3%E7%A0%81%E6%88%96%E6%96%B9%E6%B3%95%E5%BD%93%E5%81%9A%E9%94%81%E3%80%82%E5%A6%82%E6%9E%9C%E5%A4%9A%E4%B8%AA%E7%BA%BF%E7%A8%8B%E8%AE%BF%E9%97%AE%E7%9A%84%E6%98%AF%E5%90%8C%E4%B8%80%E4%B8%AA%E5%AF%B9%E8%B1%A1%EF%BC%8C%E5%93%AA%E4%B8%AA%E7%BA%BF%E7%A8%8B%E5%85%88%E6%89%A7%E8%A1%8C%E5%B8%A6synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E7%9A%84%E6%96%B9%E6%B3%95%EF%BC%8C%E5%88%99%E5%93%AA%E4%B8%AA%E7%BA%BF%E7%A8%8B%E5%B0%B1%E6%8C%81%E6%9C%89%E8%AF%A5%E6%96%B9%E6%B3%95%EF%BC%8C%E9%82%A3%E4%B9%88%E5%85%B6%E4%BB%96%E7%BA%BF%E7%A8%8B%E5%8F%AA%E8%83%BD%E5%91%88%E7%AD%89%E5%BE%85%E7%8A%B6%E6%80%81%E3%80%82%0A%3E%E5%A6%82%E6%9E%9C%E5%A4%9A%E4%B8%AA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4%BD%86%E6%98%AF%E5%90%8C%E6%AD%A5%E4%B8%8D%E8%83%BD%E7%BB%A7%E6%89%BF%EF%BC%8C%E6%89%80%E4%BB%A5%E8%BF%98%E6%98%AF%E9%9C%80%E8%A6%81%E5%9C%A8%E5%AD%90%E7%B1%BB%E6%96%B9%E6%B3%95%E4%B8%AD%E6%B7%BB%E5%8A%A0synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E3%80%82%0A%0A%23%23%23%202.%20synchronized%E5%85%B3%E9%94%AE%E5%AD%97%EF%BC%882%EF%BC%89%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/0f8be4bb-b892-4198-8904-963482ade8f8.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F616%3A1)%0A%5Bsynchronized%E5%85%B3%E9%94%AE%E5%AD%972%5D(https%3A%2F%2Fblog.csdn.net%2Fqq_34337272%2Farticle%2Fdetails%2F79670775)%0A%23%23%23%23%202.1%20synchronized%E6%96%B9%E6%B3%95%E7%9A%84%E7%BC%BA%E7%82%B9%0A*%20%E4%BD%BF%E7%94%A8synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E5%A3%B0%E6%98%8E%E6%96%B9%E6%B3%95%E6%9C%89%E4%BA%9B%E6%97%B6%E5%80%99%E6%98%AF%E6%9C%89%E5%BE%88%E5%A4%A7%E7%9A%84%E5%BC%8A%E7%AB%AF%E7%9A%84%EF%BC%8C%E6%AF%94%E5%A6%82%E6%88%91%E4%BB%AC%E6%9C%89%E4%B8%A4%E4%B8%AA%E7%BA%BF%E7%A8%8B%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8BA%E8%B0%83%E7%94%A8%E5%90%8C%E6%AD%A5%E6%96%B9%E6%B3%95%E5%90%8E%E8%8E%B7%E5%BE%97%E9%94%81%EF%BC%8C%E9%82%A3%E4%B9%88%E5%8F%A6%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8BB%E5%B0%B1%E9%9C%80%E8%A6%81%E7%AD%89%E5%BE%85A%E6%89%A7%E8%A1%8C%E5%AE%8C%EF%BC%8C%E4%BD%86%E6%98%AF%E5%A6%82%E6%9E%9C%E8%AF%B4A%E6%89%A7%E8%A1%8C%E7%9A%84%E6%98%AF%E4%B8%80%E4%B8%AA%E5%BE%88%E8%B4%B9%E6%97%B6%E9%97%B4%E7%9A%84%E4%BB%BB%E5%8A%A1%E7%9A%84%E8%AF%9D%E8%BF%99%E6%A0%B7%E5%B0%B1%E4%BC%9A%E5%BE%88%E8%80%97%E6%97%B6%E3%80%82%0A%0A%3E%E5%8F%AF%E4%BB%A5%E4%BD%BF%E7%94%A8**synchronized%E5%90%8C%E6%AD%A5%E5%9D%97**%E6%9D%A5%E8%A7%A3%E5%86%B3%E8%BF%99%E4%B8%AA%E9%97%AE%E9%A2%98%E3%80%82%E4%BD%86%E6%98%AF%E8%A6%81%E6%B3%A8%E6%84%8Fsynchronized%E5%90%8C%E6%AD%A5%E5%9D%97%E7%9A%84%E4%BD%BF%E7%94%A8%E6%96%B9%E5%BC%8F%EF%BC%8C%E5%A6%82%E6%9E%9Csynchronized%E5%90%8C%E6%AD%A5%E5%9D%97%E4%BD%BF%E7%94%A8%E4%B8%8D%E5%A5%BD%E7%9A%84%E8%AF%9D%E5%B9%B6%E4%B8%8D%E4%BC%9A%E5%B8%A6%E6%9D%A5%E6%95%88%E7%8E%87%E7%9A%84%E6%8F%90%E5%8D%87%E3%80%82%0A%0A%23%23%23%23%202.2%20synchronized%EF%BC%88this%EF%BC%89%E5%90%8C%E6%AD%A5%E4%BB%A3%E7%A0%81%E5%9D%97%E7%9A%84%E4%BD%BF%E7%94%A8%0A%60%60%60java%0Apublic%20class%20Task%20%7B%0A%0A%20%20%20%20private%20String%20getData1%3B%0A%20%20%20%20private%20String%20getData2%3B%0A%0A%20%20%20%20public%20void%20doLongTimeTask()%20%7B%0A%20%20%20%20%20%20%20%20try%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20System.out.println(%22begin%20task%22)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20Thread.sleep(3000)%3B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20String%20privateGetData1%20%3D%20%22%E9%95%BF%E6%97%B6%E9%97%B4%E5%A4%84%E7%90%86%E4%BB%BB%E5%8A%A1%E5%90%8E%E4%BB%8E%E8%BF%9C%E7%A8%8B%E8%BF%94%E5%9B%9E%E7%9A%84%E5%80%BC1%20threadName%3D%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2B%20Thread.currentThread().getName()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20String%20privateGetData2%20%3D%20%22%E9%95%BF%E6%97%B6%E9%97%B4%E5%A4%84%E7%90%86%E4%BB%BB%E5%8A%A1%E5%90%8E%E4%BB%8E%E8%BF%9C%E7%A8%8B%E8%BF%94%E5%9B%9E%E7%9A%84%E5%80%BC2%20threadName%3D%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2B%20Thread.currentThread().getName()%3B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20synchronized%20(this)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20getData1%20%3D%20privateGetData1%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20getData2%20%3D%20privateGetData2%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20System.out.println(getData1)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20System.out.println(getData2)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20System.out.println(%22end%20task%22)%3B%0A%20%20%20%20%20%20%20%20%7D%20catch%20(InterruptedException%20e)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20TODO%20Auto-generated%20catch%20block%0A%20%20%20%20%20%20%20%20%20%20%20%20e.printStackTrace()%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%7D%0A%60%60%60%0A*%20%E5%BD%93%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%E8%AE%BF%E9%97%AE%E4%B8%80%E4%B8%AA%E5%AF%B9%E8%B1%A1%E7%9A%84synchronized%E5%90%8C%E6%AD%A5%E4%BB%A3%E7%A0%81%E5%9D%97%E6%97%B6%EF%BC%8C%E5%8F%A6%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%E4%BB%BB%E7%84%B6%E5%8F%AF%E4%BB%A5%E8%AE%BF%E9%97%AE%E8%AF%A5%E5%AF%B9%E8%B1%A1%E9%9D%9Esynchronized%E5%90%8C%E6%AD%A5%E4%BB%A3%E7%A0%81%E5%9D%97%E3%80%82%0A*%20%E4%B8%8D%E5%9C%A8synchronized%E4%BB%A3%E7%A0%81%E5%9D%97%E4%B8%AD%E5%B0%B1%E5%BC%82%E6%AD%A5%E6%89%A7%E8%A1%8C%EF%BC%8C%E5%9C%A8synchronized%E4%BB%A3%E7%A0%81%E5%9D%97%E4%B8%AD%E5%B0%B1%E6%98%AF%E5%90%8C%E6%AD%A5%E6%89%A7%E8%A1%8C%E3%80%82%0A%0A%23%23%23%23%202.3%20synchronized%EF%BC%88object%EF%BC%89%E4%BB%A3%E7%A0%81%E5%9D%97%E9%97%B4%E4%BD%BF%E7%94%A8%0A*%20%E4%B8%A4%E4%B8%AA%E7%BA%BF%E7%A8%8B%E4%BD%BF%E7%94%A8%E4%BA%86%E5%90%8C%E4%B8%80%E4%B8%AA%E2%80%9C%E5%AF%B9%E8%B1%A1%E7%9B%91%E8%A7%86%E5%99%A8%E2%80%9D%2C%E6%89%80%E4%BB%A5%E8%BF%90%E8%A1%8C%E7%BB%93%E6%9E%9C%E6%98%AF%E5%90%8C%E6%AD%A5%E7%9A%84%E3%80%82%0A*%20%E4%B8%A4%E4%B8%AA%E7%BA%BF%E7%A8%8B%E4%BD%BF%E7%94%A8%E4%BA%86%E4%B8%8D%E5%90%8C%E7%9A%84%E2%80%9C%E5%AF%B9%E8%B1%A1%E7%9B%91%E8%A7%86%E5%99%A8%E2%80%9D%2C%E6%89%80%E4%BB%A5%E8%BF%90%E8%A1%8C%E7%BB%93%E6%9E%9C%E4%B8%8D%E6%98%AF%E5%90%8C%E6%AD%A5%E7%9A%84%E4%BA%86%E3%80%82%C2%A0%0A%0A%23%23%23%23%202.4%20synchronized%E4%BB%A3%E7%A0%81%E5%9D%97%E9%97%B4%E7%9A%84%E5%90%8C%E6%AD%A5%E6%80%A7%0A*%20%E5%BD%93%E4%B8%80%E4%B8%AA%E5%AF%B9%E8%B1%A1%E8%AE%BF%E9%97%AEsynchronized(this)%E4%BB%A3%E7%A0%81%E5%9D%97%E6%97%B6%EF%BC%8C%E5%85%B6%E4%BB%96%E7%BA%BF%E7%A8%8B%E5%AF%B9%E5%90%8C%E4%B8%80%E4%B8%AA%E5%AF%B9%E8%B1%A1%E4%B8%AD%E6%89%80%E6%9C%89%E5%85%B6%E4%BB%96synchronized(this)%E4%BB%A3%E7%A0%81%E5%9D%97%E4%BB%A3%E7%A0%81%E5%9D%97%E7%9A%84%E8%AE%BF%E9%97%AE%E5%B0%86%E8%A2%AB%E9%98%BB%E5%A1%9E%EF%BC%8C%E8%BF%99%E8%AF%B4%E6%98%8Esynchronized(this)%E4%BB%A3%E7%A0%81%E5%9D%97%E4%BD%BF%E7%94%A8%E7%9A%84%E2%80%9C%E5%AF%B9%E8%B1%A1%E7%9B%91%E8%A7%86%E5%99%A8%E2%80%9D%E6%98%AF%E5%90%8C%E4%B8%80%E4%B8%AA%E3%80%82%0A*%20%E5%92%8Csynchronized%E6%96%B9%E6%B3%95%E4%B8%80%E6%A0%B7%EF%BC%8Csynchronized(this)%E4%BB%A3%E7%A0%81%E5%9D%97%E4%B9%9F%E6%98%AF%E9%94%81%E5%AE%9A%E5%BD%93%E5%89%8D%E5%AF%B9%E8%B1%A1%E3%80%82%0A%3E1.%20%E5%85%B6%E4%BB%96%E7%BA%BF%E7%A8%8B%E6%89%A7%E8%A1%8C%E5%AF%B9%E8%B1%A1%E4%B8%ADsynchronized%E5%90%8C%E6%AD%A5%E6%96%B9%E6%B3%95%E5%92%8Csynchronized(this)%E4%BB%A3%E7%A0%81%E5%9D%97%E6%97%B6%E5%91%88%E7%8E%B0%E5%90%8C%E6%AD%A5%E6%95%88%E6%9E%9C%3B%0A%3E2.%20%E5%A6%82%E6%9E%9C%E4%B8%A4%E4%B8%AA%E7%BA%BF%E7%A8%8B%E4%BD%BF%E7%94%A8%E4%BA%86%E5%90%8C%E4%B8%80%E4%B8%AA%E2%80%9C%E5%AF%B9%E8%B1%A1%E7%9B%91%E8%A7%86%E5%99%A8%E2%80%9D%2C%E8%BF%90%E8%A1%8C%E7%BB%93%E6%9E%9C%E5%90%8C%E6%AD%A5%EF%BC%8C%E5%90%A6%E5%88%99%E4%B8%8D%E5%90%8C%E6%AD%A5.%0A%0A%23%23%23%23%202.5%20%E9%9D%99%E6%80%81%E5%90%8C%E6%AD%A5synchronized%E6%96%B9%E6%B3%95%E4%B8%8Esynchronized(class)%E4%BB%A3%E7%A0%81%E5%9D%97%0A*%20synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E5%8A%A0%E5%88%B0static%E9%9D%99%E6%80%81%E6%96%B9%E6%B3%95%E5%92%8Csynchronized(class)%E4%BB%A3%E7%A0%81%E5%9D%97%E4%B8%8A%E9%83%BD%E6%98%AF%E6%98%AF**%E7%BB%99Class%E7%B1%BB%E4%B8%8A%E9%94%81**%EF%BC%8C%E8%80%8Csynchronized%E5%85%B3%E9%94%AE%E5%AD%97%E5%8A%A0%E5%88%B0**%E9%9D%9E%E9%9D%99%E6%80%81%E6%96%B9%E6%B3%95**%E4%B8%8A%E6%98%AF%E7%BB%99**%E5%AF%B9%E8%B1%A1%E4%B8%8A%E9%94%81**%E3%80%82%0A*%20%E9%9D%99%E6%80%81%E5%90%8C%E6%AD%A5synchronized%E6%96%B9%E6%B3%95%E4%B8%8Esynchronized(class)%E4%BB%A3%E7%A0%81%E5%9D%97%E6%8C%81%E6%9C%89%E7%9A%84%E9%94%81%E4%B8%80%E6%A0%B7%EF%BC%8C%E9%83%BD%E6%98%AFClass%E9%94%81%EF%BC%8CClass%E9%94%81%E5%AF%B9%E5%AF%B9%E8%B1%A1%E7%9A%84%E6%89%80%E6%9C%89%E5%AE%9E%E4%BE%8B%E8%B5%B7%E4%BD%9C%E7%94%A8%E3%80%82%0A%0A%23%23%23%203.%20volatile%E5%85%B3%E9%94%AE%E5%AD%97%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/e6fb41c0-7e51-49af-8a93-15eb018adb0b.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F617%3A1)%0A%5Bvolatile%E5%85%B3%E9%94%AE%E5%AD%97%5D(https%3A%2F%2Fblog.csdn.net%2Fqq_34337272%2Farticle%2Fdetails%2F79680771)%0A%23%23%23%23%203.1%20volatile%E5%85%B3%E9%94%AE%E5%AD%97%E7%AE%80%E4%BB%8B%0A*%20volatile%E5%85%B3%E9%94%AE%E5%AD%97%E5%8F%AF%E4%BB%A5%E7%94%A8%E6%9D%A5%E6%8F%90%E9%86%92%E7%BC%96%E8%AF%91%E5%99%A8%E5%AE%83%E5%90%8E%E9%9D%A2%E6%89%80%E5%AE%9A%E4%B9%89%E7%9A%84%E5%8F%98%E9%87%8F%E9%9A%8F%E6%97%B6%E6%9C%89%E5%8F%AF%E8%83%BD%E6%94%B9%E5%8F%98%EF%BC%8C%E5%9B%A0%E6%AD%A4%E7%BC%96%E8%AF%91%E5%90%8E%E7%9A%84%E7%A8%8B%E5%BA%8F%E6%AF%8F%E6%AC%A1%E9%9C%80%E8%A6%81%E5%AD%98%E5%82%A8%E6%88%96%E8%AF%BB%E5%8F%96%E8%BF%99%E4%B8%AA%E5%8F%98%E9%87%8F%E7%9A%84%E6%97%B6%E5%80%99%EF%BC%8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91%98%E5%8F%98%E9%87%8F%E7%9A%84%E5%80%BC%E3%80%82%E8%80%8C%E4%B8%94%EF%BC%8C%E5%BD%93%E6%88%90%E5%91%98%E5%8F%98%E9%87%8F%E5%8F%91%E7%94%9F%E5%8F%98%E5%8C%96%E6%97%B6%EF%BC%8C%E5%BC%BA%E8%BF%AB%E7%BA%BF%E7%A8%8B%E5%B0%86%E5%8F%98%E5%8C%96%E5%80%BC%E5%9B%9E%E5%86%99%E5%88%B0%E4%B8%BB%E5%AD%98%EF%BC%88%E5%85%B1%E4%BA%AB%E5%86%85%E5%AD%98%EF%BC%89%E3%80%82%E8%BF%99%E6%A0%B7%E5%9C%A8%E4%BB%BB%E4%BD%95%E6%97%B6%E5%88%BB%EF%BC%8C%E4%B8%A4%E4%B8%AA%E4%B8%8D%E5%90%8C%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%80%BB%E6%98%AF%E7%9C%8B%E5%88%B0%E6%9F%90%E4%B8%AA%E6%88%90%E5%91%98%E5%8F%98%E9%87%8F%E7%9A%84%E5%90%8C%E4%B8%80%E4%B8%AA%E5%80%BC%EF%BC%8C%E8%BF%99%E6%A0%B7%E4%B9%9F%E5%B0%B1%E4%BF%9D%E8%AF%81%E4%BA%86%E5%90%8C%E6%AD%A5%E6%95%B0%E6%8D%AE%E7%9A%84%E5%8F%AF%E8%A7%81%E6%80%A7%E3%80%82%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/58194c29-083b-40ee-a3b8-4a1eba18ab33.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F618%3A1)%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/411ee538-1a11-4cc5-a04d-c547f2f44d03.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F619%3A1)%0A%0A%23%23%23%23%203.3%20synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E5%92%8Cvolatile%E5%85%B3%E9%94%AE%E5%AD%97%E6%AF%94%E8%BE%83%0A*%20volatile%E5%85%B3%E9%94%AE%E5%AD%97%E6%98%AF**%E7%BA%BF%E7%A8%8B%E5%90%8C%E6%AD%A5%E7%9A%84%E8%BD%BB%E9%87%8F%E7%BA%A7%E5%AE%9E%E7%8E%B0**%EF%BC%8C%E6%89%80%E4%BB%A5volatile%E6%80%A7%E8%83%BD%E8%82%AF%E5%AE%9A%E6%AF%94synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E8%A6%81%E5%A5%BD%E3%80%82%E4%BD%86%E6%98%AF**volatile%E5%85%B3%E9%94%AE%E5%AD%97%E5%8F%AA%E8%83%BD%E7%94%A8%E4%BA%8E%E5%8F%98%E9%87%8F**%E8%80%8Csynchronized%E5%85%B3%E9%94%AE%E5%AD%97%E5%8F%AF%E4%BB%A5%E4%BF%AE%E9%A5%B0%E6%96%B9%E6%B3%95%E4%BB%A5%E5%8F%8A%E4%BB%A3%E7%A0%81%E5%9D%97%E3%80%82synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E5%9C%A8JavaSE1.6%E4%B9%8B%E5%90%8E%E8%BF%9B%E8%A1%8C%E4%BA%86%E4%B8%BB%E8%A6%81%E5%8C%85%E6%8B%AC%E4%B8%BA%E4%BA%86%E5%87%8F%E5%B0%91%E8%8E%B7%E5%BE%97%E9%94%81%E5%92%8C%E9%87%8A%E6%94%BE%E9%94%81%E5%B8%A6%E6%9D%A5%E7%9A%84%E6%80%A7%E8%83%BD%E6%B6%88%E8%80%97%E8%80%8C%E5%BC%95%E5%85%A5%E7%9A%84%E5%81%8F%E5%90%91%E9%94%81%E5%92%8C%E8%BD%BB%E9%87%8F%E7%BA%A7%E9%94%81%E4%BB%A5%E5%8F%8A%E5%85%B6%E5%AE%83%E5%90%84%E7%A7%8D%E4%BC%98%E5%8C%96%E4%B9%8B%E5%90%8E%E6%89%A7%E8%A1%8C%E6%95%88%E7%8E%87%E6%9C%89%E4%BA%86%E6%98%BE%E8%91%97%E6%8F%90%E5%8D%87%EF%BC%8C%E5%AE%9E%E9%99%85%E5%BC%80%E5%8F%91%E4%B8%AD%E4%BD%BF%E7%94%A8synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E8%BF%98%E6%98%AF%E6%9B%B4%E5%A4%9A%E4%B8%80%E4%BA%9B%E3%80%82%0A*%20%E5%A4%9A%E7%BA%BF%E7%A8%8B%E8%AE%BF%E9%97%AEvolatile%E5%85%B3%E9%94%AE%E5%AD%97%E4%B8%8D%E4%BC%9A%E5%8F%91%E7%94%9F%E9%98%BB%E5%A1%9E%EF%BC%8C%E8%80%8Csynchronized%E5%85%B3%E9%94%AE%E5%AD%97%E5%8F%AF%E8%83%BD%E4%BC%9A%E5%8F%91%E7%94%9F%E9%98%BB%E5%A1%9E%0A*%20volatile%E5%85%B3%E9%94%AE%E5%AD%97%E8%83%BD%E4%BF%9D%E8%AF%81%E6%95%B0%E6%8D%AE%E7%9A%84%E5%8F%AF%E8%A7%81%E6%80%A7%EF%BC%8C%E4%BD%86%E4%B8%8D%E8%83%BD%E4%BF%9D%E8%AF%81%E6%95%B0%E6%8D%AE%E7%9A%84%E5%8E%9F%E5%AD%90%E6%80%A7%E3%80%82synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E4%B8%A4%E8%80%85%E9%83%BD%E8%83%BD%E4%BF%9D%E8%AF%81%E3%80%82%0A*%20volatile%E5%85%B3%E9%94%AE%E5%AD%97%E7%94%A8%E4%BA%8E%E8%A7%A3%E5%86%B3%E5%8F%98%E9%87%8F%E5%9C%A8%E5%A4%9A%E4%B8%AA%E7%BA%BF%E7%A8%8B%E4%B9%8B%E9%97%B4%E7%9A%84%E5%8F%AF%E8%A7%81%E6%80%A7%EF%BC%8C%E8%80%8Cynchronized%E5%85%B3%E9%94%AE%E5%AD%97%E8%A7%A3%E5%86%B3%E7%9A%84%E6%98%AF%E5%A4%9A%E4%B8%AA%E7%BA%BF%E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9A%84%E5%AE%9E%E7%8E%B0%0A*%20notify()%E6%89%A7%E8%A1%8C%E5%90%8E%E5%B9%B6%E4%B8%8D%E4%BC%9A%E7%AB%8B%E5%8D%B3%E9%87%8A%E6%94%BE%E9%94%81%0A*%20synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E5%8F%AF%E4%BB%A5%E5%B0%86%E4%BB%BB%E4%BD%95%E4%B8%80%E4%B8%AAObject%E5%AF%B9%E8%B1%A1%E4%BD%9C%E4%B8%BA%E5%90%8C%E6%AD%A5%E5%AF%B9%E8%B1%A1%E6%9D%A5%E7%9C%8B%E5%BE%85%EF%BC%8C%E8%80%8CJava%E4%B8%BA%E6%AF%8F%E4%B8%AAObject%E9%83%BD%E5%AE%9E%E7%8E%B0%E4%BA%86%E7%AD%89%E5%BE%85%2F%E9%80%9A%E7%9F%A5%EF%BC%88wait%2Fnotify%EF%BC%89%E6%9C%BA%E5%88%B6%E7%9A%84%E7%9B%B8%E5%85%B3%E6%96%B9%E6%B3%95%EF%BC%8C%E5%AE%83%E4%BB%AC%E5%BF%85%E9%A1%BB%E7%94%A8%E5%9C%A8synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E5%90%8C%E6%AD%A5%E7%9A%84Object%E7%9A%84%E4%B8%B4%E7%95%8C%E5%8C%BA%E5%86%85%E3%80%82%0A*%20%E9%80%9A%E8%BF%87%E8%B0%83%E7%94%A8wait()%E6%96%B9%E6%B3%95%E5%8F%AF%E4%BB%A5%E4%BD%BF%E5%A4%84%E4%BA%8E%E4%B8%B4%E7%95%8C%E5%8C%BA%E5%86%85%E7%9A%84%E7%BA%BF%E7%A8%8B%E8%BF%9B%E5%85%A5%E7%AD%89%E5%BE%85%E7%8A%B6%E6%80%81%EF%BC%8C%E5%90%8C%E6%97%B6%E9%87%8A%E6%94%BE%E8%A2%AB%E5%90%8C%E6%AD%A5%E5%AF%B9%E8%B1%A1%E7%9A%84%E9%94%81%E3%80%82%0A*%20%E8%80%8Cnotify()%E6%96%B9%E6%B3%95%E5%8F%AF%E4%BB%A5%E5%94%A4%E9%86%92%E4%B8%80%E4%B8%AA%E5%9B%A0%E8%B0%83%E7%94%A8wait%E6%93%8D%E4%BD%9C%E8%80%8C%E5%A4%84%E4%BA%8E%E9%98%BB%E5%A1%9E%E7%8A%B6%E6%80%81%E4%B8%AD%E7%9A%84%E7%BA%BF%E7%A8%8B%EF%BC%8C%E4%BD%BF%E5%85%B6%E8%BF%9B%E5%85%A5%E5%B0%B1%E7%BB%AA%E7%8A%B6%E6%80%81%E3%80%82%0A*%20%E8%A2%AB%E9%87%8D%E6%96%B0%E5%94%A4%E9%86%92%E7%9A%84%E7%BA%BF%E7%A8%8B%E4%BC%9A%E8%AF%95%E5%9B%BE%E9%87%8D%E6%96%B0%E8%8E%B7%E5%BE%97%E4%B8%B4%E7%95%8C%E5%8C%BA%E7%9A%84%E6%8E%A7%E5%88%B6%E6%9D%83%E4%B9%9F%E5%B0%B1%E6%98%AF%E9%94%81%EF%BC%8C%E5%B9%B6%E7%BB%A7%E7%BB%AD%E6%89%A7%E8%A1%8Cwait%E6%96%B9%E6%B3%95%E4%B9%8B%E5%90%8E%E7%9A%84%E4%BB%A3%E7%A0%81%E3%80%82%0A%0A%23%23%23%23%204.3%20notify()%E9%94%81%E4%B8%8D%E9%87%8A%E6%94%BE%0A%E5%BD%93%E6%96%B9%E6%B3%95wait()%E8%A2%AB%E6%89%A7%E8%A1%8C%E5%90%8E%EF%BC%8C%E9%94%81%E8%87%AA%E5%8A%A8%E8%A2%AB%E9%87%8A%E6%94%BE%EF%BC%8C%E4%BD%86%E6%89%A7%E8%A1%8C%E5%AE%8Cnotify()%E6%96%B9%E6%B3%95%E5%90%8E%EF%BC%8C%E9%94%81%E4%B8%8D%E4%BC%9A%E8%87%AA%E5%8A%A8%E9%87%8A%E6%94%BE%E3%80%82%E5%BF%85%E9%A1%BB**%E6%89%A7%E8%A1%8C%E5%AE%8Cnotify()%E6%96%B9%E6%B3%95%E6%89%80%E5%9C%A8%E7%9A%84synchronized%E4%BB%A3%E7%A0%81%E5%9D%97%E5%90%8E**%E6%89%8D%E9%87%8A%E6%94%BE%E3%80%82%0A%0A%23%23%20%E4%B8%89.%20%E7%BA%BF%E7%A8%8B%E9%97%B4%E9%80%9A%E4%BF%A1%E7%9F%A5%E8%AF%86%E7%82%B9%E8%A1%A5%E5%85%85%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/bd785765-9ac1-4b0a-a11f-366ae86fbdcf.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F620%3A1)%0A%5B%E7%BA%BF%E7%A8%8B%E9%80%9A%E4%BF%A1%E7%9F%A5%E8%AF%86%E8%A1%A5%E5%85%85%5D(https%3A%2F%2Fblog.csdn.net%2Fqq_34337272%2Farticle%2Fdetails%2F79694226)%0A%23%23%23%201.%20%E7%AE%A1%E9%81%93%E8%BE%93%E5%85%A5%2F%E8%BE%93%E5%87%BA%E6%B5%81%0A*%20%E7%AE%A1%E9%81%93%E8%BE%93%E5%85%A5%2F%E8%BE%93%E5%87%BA%E6%B5%81%E4%B8%BB%E8%A6%81%E7%94%A8%E4%BA%8E%E7%BA%BF%E7%A8%8B%E4%B9%8B%E9%97%B4%E7%9A%84%E6%95%B0%E6%8D%AE%E4%BC%A0%E8%BE%93%EF%BC%8C%E8%80%8C%E4%B8%94%E4%BC%A0%E8%BE%93%E7%9A%84%E5%AA%92%E4%BB%8B%E4%B8%BA%E5%86%85%E5%AD%98%E3%80%82%0A*%20%E7%AE%A1%E9%81%93%E8%BE%93%E5%85%A5%2F%E8%BE%93%E5%87%BA%E6%B5%81%E4%B8%BB%E8%A6%81%E5%8C%85%E6%8B%AC%E4%B8%8B%E5%88%97%E4%B8%A4%E7%B1%BB%E7%9A%84%E5%AE%9E%E7%8E%B0%EF%BC%9A%0A%3E1.%20%E9%9D%A2%E5%90%91%E5%AD%97%E8%8A%82%EF%BC%9A%20PipedOutputStream%E3%80%81%20PipedInputStream%0A%3E2.%20%20%E9%9D%A2%E5%90%91%E5%AD%97%E7%AC%A6%3A%20PipedWriter%E3%80%81%20PipedReader%0A%0A%23%23%23%202.%20Thread.join()%E7%9A%84%E4%BD%BF%E7%94%A8%0A*%20%E5%9C%A8%E5%BE%88%E5%A4%9A%E6%83%85%E5%86%B5%E4%B8%8B%EF%BC%8C%E4%B8%BB%E7%BA%BF%E7%A8%8B%E7%94%9F%E6%88%90%E5%B9%B6%E8%B5%B7%E5%8A%A8%E4%BA%86%E5%AD%90%E7%BA%BF%E7%A8%8B%EF%BC%8C%E5%A6%82%E6%9E%9C%E5%AD%90%E7%BA%BF%E7%A8%8B%E9%87%8C%E8%A6%81%E8%BF%9B%E8%A1%8C%E5%A4%A7%E9%87%8F%E7%9A%84%E8%80%97%E6%97%B6%E7%9A%84%E8%BF%90%E7%AE%97%EF%BC%8C%E4%B8%BB%E7%BA%BF%E7%A8%8B%E5%BE%80%E5%BE%80%E5%B0%86%E4%BA%8E%E5%AD%90%E7%BA%BF%E7%A8%8B%E4%B9%8B%E5%89%8D%E7%BB%93%E6%9D%9F%EF%BC%8C%E4%BD%86%E6%98%AF%E5%A6%82%E6%9E%9C%E4%B8%BB%E7%BA%BF%E7%A8%8B%E5%A4%84%E7%90%86%E5%AE%8C%E5%85%B6%E4%BB%96%E7%9A%84%E4%BA%8B%E5%8A%A1%E5%90%8E%EF%BC%8C%E9%9C%80%E8%A6%81%E7%94%A8%E5%88%B0%E5%AD%90%E7%BA%BF%E7%A8%8B%E7%9A%84%E5%A4%84%E7%90%86%E7%BB%93%E6%9E%9C%EF%BC%8C%E4%B9%9F%E5%B0%B1%E6%98%AF%E4%B8%BB%E7%BA%BF%E7%A8%8B%E9%9C%80%E8%A6%81%E7%AD%89%E5%BE%85%E5%AD%90%E7%BA%BF%E7%A8%8B%E6%89%A7%E8%A1%8C%E5%AE%8C%E6%88%90%E4%B9%8B%E5%90%8E%E5%86%8D%E7%BB%93%E6%9D%9F%EF%BC%8C%E8%BF%99%E4%B8%AA%E6%97%B6%E5%80%99%E5%B0%B1%E8%A6%81%E7%94%A8%E5%88%B0join()%E6%96%B9%E6%B3%95%E4%BA%86%E3%80%82%E5%8F%A6%E5%A4%96%EF%BC%8C%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%E9%9C%80%E8%A6%81%E7%AD%89%E5%BE%85%E5%8F%A6%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%E4%B9%9F%E9%9C%80%E8%A6%81%E7%94%A8%E5%88%B0join()%E6%96%B9%E6%B3%95%E3%80%82%0A*%20Thread%E7%B1%BB%E9%99%A4%E4%BA%86%E6%8F%90%E4%BE%9Bjoin()%E6%96%B9%E6%B3%95%E4%B9%8B%E5%A4%96%EF%BC%8C%E8%BF%98%E6%8F%90%E4%BE%9B%E4%BA%86join(long%20millis)%E3%80%81join(long%20millis%2C%20int%20nanos)%E4%B8%A4%E4%B8%AA%E5%85%B7%E6%9C%89%E8%B6%85%E6%97%B6%E7%89%B9%E6%80%A7%E7%9A%84%E6%96%B9%E6%B3%95%E3%80%82%E8%BF%99%E4%B8%A4%E4%B8%AA%E8%B6%85%E6%97%B6%E6%96%B9%E6%B3%95%E8%A1%A8%E7%A4%BA%EF%BC%8C%E5%A6%82%E6%9E%9C%E7%BA%BF%E7%A8%8Bthread%E5%9C%A8%E6%8C%87%E5%AE%9A%E7%9A%84%E8%B6%85%E6%97%B6%E6%97%B6%E9%97%B4%E6%B2%A1%E6%9C%89%E7%BB%88%E6%AD%A2%EF%BC%8C%E9%82%A3%E4%B9%88%E5%B0%86%E4%BC%9A%E4%BB%8E%E8%AF%A5%E8%B6%85%E6%97%B6%E6%96%B9%E6%B3%95%E4%B8%AD%E8%BF%94%E5%9B%9E%E3%80%82%0A*%20%C2%A0Thread.sleep(2000)%E4%B8%8D%E4%BC%9A%E9%87%8A%E6%94%BE%E9%94%81%EF%BC%8CthreadTest.join(2000)%E4%BC%9A%E9%87%8A%E6%94%BE%E9%94%81%C2%A0%E3%80%82%0A%0A%23%23%23%203.%20%C2%A0ThreadLocal%E7%9A%84%E4%BD%BF%E7%94%A8%0A%23%23%23%23%203.1%20ThreadLocal%E4%BB%8B%E7%BB%8D%0A*%20%E5%8F%98%E9%87%8F%E5%80%BC%E7%9A%84%E5%85%B1%E4%BA%AB%E5%8F%AF%E4%BB%A5%E4%BD%BF%E7%94%A8public%20static%E5%8F%98%E9%87%8F%E7%9A%84%E5%BD%A2%E5%BC%8F%EF%BC%8C%E6%89%80%E6%9C%89%E7%BA%BF%E7%A8%8B%E9%83%BD%E4%BD%BF%E7%94%A8%E4%B8%80%E4%B8%AApublic%20static%E5%8F%98%E9%87%8F%E3%80%82%E5%A6%82%E6%9E%9C%E6%83%B3%E5%AE%9E%E7%8E%B0**%E6%AF%8F%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%E9%83%BD%E6%9C%89%E8%87%AA%E5%B7%B1%E7%9A%84%E5%85%B1%E4%BA%AB%E5%8F%98%E9%87%8F**%E8%AF%A5%E5%A6%82%E4%BD%95%E8%A7%A3%E5%86%B3%E5%91%A2%EF%BC%9F%0A*%20JDK%E4%B8%AD%E6%8F%90%E4%BE%9B%E7%9A%84ThreadLocal%E7%B1%BB%E6%AD%A3%E6%98%AF%E4%B8%BA%E4%BA%86%E8%A7%A3%E5%86%B3%E8%BF%99%E6%A0%B7%E7%9A%84%E9%97%AE%E9%A2%98%E3%80%82ThreadLocal%E7%B1%BB%E4%B8%BB%E8%A6%81%E8%A7%A3%E5%86%B3%E7%9A%84%E5%B0%B1%E6%98%AF%E8%AE%A9**%E6%AF%8F%E4%B8%AA%E7%BA%BF%E7%A8%8B%E7%BB%91%E5%AE%9A%E8%87%AA%E5%B7%B1%E7%9A%84%E5%80%BC**%EF%BC%8C%E5%8F%AF%E4%BB%A5%E5%B0%86ThreadLocal%E7%B1%BB%E5%BD%A2%E8%B1%A1%E7%9A%84%E6%AF%94%E5%96%BB%E6%88%90%E5%AD%98%E6%94%BE%E6%95%B0%E6%8D%AE%E7%9A%84%E7%9B%92%E5%AD%90%EF%BC%8C%E7%9B%92%E5%AD%90%E4%B8%AD%E5%8F%AF%E4%BB%A5%E5%AD%98%E5%82%A8%E6%AF%8F%E4%B8%AA%E7%BA%BF%E7%A8%8B%E7%9A%84%E7%A7%81%E6%9C%89%E6%95%B0%E6%8D%AE%E3%80%82%0A%0A%23%23%23%23%203.2%20ThreadLocal%E6%96%B9%E6%B3%95%0A%0A%7C%20%E6%96%B9%E6%B3%95%E5%90%8D%E7%A7%B0%20%7C%20%E6%8F%8F%E8%BF%B0%20%7C%0A%7C%20---%20%7C%20---%20%7C%0A%7C%20%20get()%7C%E8%BF%94%E5%9B%9E%E5%BD%93%E5%89%8D%E7%BA%BF%E7%A8%8B%E7%9A%84%E6%AD%A4%E7%BA%BF%E7%A8%8B%E5%B1%80%E9%83%A8%E5%8F%98%E9%87%8F%E7%9A%84%E5%89%AF%E6%9C%AC%E4%B8%AD%E7%9A%84%E5%80%BC%E3%80%82%20%20%7C%0A%7Cset(T%20value)%20%20%7C%20%E5%B0%86%E5%BD%93%E5%89%8D%E7%BA%BF%E7%A8%8B%E7%9A%84%E6%AD%A4%E7%BA%BF%E7%A8%8B%E5%B1%80%E9%83%A8%E5%8F%98%E9%87%8F%E7%9A%84%E5%89%AF%E6%9C%AC%E8%AE%BE%E7%BD%AE%E4%B8%BA%E6%8C%87%E5%AE%9A%E7%9A%84%E5%80%BC%20%7C%0A%7C%20remove()%20%7C%20%E5%88%A0%E9%99%A4%E6%AD%A4%E7%BA%BF%E7%A8%8B%E5%B1%80%E9%83%A8%E5%8F%98%E9%87%8F%E7%9A%84%E5%BD%93%E5%89%8D%E7%BA%BF%E7%A8%8B%E7%9A%84%E5%80%BC%20%7C%0A%7C%20initialValue()%20%7C%E8%BF%94%E5%9B%9E%E6%AD%A4%E7%BA%BF%E7%A8%8B%E5%B1%80%E9%83%A8%E5%8F%98%E9%87%8F%E7%9A%84%E5%BD%93%E5%89%8D%E7%BA%BF%E7%A8%8B%E7%9A%84%E2%80%9C%E5%88%9D%E5%A7%8B%E5%80%BC%E2%80%9D%20%20%7C%0A%0A%0A%23%23%23%23%203.3%20%C2%A0InheritableThreadLocal%0A*%20ThreadLocal%E7%B1%BB%E5%9B%BA%E7%84%B6%E5%BE%88%E5%A5%BD%EF%BC%8C%E4%BD%86%E6%98%AF%E5%AD%90%E7%BA%BF%E7%A8%8B%E5%B9%B6%E4%B8%8D%E8%83%BD%E5%8F%96%E5%88%B0%E7%88%B6%E7%BA%BF%E7%A8%8B%E7%9A%84ThreadLocal%E7%B1%BB%E7%9A%84%E5%8F%98%E9%87%8F%EF%BC%8CInheritableThreadLocal%E7%B1%BB%E5%B0%B1%E6%98%AF%E8%A7%A3%E5%86%B3%E8%BF%99%E4%B8%AA%E9%97%AE%E9%A2%98%E7%9A%84%E3%80%82%0A*%20%E5%9C%A8%E4%BD%BF%E7%94%A8InheritableThreadLocal%E7%B1%BB%E9%9C%80%E8%A6%81%E6%B3%A8%E6%84%8F%E7%9A%84%E4%B8%80%E7%82%B9%E6%98%AF%EF%BC%9A%E5%A6%82%E6%9E%9C%E5%AD%90%E7%BA%BF%E7%A8%8B%E5%9C%A8%E5%8F%96%E5%BE%97%E5%80%BC%E7%9A%84%E5%90%8C%E6%97%B6%EF%BC%8C%E4%B8%BB%E7%BA%BF%E7%A8%8B%E5%B0%86InheritableThreadLocal%E4%B8%AD%E7%9A%84%E5%80%BC%E8%BF%9B%E8%A1%8C%E6%9B%B4%E6%94%B9%EF%BC%8C%E9%82%A3%E4%B9%88%E5%AD%90%E7%BA%BF%E7%A8%8B%E5%8F%96%E5%88%B0%E7%9A%84%E8%BF%98%E6%98%AF%E6%97%A7%E5%80%BC%E3%80%82%0A%0A%23%23%20%E5%9B%9B.%20Lock%E9%94%81%E7%9A%84%E4%BD%BF%E7%94%A8%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/7174644d-315f-47ad-be23-1431f3b7a2b4.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F621%3A1)%0A%5Block%E9%94%81%E7%9A%84%E4%BD%BF%E7%94%A8%5D(https%3A%2F%2Fblog.csdn.net%2Fqq_34337272%2Farticle%2Fdetails%2F79714196)%0A%0A%23%23%23%201%20Lock%E6%8E%A5%E5%8F%A3%0A%23%23%23%23%201.1%20Lock%E6%8E%A5%E5%8F%A3%E7%AE%80%E4%BB%8B%0A%3E%E9%94%81%E6%98%AF%E7%94%A8%E4%BA%8E%E9%80%9A%E8%BF%87%E5%A4%9A%E4%B8%AA%E7%BA%BF%E7%A8%8B**%E6%8E%A7%E5%88%B6%E5%AF%B9%E5%85%B1%E4%BA%AB%E8%B5%84%E6%BA%90%E7%9A%84%E8%AE%BF%E9%97%AE**%E7%9A%84%E5%B7%A5%E5%85%B7%E3%80%82%0A%3E%E9%80%9A%E5%B8%B8%EF%BC%8C%E9%94%81%E6%8F%90%E4%BE%9B%E5%AF%B9**%E5%85%B1%E4%BA%AB%E8%B5%84%E6%BA%90%E7%9A%84%E7%8B%AC%E5%8D%A0%E8%AE%BF%E9%97%AE**%EF%BC%9A%E4%B8%80%E6%AC%A1%E5%8F%AA%E8%83%BD%E6%9C%89%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%E5%8F%AF%E4%BB%A5%E8%8E%B7%E5%8F%96%E9%94%81%EF%BC%8C%E5%B9%B6%E4%B8%94%E5%AF%B9%E5%85%B1%E4%BA%AB%E8%B5%84%E6%BA%90%E7%9A%84%E6%89%80%E6%9C%89%E8%AE%BF%E9%97%AE%E9%83%BD%E8%A6%81%E6%B1%82%E9%A6%96%E5%85%88%E8%8E%B7%E5%8F%96%E9%94%81%E3%80%82%0A%3E%20%E4%BD%86%E6%98%AF%EF%BC%8C%E4%B8%80%E4%BA%9B%E9%94%81%E5%8F%AF%E8%83%BD%E5%85%81%E8%AE%B8%E5%B9%B6%E5%8F%91%E8%AE%BF%E9%97%AE%E5%85%B1%E4%BA%AB%E8%B5%84%E6%BA%90%EF%BC%8C%E5%A6%82ReadWriteLock%E7%9A%84%E8%AF%BB%E5%86%99%E9%94%81%E3%80%82%0A%0A*%20%E5%9C%A8Lock%E6%8E%A5%E5%8F%A3%E5%87%BA%E7%8E%B0%E4%B9%8B%E5%89%8D%EF%BC%8CJava%E7%A8%8B%E5%BA%8F%E6%98%AF%E9%9D%A0synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E5%AE%9E%E7%8E%B0%E9%94%81%E5%8A%9F%E8%83%BD%E7%9A%84%E3%80%82JDK1.5%E4%B9%8B%E5%90%8E%E5%B9%B6%E5%8F%91%E5%8C%85%E4%B8%AD%E6%96%B0%E5%A2%9E%E4%BA%86Lock%E6%8E%A5%E5%8F%A3%E4%BB%A5%E5%8F%8A%E7%9B%B8%E5%85%B3%E5%AE%9E%E7%8E%B0%E7%B1%BB%E6%9D%A5%E5%AE%9E%E7%8E%B0%E9%94%81%E5%8A%9F%E8%83%BD%E3%80%82%0A%0A%3ELock%E6%8E%A5%E5%8F%A3%E7%9A%84%E5%AE%9E%E7%8E%B0%E7%B1%BB%EF%BC%9A%C2%A0%0A%3E*%20ReentrantLock%20%0A%3E%20*%20ReentrantReadWriteLock.ReadLock%20%0A%3E%20%20*%20ReentrantReadWriteLock.WriteLock%0A%0A%23%23%23%23%201.2.%20Lock%E7%9A%84%E7%AE%80%E5%8D%95%E4%BD%BF%E7%94%A8%0A%60%60%60java%0A%20Lock%20lock%20%3D%20new%20ReentrantLock()%EF%BC%9B%20%0A%20lock.lock()%3B%20%0A%20try%7B%20%0A%20%7Dfinally%7B%20%0A%20lock.unlock()%3B%20%0A%20%7D%0A%60%60%60%0A*%20%E5%9B%A0%E4%B8%BALock%E6%98%AF%E6%8E%A5%E5%8F%A3%E6%89%80%E4%BB%A5%E4%BD%BF%E7%94%A8%E6%97%B6%E8%A6%81%E7%BB%93%E5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87%E5%AE%9A%E7%9A%84%E6%88%AA%E6%AD%A2%E6%97%B6%E9%97%B4%E4%B9%8B%E5%89%8D%E8%8E%B7%E5%8F%96%E9%94%81%EF%BC%8C%20%E8%B6%85%E8%BF%87%E6%88%AA%E6%AD%A2%E6%97%B6%E9%97%B4%E5%90%8E%E4%BB%8D%E6%97%A7%E6%97%A0%E6%B3%95%E8%8E%B7%E5%8F%96%E5%88%99%E8%BF%94%E5%9B%9E%20%7C%0A%0A*%20Lock%E6%8E%A5%E5%8F%A3%E5%9F%BA%E6%9C%AC%E7%9A%84%E6%96%B9%E6%B3%95%EF%BC%9A%0A%0A%7C%E6%96%B9%E6%B3%95%E5%90%8D%E7%A7%B0%7C%09%E6%8F%8F%E8%BF%B0%7C%0A%7C%20---%20%7C%20---%20%7C%0A%7Cvoid%20lock()%20%20%20%20%20%20%7C%09%E8%8E%B7%E5%BE%97%E9%94%81%E3%80%82%E5%A6%82%E6%9E%9C%E9%94%81%E4%B8%8D%E5%8F%AF%E7%94%A8%EF%BC%8C%E5%88%99%E5%BD%93%E5%89%8D%E7%BA%BF%E7%A8%8B%E5%B0%86%E8%A2%AB%E7%A6%81%E7%94%A8%E4%BB%A5%E8%BF%9B%E8%A1%8C%E7%BA%BF%E7%A8%8B%E8%B0%83%E5%BA%A6%EF%BC%8C%E5%B9%B6%E5%A4%84%E4%BA%8E%E4%BC%91%E7%9C%A0%E7%8A%B6%E6%80%81%EF%BC%8C%E7%9B%B4%E5%88%B0%E8%8E%B7%E5%8F%96%E9%94%81%E3%80%82%7C%0A%7Cvoid%20lockInterruptibly()%7C%09%E8%8E%B7%E5%8F%96%E9%94%81%EF%BC%8C%E5%A6%82%E6%9E%9C%E5%8F%AF%E7%94%A8%E5%B9%B6%E7%AB%8B%E5%8D%B3%E8%BF%94%E5%9B%9E%E3%80%82%E5%A6%82%E6%9E%9C%E9%94%81%E4%B8%8D%E5%8F%AF%E7%94%A8%EF%BC%8C%E9%82%A3%E4%B9%88%E5%BD%93%E5%89%8D%E7%BA%BF%E7%A8%8B%E5%B0%86%E8%A2%AB%E7%A6%81%E7%94%A8%E4%BB%A5%E8%BF%9B%E8%A1%8C%E7%BA%BF%E7%A8%8B%E8%B0%83%E5%BA%A6%EF%BC%8C%E5%B9%B6%E4%B8%94%E5%A4%84%E4%BA%8E%E4%BC%91%E7%9C%A0%E7%8A%B6%E6%80%81%EF%BC%8C%E5%92%8Clock()%E6%96%B9%E6%B3%95%E4%B8%8D%E5%90%8C%E7%9A%84%E6%98%AF%E5%9C%A8%E9%94%81%E7%9A%84%E8%8E%B7%E5%8F%96%E4%B8%AD%E5%8F%AF%E4%BB%A5%E4%B8%AD%E6%96%AD%E5%BD%93%E5%89%8D%E7%BA%BF%E7%A8%8B%EF%BC%88%E7%9B%B8%E5%BA%94%E4%B8%AD%E6%96%AD%EF%BC%89%E3%80%82%7C%0A%7CCondition%20newCondition()%09%7C%E8%8E%B7%E5%8F%96%E7%AD%89%E5%BE%85%E9%80%9A%E7%9F%A5%E7%BB%84%E4%BB%B6%EF%BC%8C%E8%AF%A5%E7%BB%84%E4%BB%B6%E5%92%8C%E5%BD%93%E5%89%8D%E7%9A%84%E9%94%81%E7%BB%91%E5%AE%9A%EF%BC%8C%E5%BD%93%E5%89%8D%E7%BA%BF%E7%A8%8B%E5%8F%AA%E6%9C%89%E8%8E%B7%E5%BE%97%E4%BA%86%E9%94%81%EF%BC%8C%E6%89%8D%E8%83%BD%E8%B0%83%E7%94%A8%E8%AF%A5%E7%BB%84%E4%BB%B6%E7%9A%84wait()%E6%96%B9%E6%B3%95%EF%BC%8C%E8%80%8C%E8%B0%83%E7%94%A8%E5%90%8E%EF%BC%8C%E5%BD%93%E5%89%8D%E7%BA%BF%E7%A8%8B%E5%B0%86%E9%87%8A%E6%94%BE%E9%94%81%E3%80%82%7C%0A%7Cboolean%20tryLock()%09%7C%E5%8F%AA%E6%9C%89%E5%9C%A8%E8%B0%83%E7%94%A8%E6%97%B6%E6%89%8D%E5%8F%AF%E4%BB%A5%E8%8E%B7%E5%BE%97%E9%94%81%E3%80%82%E5%A6%82%E6%9E%9C%E5%8F%AF%E7%94%A8%EF%BC%8C%E5%88%99%E8%8E%B7%E5%8F%96%E9%94%81%E5%AE%9A%EF%BC%8C%E5%B9%B6%E7%AB%8B%E5%8D%B3%E8%BF%94%E5%9B%9E%E5%80%BC%E4%B8%BAtrue%EF%BC%9B%E5%A6%82%E6%9E%9C%E9%94%81%E4%B8%8D%E5%8F%AF%E7%94%A8%EF%BC%8C%E5%88%99%E6%AD%A4%E6%96%B9%E6%B3%95%E5%B0%86%E7%AB%8B%E5%8D%B3%E8%BF%94%E5%9B%9E%E5%80%BC%E4%B8%BAfalse%20%E3%80%82%7C%0A%7Cboolean%20tryLock(long%20time%2C%20TimeUnit%20unit)%09%7C%E8%B6%85%E6%97%B6%E8%8E%B7%E5%8F%96%E9%94%81%EF%BC%8C%E5%BD%93%E5%89%8D%E7%BA%BF%E7%A8%8B%E5%9C%A8%E4%B8%80%E4%B8%8B%E4%B8%89%E7%A7%8D%E6%83%85%E5%86%B5%E4%B8%8B%E4%BC%9A%E8%BF%94%E5%9B%9E%EF%BC%9A%201.%20%E5%BD%93%E5%89%8D%E7%BA%BF%E7%A8%8B%E5%9C%A8%E8%B6%85%E6%97%B6%E6%97%B6%E9%97%B4%E5%86%85%E8%8E%B7%E5%BE%97%E4%BA%86%E9%94%81%EF%BC%9B2.%E5%BD%93%E5%89%8D%E7%BA%BF%E7%A8%8B%E5%9C%A8%E8%B6%85%E6%97%B6%E6%97%B6%E9%97%B4%E5%86%85%E8%A2%AB%E4%B8%AD%E6%96%AD%EF%BC%9B3.%E8%B6%85%E6%97%B6%E6%97%B6%E9%97%B4%E7%BB%93%E6%9D%9F%EF%BC%8C%E8%BF%94%E5%9B%9Efalse.%7C%0A%7Cvoid%20unlock()%09%7C%E9%87%8A%E6%94%BE%E9%94%81%E3%80%82%7C%0A%0A%23%23%23%202.%20Lock%E6%8E%A5%E5%8F%A3%E7%9A%84%E5%AE%9E%E7%8E%B0%E7%B1%BB%EF%BC%9AReentrantLock%0A*%20ReentrantLock%E5%92%8Csynchronized%E5%85%B3%E9%94%AE%E5%AD%97%E4%B8%80%E6%A0%B7%E5%8F%AF%E4%BB%A5%E7%94%A8%E6%9D%A5%E5%AE%9E%E7%8E%B0%E7%BA%BF%E7%A8%8B%E4%B9%8B%E9%97%B4%E7%9A%84%E5%90%8C%E6%AD%A5%E4%BA%92%E6%96%A5%EF%BC%8C%E4%BD%86%E6%98%AF%E5%9C%A8%E5%8A%9F%E8%83%BD%E6%98%AF%E6%AF%94synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E6%9B%B4%E5%BC%BA%E5%A4%A7%E8%80%8C%E4%B8%94%E6%9B%B4%E7%81%B5%E6%B4%BB%E3%80%82%0A%23%23%23%23%202.1%20ReentrantLock%E7%B1%BB%E5%B8%B8%E8%A7%81%E6%96%B9%E6%B3%95%0A%3E%20*%20%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95%EF%BC%9A%0A%0A%7C%E6%96%B9%E6%B3%95%E5%90%8D%E7%A7%B0%7C%E6%8F%8F%E8%BF%B0%7C%0A%7C%20---%20%7C%20---%20%7C%0A%7CReentrantLock()%7C%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%20ReentrantLock%E7%9A%84%E5%AE%9E%E4%BE%8B%E3%80%82%7C%0A%7CReentrantLock(boolean%20fair)%7C%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E7%89%B9%E5%AE%9A%E9%94%81%E7%B1%BB%E5%9E%8B%EF%BC%88%E5%85%AC%E5%B9%B3%E9%94%81%2F%E9%9D%9E%E5%85%AC%E5%B9%B3%E9%94%81%EF%BC%89%E7%9A%84ReentrantLock%E7%9A%84%E5%AE%9E%E4%BE%8B%7C%0A%0A%3E*%20ReentrantLock%E7%B1%BB%E5%B8%B8%E8%A7%81%E6%96%B9%E6%B3%95(Lock%E6%8E%A5%E5%8F%A3%E5%B7%B2%E6%9C%89%E6%96%B9%E6%B3%95%E8%BF%99%E9%87%8C%E6%B2%A1%E5%8A%A0%E4%B8%8A)%EF%BC%9A%0A%0A%7C%E6%96%B9%E6%B3%95%E5%90%8D%E7%A7%B0%09%7C%E6%8F%8F%E8%BF%B0%7C%0A%7C%20---%20%7C%20---%20%7C%0A%7Cint%20getHoldCount()%09%7C%E6%9F%A5%E8%AF%A2%E5%BD%93%E5%89%8D%E7%BA%BF%E7%A8%8B%E4%BF%9D%E6%8C%81%E6%AD%A4%E9%94%81%E5%AE%9A%E7%9A%84%E4%B8%AA%E6%95%B0%EF%BC%8C%E4%B9%9F%E5%B0%B1%E6%98%AF%E8%B0%83%E7%94%A8lock()%E6%96%B9%E6%B3%95%E7%9A%84%E6%AC%A1%E6%95%B0%E3%80%82%7C%0A%7Cprotected%20Thread%20getOwner()%09%7C%E8%BF%94%E5%9B%9E%E5%BD%93%E5%89%8D%E6%8B%A5%E6%9C%89%E6%AD%A4%E9%94%81%E7%9A%84%E7%BA%BF%E7%A8%8B%EF%BC%8C%E5%A6%82%E6%9E%9C%E4%B8%8D%E6%8B%A5%E6%9C%89%EF%BC%8C%E5%88%99%E8%BF%94%E5%9B%9E%20null%7C%0A%7Cprotected%20Collection%20getQueuedThreads()%09%7C%E8%BF%94%E5%9B%9E%E5%8C%85%E5%90%AB%E5%8F%AF%E8%83%BD%E6%AD%A3%E5%9C%A8%E7%AD%89%E5%BE%85%E8%8E%B7%E5%8F%96%E6%AD%A4%E9%94%81%E7%9A%84%E7%BA%BF%E7%A8%8B%E7%9A%84%E9%9B%86%E5%90%88%7C%0A%7Cint%20getQueueLength()%09%7C%E8%BF%94%E5%9B%9E%E7%AD%89%E5%BE%85%E8%8E%B7%E5%8F%96%E6%AD%A4%E9%94%81%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%95%B0%E7%9A%84%E4%BC%B0%E8%AE%A1%E3%80%82%7C%0A%7Cprotected%20Collection%20getWaitingThreads(Condition%20condition)%09%7C%E8%BF%94%E5%9B%9E%E5%8C%85%E5%90%AB%E5%8F%AF%E8%83%BD%E5%9C%A8%E4%B8%8E%E6%AD%A4%E9%94%81%E7%9B%B8%E5%85%B3%E8%81%94%E7%9A%84%E7%BB%99%E5%AE%9A%E6%9D%A1%E4%BB%B6%E4%B8%8B%E7%AD%89%E5%BE%85%E7%9A%84%E7%BA%BF%E7%A8%8B%E7%9A%84%E9%9B%86%E5%90%88%E3%80%82%7C%0A%7Cint%20getWaitQueueLength(Condition%20condition)%7C%09%E8%BF%94%E5%9B%9E%E4%B8%8E%E6%AD%A4%E9%94%81%E7%9B%B8%E5%85%B3%E8%81%94%E7%9A%84%E7%BB%99%E5%AE%9A%E6%9D%A1%E4%BB%B6%E7%AD%89%E5%BE%85%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%95%B0%E7%9A%84%E4%BC%B0%E8%AE%A1%E3%80%82%7C%0A%7Cboolean%20hasQueuedThread(Thread%20thread)%7C%09%E6%9F%A5%E8%AF%A2%E7%BB%99%E5%AE%9A%E7%BA%BF%E7%A8%8B%E6%98%AF%E5%90%A6%E7%AD%89%E5%BE%85%E8%8E%B7%E5%8F%96%E6%AD%A4%E9%94%81%E3%80%82%7C%0A%7Cboolean%20hasQueuedThreads()%7C%09%E6%9F%A5%E8%AF%A2%E6%98%AF%E5%90%A6%E6%9C%89%E7%BA%BF%E7%A8%8B%E6%AD%A3%E5%9C%A8%E7%AD%89%E5%BE%85%E8%8E%B7%E5%8F%96%E6%AD%A4%E9%94%81%E3%80%82%7C%0A%7Cboolean%20hasWaiters(Condition%20condition)%7C%09%E6%9F%A5%E8%AF%A2%E4%BB%BB%E4%BD%95%E7%BA%BF%E7%A8%8B%E6%98%AF%E5%90%A6%E7%AD%89%E5%BE%85%E4%B8%8E%E6%AD%A4%E9%94%81%E7%9B%B8%E5%85%B3%E8%81%94%E7%9A%84%E7%BB%99%E5%AE%9A%E6%9D%A1%E4%BB%B6%7C%0A%7Cboolean%20isFair()%09%7C%E5%A6%82%E6%9E%9C%E6%AD%A4%E9%94%81%E7%9A%84%E5%85%AC%E5%B9%B3%E8%AE%BE%E7%BD%AE%E4%B8%BAtrue%EF%BC%8C%E5%88%99%E8%BF%94%E5%9B%9E%20true%20%E3%80%82%7C%0A%7Cboolean%20isHeldByCurrentThread()%7C%09%E6%9F%A5%E8%AF%A2%E6%AD%A4%E9%94%81%E6%98%AF%E5%90%A6%E7%94%B1%E5%BD%93%E5%89%8D%E7%BA%BF%E7%A8%8B%E6%8C%81%E6%9C%89%E3%80%82%7C%0A%7Cboolean%20isLocked()%7C%E6%9F%A5%E8%AF%A2%E6%AD%A4%E9%94%81%E6%98%AF%E5%90%A6%E7%94%B1%E4%BB%BB%E4%BD%95%E7%BA%BF%E7%A8%8B%E6%8C%81%E6%9C%89%E3%80%82%7C%0A%0A%23%23%23%23%202.2%20%E7%AC%AC%E4%B8%80%E4%B8%AAReentrantLock%E7%A8%8B%E5%BA%8F%0A*%20%E5%BD%93%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%E8%BF%90%E8%A1%8C%E5%AE%8C%E6%AF%95%E5%90%8E%E6%89%8D%E6%8A%8A%E9%94%81%E9%87%8A%E6%94%BE%EF%BC%8C%E5%85%B6%E4%BB%96%E7%BA%BF%E7%A8%8B%E6%89%8D%E8%83%BD%E6%89%A7%E8%A1%8C%EF%BC%8C%E5%85%B6%E4%BB%96%E7%BA%BF%E7%A8%8B%E7%9A%84%E6%89%A7%E8%A1%8C%E9%A1%BA%E5%BA%8F%E6%98%AF%E4%B8%8D%E7%A1%AE%E5%AE%9A%E7%9A%84%E3%80%82%0A%0A%23%23%23%203.%20Condition%E6%8E%A5%E5%8F%A3%E7%AE%80%E4%BB%8B%0A*%20synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E4%B8%8Ewait()%E5%92%8Cnotify%2FnotifyAll()%E6%96%B9%E6%B3%95%E7%9B%B8%E7%BB%93%E5%90%88%E5%8F%AF%E4%BB%A5%E5%AE%9E%E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%A5%EF%BC%8C%E5%9C%A8%E8%B0%83%E5%BA%A6%E7%BA%BF%E7%A8%8B%E4%B8%8A%E6%9B%B4%E5%8A%A0%E7%81%B5%E6%B4%BB%E3%80%82%0A*%20%E5%9C%A8%E4%BD%BF%E7%94%A8notify%2FnotifyAll()%E6%96%B9%E6%B3%95%E8%BF%9B%E8%A1%8C%E9%80%9A%E7%9F%A5%E6%97%B6%EF%BC%8C%E8%A2%AB%E9%80%9A%E7%9F%A5%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%98%AF%E6%9C%89JVM%E9%80%89%E6%8B%A9%E7%9A%84%EF%BC%8C%E4%BD%BF%E7%94%A8ReentrantLock%E7%B1%BB%E7%BB%93%E5%90%88Condition%E5%AE%9E%E4%BE%8B%E5%8F%AF%E4%BB%A5%E5%AE%9E%E7%8E%B0%E2%80%9C**%E9%80%89%E6%8B%A9%E6%80%A7%E9%80%9A%E7%9F%A5**%E2%80%9D%EF%BC%8C%E8%BF%99%E4%B8%AA%E5%8A%9F%E8%83%BD%E9%9D%9E%E5%B8%B8%E9%87%8D%E8%A6%81%EF%BC%8C%E8%80%8C%E4%B8%94%E6%98%AFCondition%E6%8E%A5%E5%8F%A3%E9%BB%98%E8%AE%A4%E6%8F%90%E4%BE%9B%E7%9A%84%E3%80%82%0A%0A%3E%20*%20Condition%E6%8E%A5%E5%8F%A3%E7%9A%84%E5%B8%B8%E8%A7%81%E6%96%B9%E6%B3%95%EF%BC%9A%0A%0A%7C%E6%96%B9%E6%B3%95%E5%90%8D%E7%A7%B0%7C%09%E6%8F%8F%E8%BF%B0%7C%0A%7C%20---%20%7C%20---%20%7C%0A%7Cvoid%20await()%7C%09%E7%9B%B8%E5%BD%93%E4%BA%8EObject%E7%B1%BB%E7%9A%84wait%E6%96%B9%E6%B3%95%7C%0A%7Cboolean%20await(long%20time%2C%20TimeUnit%20unit)%09%7C%E7%9B%B8%E5%BD%93%E4%BA%8EObject%E7%B1%BB%E7%9A%84wait(long%20timeout)%E6%96%B9%E6%B3%95%7C%0A%7Csignal()%7C%09%E7%9B%B8%E5%BD%93%E4%BA%8EObject%E7%B1%BB%E7%9A%84notify%E6%96%B9%E6%B3%95%7C%0A%7CsignalAll()%7C%09%E7%9B%B8%E5%BD%93%E4%BA%8EObject%E7%B1%BB%E7%9A%84notifyAll%E6%96%B9%E6%B3%95%7C%0A%0A*%20synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E5%B0%B1%E7%9B%B8%E5%BD%93%E4%BA%8E%E6%95%B4%E4%B8%AALock%E5%AF%B9%E8%B1%A1%E4%B8%AD%E5%8F%AA%E6%9C%89%E4%B8%80%E4%B8%AACondition%E5%AE%9E%E4%BE%8B%EF%BC%8C%E6%89%80%E6%9C%89%E7%9A%84%E7%BA%BF%E7%A8%8B%E9%83%BD%E6%B3%A8%E5%86%8C%E5%9C%A8%E5%AE%83%E4%B8%80%E4%B8%AA%E8%BA%AB%E4%B8%8A%E3%80%82%E5%A6%82%E6%9E%9C%E6%89%A7%E8%A1%8CnotifyAll()%E6%96%B9%E6%B3%95%E7%9A%84%E8%AF%9D%E5%B0%B1%E4%BC%9A%E9%80%9A%E7%9F%A5%E6%89%80%E6%9C%89%E5%A4%84%E4%BA%8E%E7%AD%89%E5%BE%85%E7%8A%B6%E6%80%81%E7%9A%84%E7%BA%BF%E7%A8%8B%E8%BF%99%E6%A0%B7%E4%BC%9A%E9%80%A0%E6%88%90%E5%BE%88%E5%A4%A7%E7%9A%84%E6%95%88%E7%8E%87%E9%97%AE%E9%A2%98%EF%BC%8C%E8%80%8CCondition%E5%AE%9E%E4%BE%8B%E7%9A%84signalAll()%E6%96%B9%E6%B3%95%20%E5%8F%AA%E4%BC%9A%E5%94%A4%E9%86%92%E6%B3%A8%E5%86%8C%E5%9C%A8%E8%AF%A5Condition%E5%AE%9E%E4%BE%8B%E4%B8%AD%E7%9A%84%E6%89%80%E6%9C%89%E7%AD%89%E5%BE%85%E7%BA%BF%E7%A8%8B%0A%0A%23%23%23%23%203.1%20%E4%BD%BF%E7%94%A8Condition%E5%AE%9E%E7%8E%B0%E7%AD%89%E5%BE%85%2F%E9%80%9A%E7%9F%A5%E6%9C%BA%E5%88%B6%0A1.%20%20%E4%BD%BF%E7%94%A8%E5%8D%95%E4%B8%AACondition%E5%AE%9E%E4%BE%8B%E5%AE%9E%E7%8E%B0%E7%AD%89%E5%BE%85%2F%E9%80%9A%E7%9F%A5%E6%9C%BA%E5%88%B6%EF%BC%9A%0A%3E*%20%E5%BF%85%E9%A1%BB%E6%89%A7%E8%A1%8C%E5%AE%8Csignal%E6%89%80%E5%9C%A8%E7%9A%84try%E8%AF%AD%E5%8F%A5%E5%9D%97%E4%B9%8B%E5%90%8E%E6%89%8D%E9%87%8A%E6%94%BE%E9%94%81%EF%BC%8Ccondition.await()%E5%90%8E%E7%9A%84%E8%AF%AD%E5%8F%A5%E6%89%8D%E8%83%BD%E8%A2%AB%E6%89%A7%E8%A1%8C%E3%80%82%0A%3E*%20%E6%B3%A8%E6%84%8F%EF%BC%9A%C2%A0%E5%BF%85%E9%A1%BB%E5%9C%A8condition.await()%E6%96%B9%E6%B3%95%E8%B0%83%E7%94%A8%E4%B9%8B%E5%89%8D%E8%B0%83%E7%94%A8lock.lock()%E4%BB%A3%E7%A0%81%E8%8E%B7%E5%BE%97%E5%90%8C%E6%AD%A5%E7%9B%91%E8%A7%86%E5%99%A8%EF%BC%8C%E4%B8%8D%E7%84%B6%E4%BC%9A%E6%8A%A5%E9%94%99%E3%80%82%0A%0A2.%20%E4%BD%BF%E7%94%A8%E5%A4%9A%E4%B8%AACondition%E5%AE%9E%E4%BE%8B%E5%AE%9E%E7%8E%B0%E7%AD%89%E5%BE%85%2F%E9%80%9A%E7%9F%A5%E6%9C%BA%E5%88%B6%EF%BC%9A%0A%3E*%20%E5%AE%9E%E7%8E%B0%E2%80%9C%E9%80%89%E6%8B%A9%E6%80%A7%E9%80%9A%E7%9F%A5%E2%80%9D%2C%E5%8F%AA%E4%BC%9A%E5%94%A4%E9%86%92%E6%B3%A8%E5%86%8C%E5%9C%A8%E6%8C%87%E5%AE%9ACondition%E5%AE%9E%E4%BE%8B%E4%B8%AD%E7%9A%84%E6%89%80%E6%9C%89%E7%AD%89%E5%BE%85%E7%BA%BF%E7%A8%8B%0A%0A3.%20%E4%BD%BF%E7%94%A8Condition%E5%AE%9E%E7%8E%B0%E9%A1%BA%E5%BA%8F%E6%89%A7%E8%A1%8C%0A%3E*%20%E5%9C%A8%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%E8%BF%90%E8%A1%8C%E5%AE%8C%E4%B9%8B%E5%90%8E%E9%80%9A%E8%BF%87condition.signal()%2Fcondition.signalAll()%E6%96%B9%E6%B3%95%E9%80%9A%E7%9F%A5%E4%B8%8B%E4%B8%80%E4%B8%AA%E7%89%B9%E5%AE%9A%E7%9A%84%E7%BA%BF%E7%A8%8B%E8%BF%90%E8%A1%8C%EF%BC%8C%E5%B0%B1%E8%BF%99%E6%A0%B7%E5%BE%AA%E7%8E%AF%E5%BE%80%E5%A4%8D%E5%8D%B3%E5%8F%AF%E3%80%82%20%0A%3E*%20%E6%B3%A8%E6%84%8F%EF%BC%9A%C2%A0%E9%BB%98%E8%AE%A4%E6%83%85%E5%86%B5%E4%B8%8BReentranLock%E7%B1%BB%E4%BD%BF%E7%94%A8%E7%9A%84%E6%98%AF%E9%9D%9E%E5%85%AC%E5%B9%B3%E9%94%81%0A%0A%23%23%23%204.%20%E5%85%AC%E5%B9%B3%E9%94%81%E4%B8%8E%E9%9D%9E%E5%85%AC%E5%B9%B3%E9%94%81%0A*%20Lock%E9%94%81%E5%88%86%E4%B8%BA%EF%BC%9A%E5%85%AC%E5%B9%B3%E9%94%81%C2%A0%E5%92%8C%C2%A0%E9%9D%9E%E5%85%AC%E5%B9%B3%E9%94%81%E3%80%82%0A%3E*%20%E5%85%AC%E5%B9%B3%E9%94%81%E8%A1%A8%E7%A4%BA%E7%BA%BF%E7%A8%8B%E8%8E%B7%E5%8F%96%E9%94%81%E7%9A%84%E9%A1%BA%E5%BA%8F%E6%98%AF%E6%8C%89%E7%85%A7%E7%BA%BF%E7%A8%8B%E5%8A%A0%E9%94%81%E7%9A%84%E9%A1%BA%E5%BA%8F%E6%9D%A5%E5%88%86%E9%85%8D%E7%9A%84%EF%BC%8C%E5%8D%B3%E5%85%88%E6%9D%A5%E5%85%88%E5%BE%97%E7%9A%84FIFO%E5%85%88%E8%BF%9B%E5%85%88%E5%87%BA%E9%A1%BA%E5%BA%8F%E3%80%82%0A%3E*%20%E8%80%8C%E9%9D%9E%E5%85%AC%E5%B9%B3%E9%94%81%E5%B0%B1%E6%98%AF%E4%B8%80%E7%A7%8D%E8%8E%B7%E5%8F%96%E9%94%81%E7%9A%84%E6%8A%A2%E5%8D%A0%E6%9C%BA%E5%88%B6%EF%BC%8C%E6%98%AF%E9%9A%8F%E6%9C%BA%E8%8E%B7%E5%8F%96%E9%94%81%E7%9A%84%EF%BC%8C%E5%92%8C%E5%85%AC%E5%B9%B3%E9%94%81%E4%B8%8D%E4%B8%80%E6%A0%B7%E7%9A%84%E5%B0%B1%E6%98%AF%E5%85%88%E6%9D%A5%E7%9A%84%E4%B8%8D%E4%B8%80%E5%AE%9A%E5%85%88%E7%9A%84%E5%88%B0%E9%94%81%EF%BC%8C%E8%BF%99%E6%A0%B7%E5%8F%AF%E8%83%BD%E9%80%A0%E6%88%90%E6%9F%90%E4%BA%9B%E7%BA%BF%E7%A8%8B%E4%B8%80%E7%9B%B4%E6%8B%BF%E4%B8%8D%E5%88%B0%E9%94%81%EF%BC%8C%E7%BB%93%E6%9E%9C%E4%B9%9F%E5%B0%B1%E6%98%AF%E4%B8%8D%E5%85%AC%E5%B9%B3%E7%9A%84%E4%BA%86%E3%80%82%0A%0A%23%23%23%205.%20ReadWriteLock%E6%8E%A5%E5%8F%A3%E7%9A%84%E5%AE%9E%E7%8E%B0%E7%B1%BB%EF%BC%9AReentrantReadWriteLock%0A%0A%23%23%23%23%205.1%20%E7%AE%80%E4%BB%8B%0A%3E*%20ReentrantLock%EF%BC%88%E6%8E%92%E4%BB%96%E9%94%81%EF%BC%89%E5%85%B7%E6%9C%89%E5%AE%8C%E5%85%A8%E4%BA%92%E6%96%A5%E6%8E%92%E4%BB%96%E7%9A%84%E6%95%88%E6%9E%9C%EF%BC%8C%E5%8D%B3%E5%90%8C%E4%B8%80%E6%97%B6%E5%88%BB%E5%8F%AA%E5%85%81%E8%AE%B8%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%E8%AE%BF%E9%97%AE%EF%BC%8C%E8%BF%99%E6%A0%B7%E5%81%9A%E8%99%BD%E7%84%B6%E8%99%BD%E7%84%B6%E4%BF%9D%E8%AF%81%E4%BA%86%E5%AE%9E%E4%BE%8B%E5%8F%98%E9%87%8F%E7%9A%84%E7%BA%BF%E7%A8%8B%E5%AE%89%E5%85%A8%E6%80%A7%EF%BC%8C%E4%BD%86%E6%95%88%E7%8E%87%E9%9D%9E%E5%B8%B8%E4%BD%8E%E4%B8%8B%E3%80%82%0A%3EReadWriteLock%E6%8E%A5%E5%8F%A3%E7%9A%84%E5%AE%9E%E7%8E%B0%E7%B1%BB-ReentrantReadWriteLock%E8%AF%BB%E5%86%99%E9%94%81%E5%B0%B1%E6%98%AF%E4%B8%BA%E4%BA%86%E8%A7%A3%E5%86%B3%E8%BF%99%E4%B8%AA%E9%97%AE%E9%A2%98%E3%80%82%0A%0A%3E*%20%E8%AF%BB%E5%86%99%E9%94%81%E7%BB%B4%E6%8A%A4%E4%BA%86%E4%B8%A4%E4%B8%AA%E9%94%81%EF%BC%8C%E4%B8%80%E4%B8%AA%E6%98%AF**%E8%AF%BB%E6%93%8D%E4%BD%9C**%E7%9B%B8%E5%85%B3%E7%9A%84%E9%94%81%E4%B9%9F%E6%88%90%E4%B8%BA**%E5%85%B1%E4%BA%AB%E9%94%81**%EF%BC%8C%0A%3E%E4%B8%80%E4%B8%AA%E6%98%AF**%E5%86%99%E6%93%8D%E4%BD%9C**%E7%9B%B8%E5%85%B3%E7%9A%84%E9%94%81%E4%B9%9F%E7%A7%B0%E4%B8%BA**%E6%8E%92%E4%BB%96%E9%94%81**%E3%80%82%0A%3E%E9%80%9A%E8%BF%87%E5%88%86%E7%A6%BB%E8%AF%BB%E9%94%81%E5%92%8C%E5%86%99%E9%94%81%EF%BC%8C%E5%85%B6%E5%B9%B6%E5%8F%91%E6%80%A7%E6%AF%94%E4%B8%80%E8%88%AC%E6%8E%92%E4%BB%96%E9%94%81%E6%9C%89%E4%BA%86%E5%BE%88%E5%A4%A7%E6%8F%90%E5%8D%87%E3%80%82%0A%0A%3E*%20%E5%A4%9A%E4%B8%AA%E8%AF%BB%E9%94%81%E4%B9%8B%E9%97%B4%E4%B8%8D%E4%BA%92%E6%96%A5%EF%BC%8C%E8%AF%BB%E9%94%81%E4%B8%8E%E5%86%99%E9%94%81%E4%BA%92%E6%96%A5%EF%BC%8C%E5%86%99%E9%94%81%E4%B8%8E%E5%86%99%E9%94%81%E4%BA%92%E6%96%A5%EF%BC%88%E5%8F%AA%E8%A6%81%E5%87%BA%E7%8E%B0%E5%86%99%E6%93%8D%E4%BD%9C%E7%9A%84%E8%BF%87%E7%A8%8B%E5%B0%B1%E6%98%AF%E4%BA%92%E6%96%A5%E7%9A%84%EF%BC%89%0A%3E%E5%9C%A8%E6%B2%A1%E6%9C%89%E7%BA%BF%E7%A8%8BThread%E8%BF%9B%E8%A1%8C%E5%86%99%E5%85%A5%E6%93%8D%E4%BD%9C%E6%97%B6%EF%BC%8C%E8%BF%9B%E8%A1%8C%E8%AF%BB%E5%8F%96%E6%93%8D%E4%BD%9C%E7%9A%84%E5%A4%9A%E4%B8%AAThread%E9%83%BD%E5%8F%AF%E4%BB%A5%E8%8E%B7%E5%8F%96%E8%AF%BB%E9%94%81%EF%BC%8C%0A%3E%E8%80%8C%E8%BF%9B%E8%A1%8C%E5%86%99%E5%85%A5%E6%93%8D%E4%BD%9C%E7%9A%84Thread%E5%8F%AA%E6%9C%89%E5%9C%A8%E8%8E%B7%E5%8F%96%E5%86%99%E9%94%81%E5%90%8E%E6%89%8D%E8%83%BD%E8%BF%9B%E8%A1%8C%E5%86%99%E5%85%A5%E6%93%8D%E4%BD%9C%E3%80%82%0A%3E%E5%8D%B3%E5%A4%9A%E4%B8%AAThread%E5%8F%AF%E4%BB%A5**%E5%90%8C%E6%97%B6%E8%BF%9B%E8%A1%8C%E8%AF%BB%E5%8F%96%E6%93%8D%E4%BD%9C**%2C%E4%BD%86%E6%98%AF%E5%90%8C%E4%B8%80%E6%97%B6%E5%88%BB**%E5%8F%AA%E5%85%81%E8%AE%B8%E4%B8%80%E4%B8%AAThread%E8%BF%9B%E8%A1%8C%E5%86%99%E5%85%A5%E6%93%8D%E4%BD%9C**%E3%80%82%0A%0A%23%23%23%23%205.2%20ReentrantReadWriteLock%E7%9A%84%E7%89%B9%E6%80%A7%E4%B8%8E%E5%B8%B8%E8%A7%81%E6%96%B9%E6%B3%95%0A%0A%3E*%20ReentrantReadWriteLock%E7%9A%84%E7%89%B9%E6%80%A7%EF%BC%9A%0A%0A%7C%E7%89%B9%E6%80%A7%7C%E8%AF%B4%E6%98%8E%7C%0A%7C%20---%20%7C%20---%20%7C%0A%E5%85%AC%E5%B9%B3%E6%80%A7%E9%80%89%E6%8B%A9%7C%09%E6%94%AF%E6%8C%81%E9%9D%9E%E5%85%AC%E5%B9%B3%EF%BC%88%E9%BB%98%E8%AE%A4%EF%BC%89%E5%92%8C%E5%85%AC%E5%B9%B3%E7%9A%84%E9%94%81%E8%8E%B7%E5%8F%96%E6%96%B9%E5%BC%8F%EF%BC%8C%E5%90%9E%E5%90%90%E9%87%8F%E4%B8%8A%E6%9D%A5%E7%9C%8B%E8%BF%98%E6%98%AF%E9%9D%9E%E5%85%AC%E5%B9%B3%E4%BC%98%E4%BA%8E%E5%85%AC%E5%B9%B3%0A%E9%87%8D%E8%BF%9B%E5%85%A5%7C%09%E8%AF%A5%E9%94%81%E6%94%AF%E6%8C%81%E9%87%8D%E8%BF%9B%E5%85%A5%EF%BC%8C%E4%BB%A5%E8%AF%BB%E5%86%99%E7%BA%BF%E7%A8%8B%E4%B8%BA%E4%BE%8B%EF%BC%9A%E8%AF%BB%E7%BA%BF%E7%A8%8B%E5%9C%A8%E8%8E%B7%E5%8F%96%E4%BA%86%E8%AF%BB%E9%94%81%E4%B9%8B%E5%90%8E%EF%BC%8C%E8%83%BD%E5%A4%9F%E5%86%8D%E6%AC%A1%E8%8E%B7%E5%8F%96%E8%AF%BB%E9%94%81%E3%80%82%E8%80%8C%E5%86%99%E7%BA%BF%E7%A8%8B%E5%9C%A8%E8%8E%B7%E5%8F%96%E4%BA%86%E5%86%99%E9%94%81%E4%B9%8B%E5%90%8E%E8%83%BD%E5%A4%9F%E5%86%8D%E6%AC%A1%E8%8E%B7%E5%8F%96%E5%86%99%E9%94%81%E4%B9%9F%E8%83%BD%E5%A4%9F%E5%90%8C%E6%97%B6%E8%8E%B7%E5%8F%96%E8%AF%BB%E9%94%81%0A%E9%94%81%E9%99%8D%E7%BA%A7%7C%09%E9%81%B5%E5%BE%AA%E8%8E%B7%E5%8F%96%E5%86%99%E9%94%81%E3%80%81%E8%8E%B7%E5%8F%96%E8%AF%BB%E9%94%81%E5%86%8D%E9%87%8A%E6%94%BE%E5%86%99%E9%94%81%E7%9A%84%E6%AC%A1%E5%BA%8F%EF%BC%8C%E5%86%99%E9%94%81%E8%83%BD%E5%A4%9F%E9%99%8D%E7%BA%A7%E7%A7%B0%E4%B8%BA%E8%AF%BB%E9%94%81%0A%0A%3E*%20ReentrantReadWriteLock%E5%B8%B8%E8%A7%81%E6%96%B9%E6%B3%95%EF%BC%9A%0A%3E%C2%A0%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95%0A%0A%E6%96%B9%E6%B3%95%E5%90%8D%E7%A7%B0%7C%09%E6%8F%8F%E8%BF%B0%0A%7C%20---%20%7C%20---%20%7C%0AReentrantReadWriteLock()%09%7C%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%20ReentrantReadWriteLock()%E7%9A%84%E5%AE%9E%E4%BE%8B%0AReentrantReadWriteLock(boolean%20fair)%09%7C%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E7%89%B9%E5%AE%9A%E9%94%81%E7%B1%BB%E5%9E%8B%EF%BC%88%E5%85%AC%E5%B9%B3%E9%94%81%2F%E9%9D%9E%E5%85%AC%E5%B9%B3%E9%94%81%EF%BC%89%E7%9A%84ReentrantReadWriteLock%E7%9A%84%E5%AE%9E%E4%BE%8B%0A%0A%3E%E5%B8%B8%E8%A7%81%E6%96%B9%E6%B3%95%EF%BC%9A%C2%A0%0A%E5%92%8CReentrantLock%E7%B1%BB%20%E7%B1%BB%E4%BC%BC%0A%0A%23%23%23%23%205.3%20ReentrantReadWriteLock%E7%9A%84%E4%BD%BF%E7%94%A8%0A1.%20%E8%AF%BB%E8%AF%BB%E5%85%B1%E4%BA%AB%0A%20%20%20%20%3E%E4%B8%A4%E4%B8%AA%E7%BA%BF%E7%A8%8B%E5%90%8C%E6%97%B6%E8%BF%90%E8%A1%8Cread%E6%96%B9%E6%B3%95%EF%BC%8C%E4%BD%A0%E4%BC%9A%E5%8F%91%E7%8E%B0%E4%B8%A4%E4%B8%AA%E7%BA%BF%E7%A8%8B%E5%8F%AF%E4%BB%A5%E5%90%8C%E6%97%B6%E6%88%96%E8%80%85%E8%AF%B4%E6%98%AF%E5%87%A0%E4%B9%8E%E5%90%8C%E6%97%B6%E8%BF%90%E8%A1%8Clock()%E6%96%B9%E6%B3%95%E5%90%8E%E9%9D%A2%E7%9A%84%E4%BB%A3%E7%A0%81%EF%BC%8C%E8%BE%93%E5%87%BA%E7%9A%84%E4%B8%A4%E5%8F%A5%E8%AF%9D%E6%98%BE%E7%A4%BA%E7%9A%84%E6%97%B6%E9%97%B4%E4%B8%80%E6%A0%B7%E3%80%82%E8%BF%99%E6%A0%B7%E6%8F%90%E9%AB%98%E4%BA%86%E7%A8%8B%E5%BA%8F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4%BB%A3%E7%A0%81%E3%80%82%0A%20%20%20%20%3E*%20%E8%AE%B0%E4%BD%8F%EF%BC%9A%E5%8F%AA%E8%A6%81%E5%87%BA%E7%8E%B0%E5%86%99%E6%93%8D%E4%BD%9C%E7%9A%84%E8%BF%87%E7%A8%8B%E5%B0%B1%E6%98%AF%E4%BA%92%E6%96%A5%E7%9A%84%E3%80%82%0A%0A%23%23%20%E4%BA%94.%20%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B%E4%B8%AD%E4%B8%80%E4%BA%9B%E9%97%AE%E9%A2%98%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/1c7d6d29-4444-4622-a12d-4f1d48fb4f6a.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F622%3A1)%0A%3E%5B%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B%E7%9A%84%E9%97%AE%E9%A2%98%5D(https%3A%2F%2Fblog.csdn.net%2Fqq_34337272%2Farticle%2Fdetails%2F79844051)%0A%0A%23%23%23%201.%20%E5%A4%9A%E7%BA%BF%E7%A8%8B%E5%B0%B1%E4%B8%80%E5%AE%9A%E5%A5%BD%E5%90%97%EF%BC%9F%E5%BF%AB%E5%90%97%EF%BC%9F%EF%BC%9F%0A*%20%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B%E7%9A%84%E7%9B%AE%E7%9A%84%E5%B0%B1%E6%98%AF%E4%B8%BA%E4%BA%86%E8%83%BD%E6%8F%90%E9%AB%98%E7%A8%8B%E5%BA%8F%E7%9A%84%E6%89%A7%E8%A1%8C%E6%95%88%E7%8E%87%E6%8F%90%E9%AB%98%E7%A8%8B%E5%BA%8F%E8%BF%90%E8%A1%8C%E9%80%9F%E5%BA%A6%EF%BC%8C%E4%BD%86%E6%98%AF%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B%E5%B9%B6%E4%B8%8D%E6%80%BB%E6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97%B6%E5%80%99%E5%88%9B%E5%BB%BA%E5%A4%A7%E9%87%8F%E7%BA%BF%E7%A8%8B%E4%BC%9A%E5%AF%BC%E8%87%B4%E5%A4%A7%E9%87%8F%E7%BA%BF%E7%A8%8B%E9%83%BD%E5%A4%84%E4%BA%8E%E7%AD%89%E5%BE%85%E7%8A%B6%E6%80%81%E3%80%82%0A*%20%E4%BD%BF%E7%94%A8%E5%8D%8F%E7%A8%8B%E3%80%82%0A%0A%23%23%23%23%202.2%20CAS%E7%AE%97%E6%B3%95%0A%3ECAS%EF%BC%88%E6%AF%94%E8%BE%83%E4%B8%8E%E4%BA%A4%E6%8D%A2%EF%BC%8CCompare%20and%20swap%EF%BC%89%20%E6%98%AF%E4%B8%80%E7%A7%8D%E6%9C%89%E5%90%8D%E7%9A%84%E6%97%A0%E9%94%81%E7%AE%97%E6%B3%95%E3%80%82%E6%97%A0%E9%94%81%E7%BC%96%E7%A8%8B%EF%BC%8C%E5%8D%B3%E4%B8%8D%E4%BD%BF%E7%94%A8%E9%94%81%E7%9A%84%E6%83%85%E5%86%B5%E4%B8%8B%E5%AE%9E%E7%8E%B0%E5%A4%9A%E7%BA%BF%E7%A8%8B%E4%B9%8B%E9%97%B4%E7%9A%84%E5%8F%98%E9%87%8F%E5%90%8C%E6%AD%A5%EF%BC%8C%E4%B9%9F%E5%B0%B1%E6%98%AF%E5%9C%A8%E6%B2%A1%E6%9C%89%E7%BA%BF%E7%A8%8B%E8%A2%AB%E9%98%BB%E5%A1%9E%E7%9A%84%E6%83%85%E5%86%B5%E4%B8%8B%E5%AE%9E%E7%8E%B0%E5%8F%98%E9%87%8F%E7%9A%84%E5%90%8C%E6%AD%A5%EF%BC%8C%E6%89%80%E4%BB%A5%E4%B9%9F%E5%8F%AB%E9%9D%9E%E9%98%BB%E5%A1%9E%E5%90%8C%E6%AD%A5%EF%BC%88Non-blocking%20Synchronization%EF%BC%89%E3%80%82%0A%3E%E5%AE%9E%E7%8E%B0%E9%9D%9E%E9%98%BB%E5%A1%9E%E5%90%8C%E6%AD%A5%E7%9A%84%E6%96%B9%E6%A1%88%E7%A7%B0%E4%B8%BA%E2%80%9C%E6%97%A0%E9%94%81%E7%BC%96%E7%A8%8B%E7%AE%97%E6%B3%95%E2%80%9D%EF%BC%88%20Non-blocking%20algorithm%EF%BC%89%E3%80%82%20%E5%B1%9E%E4%BA%8E%E4%B9%90%E8%A7%82%E9%94%81%E3%80%82%0A%0A%3E**CAS%E7%AE%97%E6%B3%95%E6%B6%89%E5%8F%8A%E5%88%B0%E4%B8%89%E4%B8%AA%E6%93%8D%E4%BD%9C%E6%95%B0**%0A%3E*%20%E9%9C%80%E8%A6%81%E8%AF%BB%E5%86%99%E7%9A%84%E5%86%85%E5%AD%98%E5%80%BCV%0A%3E*%20%E8%BF%9B%E8%A1%8C%E6%AF%94%E8%BE%83%E7%9A%84%E5%80%BCA%0A%3E*%20%E6%8B%9F%E5%86%99%E5%85%A5%E7%9A%84%E6%96%B0%E5%80%BCB%0A%3E*%20%E5%BD%93%E4%B8%94%E4%BB%85%E5%BD%93%20V%20%E7%9A%84%E5%80%BC%E7%AD%89%E4%BA%8E%20A%E6%97%B6%EF%BC%8CCAS%E9%80%9A%E8%BF%87%E5%8E%9F%E5%AD%90%E6%96%B9%E5%BC%8F%E7%94%A8%E6%96%B0%E5%80%BCB%E6%9D%A5%E6%9B%B4%E6%96%B0V%E7%9A%84%E5%80%BC%EF%BC%8C%E5%90%A6%E5%88%99%E4%B8%8D%E4%BC%9A%E6%89%A7%E8%A1%8C%E4%BB%BB%E4%BD%95%E6%93%8D%E4%BD%9C%EF%BC%88%E6%AF%94%E8%BE%83%E5%92%8C%E6%9B%BF%E6%8D%A2%E6%98%AF%E4%B8%80%E4%B8%AA%E5%8E%9F%E5%AD%90%E6%93%8D%E4%BD%9C%EF%BC%89%E3%80%82%E4%B8%80%E8%88%AC%E6%83%85%E5%86%B5%E4%B8%8B%E6%98%AF%E4%B8%80%E4%B8%AA%E8%87%AA%E6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%94%81%0A%3E*%20%E9%81%BF%E5%85%8D%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%E5%9C%A8%E9%94%81%E5%86%85%E5%90%8C%E6%97%B6%E5%8D%A0%E7%94%A8%E5%A4%9A%E4%B8%AA%E8%B5%84%E6%BA%90%EF%BC%8C%E5%B0%BD%E9%87%8F%E4%BF%9D%E8%AF%81%E6%AF%8F%E4%B8%AA%E9%94%81%E5%8F%AA%E5%8D%A0%E7%94%A8%E4%B8%80%E4%B8%AA%E8%B5%84%E6%BA%90%0A%3E*%20%E5%B0%9D%E8%AF%95%E4%BD%BF%E7%94%A8%E5%AE%9A%E6%97%B6%E9%94%81%EF%BC%8C%E4%BD%BF%E7%94%A8lock.tryLock(timeout)%E6%9D%A5%E6%9B%BF%E4%BB%A3%E4%BD%BF%E7%94%A8%E5%86%85%E9%83%A8%E9%94%81%E6%9C%BA%E5%88%B6%0A%3E*%20%E5%AF%B9%E4%BA%8E%E6%95%B0%E6%8D%AE%E5%BA%93%E9%94%81%EF%BC%8C%E5%8A%A0%E9%94%81%E5%92%8C%E8%A7%A3%E9%94%81%E5%BF%85%E9%A1%BB%E5%9C%A8%E4%B8%80%E4%B8%AA%E6%95%B0%E6%8D%AE%E5%BA%93%E8%BF%9E%E6%8E%A5%E9%87%8C%EF%BC%8C%E5%90%A6%E5%88%99%E4%BC%9A%E5%87%BA%E7%8E%B0%E8%A7%A3%E9%94%81%E5%A4%B1%E8%B4%A5%E7%9A%84%E6%83%85%E5%86%B5%0A%0A%23%23%23%23%203.3%20%E8%A7%A3%E5%86%B3%E8%B5%84%E6%BA%90%E9%99%90%E5%88%B6%0A1.%20**%E4%BB%80%E4%B9%88%E6%98%AF%E8%B5%84%E6%BA%90%E9%99%90%E5%88%B6%EF%BC%9F**%0A%3E%E6%89%80%E8%B0%93%E8%B5%84%E6%BA%90%E9%99%90%E5%88%B6%E5%B0%B1%E6%98%AF%E6%88%91%E4%BB%AC%E5%9C%A8%E8%BF%9B%E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%BA%8F%E7%9A%84%E5%B9%B6%E5%8F%91%E5%BA%A6%EF%BC%8C%E6%AF%94%E5%A6%82%E4%B8%8B%E8%BD%BD%E6%96%87%E4%BB%B6%E7%A8%8B%E5%BA%8F%E4%BE%9D%E8%B5%96%E4%BA%8E%E4%B8%A4%E4%B8%AA%E8%B5%84%E6%BA%90-%E5%B8%A6%E5%AE%BD%E5%92%8C%E7%A1%AC%E7%9B%98%E8%AF%BB%E5%86%99%E9%80%9F%E5%BA%A6%E3%80%82%E6%9C%89%E6%95%B0%E6%8D%AE%E5%BA%93%E6%93%8D%E4%BD%9C%E6%97%B6%EF%BC%8C%E8%AE%BE%E8%AE%A1%E6%95%B0%E6%8D%AE%E5%BA%93%E7%BB%83%E8%BF%9E%E6%8E%A5%E6%95%B0%EF%BC%8C%E5%A6%82%E6%9E%9CSQL%E8%AF%AD%E5%8F%A5%E6%89%A7%E8%A1%8C%E9%9D%9E%E5%B8%B8%E5%BF%AB%EF%BC%8C%E8%80%8C%E7%BA%BF%E7%A8%8B%E7%9A%84%E6%95%B0%E9%87%8F%E6%AF%94%E6%95%B0%E6%8D%AE%E5%BA%93%E8%BF%9E%E6%8E%A5%E6%95%B0%E5%A4%A7%E5%BE%88%E5%A4%9A%EF%BC%8C%E5%88%99%E6%9F%90%E4%BA%9B%E7%BA%BF%E7%A8%8B%E4%BC%9A%E8%A2%AB%E9%98%BB%E5%A1%9E%EF%BC%8C%E7%AD%89%E5%BE%85%E6%95%B0%E6%8D%AE%E5%BA%93%E8%BF%9E%E6%8E%A5%E3%80%82%0A%0A%23%23%20%E5%85%AD.%20%E7%BA%BF%E7%A8%8B%E6%B1%A0%E4%B8%8EExecutor%20%E6%A1%86%E6%9E%B6%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/c9c32249-a785-4ff3-bde9-0395dafc2608.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F629%3A1)%0A%0A%5B%E7%BA%BF%E7%A8%8B%E6%B1%A0%E4%B8%8EExecutor%E6%A1%86%E6%9E%B6%5D(https%3A%2F%2Fblog.csdn.net%2Fqq_34337272%2Farticle%2Fdetails%2F79959271)%0A-%20-%20-%20%0A%23%23%23%201.%20%E4%BD%BF%E7%94%A8%E7%BA%BF%E7%A8%8B%E6%B1%A0%E7%9A%84%E5%A5%BD%E5%A4%84%0A*%20%E7%BA%BF%E7%A8%8B%E6%B1%A0%E6%8F%90%E4%BE%9B%E4%BA%86%E4%B8%80%E7%A7%8D%E9%99%90%E5%88%B6%E5%92%8C%E7%AE%A1%E7%90%86%E8%B5%84%E6%BA%90%EF%BC%88%E5%8C%85%E6%8B%AC%E6%89%A7%E8%A1%8C%E4%B8%80%E4%B8%AA%E4%BB%BB%E5%8A%A1%EF%BC%89%E3%80%82%20%E6%AF%8F%E4%B8%AA%E7%BA%BF%E7%A8%8B%E6%B1%A0%E8%BF%98%E7%BB%B4%E6%8A%A4%E4%B8%80%E4%BA%9B%E5%9F%BA%E6%9C%AC%E7%BB%9F%E8%AE%A1%E4%BF%A1%E6%81%AF%0A%3E%E4%BD%BF%E7%94%A8%E7%BA%BF%E7%A8%8B%E6%B1%A0%E7%9A%84%E5%A5%BD%E5%A4%84%0A%3E%20*%20%20%E9%99%8D%E4%BD%8E%E8%B5%84%E6%BA%90%E6%B6%88%E8%80%97%E3%80%82%E9%80%9A%E8%BF%87%E9%87%8D%E5%A4%8D%E5%88%A9%E7%94%A8%E5%B7%B2%E5%88%9B%E5%BB%BA%E7%9A%84%E7%BA%BF%E7%A8%8B%E9%99%8D%E4%BD%8E%E7%BA%BF%E7%A8%8B%E5%88%9B%E5%BB%BA%E5%92%8C%E9%94%80%E6%AF%81%E9%80%A0%E6%88%90%E7%9A%84%E6%B6%88%E8%80%97%E3%80%82%0A%3E%20*%20%E6%8F%90%E9%AB%98%E5%93%8D%E5%BA%94%E9%80%9F%E5%BA%A6%E3%80%82%E5%BD%93%E4%BB%BB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80%9A%E8%BF%87%20Executor%20%E6%9D%A5%E5%90%AF%E5%8A%A8%E7%BA%BF%E7%A8%8B%E6%AF%94%E4%BD%BF%E7%94%A8%20Thread%20%E7%9A%84%20start%20%E6%96%B9%E6%B3%95%E6%9B%B4%E5%A5%BD%EF%BC%8C%E9%99%A4%E4%BA%86%E6%9B%B4%E6%98%93%E7%AE%A1%E7%90%86%EF%BC%8C%E6%95%88%E7%8E%87%E6%9B%B4%E5%A5%BD%EF%BC%88%E7%94%A8%E7%BA%BF%E7%A8%8B%E6%B1%A0%E5%AE%9E%E7%8E%B0%EF%BC%8C%E8%8A%82%E7%BA%A6%E5%BC%80%E9%94%80%EF%BC%89%E5%A4%96%EF%BC%8C%E8%BF%98%E6%9C%89%E5%85%B3%E9%94%AE%E7%9A%84%E4%B8%80%E7%82%B9%EF%BC%9A%E6%9C%89%E5%8A%A9%E4%BA%8E%E9%81%BF%E5%85%8D%20this%20%E9%80%83%E9%80%B8%E9%97%AE%E9%A2%98%E3%80%82%0A%3Ethis%E9%80%83%E9%80%B8%E6%98%AF%E6%8C%87%E5%9C%A8%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%E8%BF%94%E5%9B%9E%E4%B9%8B%E5%89%8D%E5%85%B6%E4%BB%96%E7%BA%BF%E7%A8%8B%E5%B0%B1%E6%8C%81%E6%9C%89%E8%AF%A5%E5%AF%B9%E8%B1%A1%E7%9A%84%E5%BC%95%E7%94%A8.%20%E8%B0%83%E7%94%A8%E5%B0%9A%E6%9C%AA%E6%9E%84%E9%80%A0%E5%AE%8C%E5%85%A8%E7%9A%84%E5%AF%B9%E8%B1%A1%E7%9A%84%E6%96%B9%E6%B3%95%E5%8F%AF%E8%83%BD%E5%BC%95%E5%8F%91%E4%BB%A4%E4%BA%BA%E7%96%91%E6%83%91%E7%9A%84%E9%94%99%E8%AF%AF%E3%80%82%0A%0A%23%23%23%23%202.2%20Executor%20%E6%A1%86%E6%9E%B6%E7%BB%93%E6%9E%84(%E4%B8%BB%E8%A6%81%E7%94%B1%E4%B8%89%E5%A4%A7%E9%83%A8%E5%88%86%E7%BB%84%E6%88%90)%0A%0A%23%23%23%23%23%201%20%E4%BB%BB%E5%8A%A1%0A%E6%89%A7%E8%A1%8C%E4%BB%BB%E5%8A%A1%E9%9C%80%E8%A6%81%E5%AE%9E%E7%8E%B0%E7%9A%84Runnable%E6%8E%A5%E5%8F%A3%E6%88%96Callable%E6%8E%A5%E5%8F%A3%E3%80%82Runnable%E6%8E%A5%E5%8F%A3%E6%88%96Callable%E6%8E%A5%E5%8F%A3%E5%AE%9E%E7%8E%B0%E7%B1%BB%E9%83%BD%E5%8F%AF%E4%BB%A5%E8%A2%ABThreadPoolExecutor%E6%88%96ScheduledThreadPoolExecutor%E6%89%A7%E8%A1%8C%E3%80%82%0A%0A%3E%E4%B8%A4%E8%80%85%E7%9A%84%E5%8C%BA%E5%88%AB%EF%BC%9A%0A%3E*%20Runnable%E6%8E%A5%E5%8F%A3%E4%B8%8D%E4%BC%9A%E8%BF%94%E5%9B%9E%E7%BB%93%E6%9E%9C%2C%E4%BD%86%E6%98%AFCallable%E6%8E%A5%E5%8F%A3%E5%8F%AF%E4%BB%A5%E8%BF%94%E5%9B%9E%E7%BB%93%E6%9E%9C%E3%80%82%E5%90%8E%E9%9D%A2%E4%BB%8B%E7%BB%8DExecutors%E7%B1%BB%E7%9A%84%E4%B8%80%E4%BA%9B%E6%96%B9%E6%B3%95%E7%9A%84%E6%97%B6%E5%80%99%E4%BC%9A%E4%BB%8B%E7%BB%8D%E5%88%B0%E4%B8%A4%E8%80%85%E7%9A%84%E7%9B%B8%E4%BA%92%E8%BD%AC%E6%8D%A2%E3%80%82%0A%0A%23%23%23%23%23%202%20%E4%BB%BB%E5%8A%A1%E7%9A%84%E6%89%A7%E8%A1%8C%0A%3E!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/9842f2cd-109b-4af6-af9e-ea3f706f0e88.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F624%3A1)%0A*%20%E5%8C%85%E6%8B%AC%E4%BB%BB%E5%8A%A1%E6%89%A7%E8%A1%8C%E6%9C%BA%E5%88%B6%E7%9A%84%E6%A0%B8%E5%BF%83%E6%8E%A5%E5%8F%A3Executor%C2%A0%EF%BC%8C%E4%BB%A5%E5%8F%8A%E7%BB%A7%E6%89%BF%E8%87%AAExecutor%20%E6%8E%A5%E5%8F%A3%E7%9A%84ExecutorService%E6%8E%A5%E5%8F%A3%E3%80%82%0A*%20ScheduledThreadPoolExecutor%E5%92%8CThreadPoolExecutor%E8%BF%99%E4%B8%A4%E4%B8%AA%E5%85%B3%E9%94%AE%E7%B1%BB%E5%AE%9E%E7%8E%B0%E4%BA%86ExecutorService%E6%8E%A5%E5%8F%A3%E3%80%82%0A%23%23%23%23%23%203%20%E5%BC%82%E6%AD%A5%E8%AE%A1%E7%AE%97%E7%9A%84%E7%BB%93%E6%9E%9C%0A*%20Future%E6%8E%A5%E5%8F%A3%E4%BB%A5%E5%8F%8AFuture%E6%8E%A5%E5%8F%A3%E7%9A%84%E5%AE%9E%E7%8E%B0%E7%B1%BBFutureTask%E7%B1%BB%E3%80%82%0A*%20%E5%BD%93%E6%88%91%E4%BB%AC%E6%8A%8ARunnable%E6%8E%A5%E5%8F%A3%E6%88%96Callable%E6%8E%A5%E5%8F%A3%E7%9A%84%E5%AE%9E%E7%8E%B0%E7%B1%BB%E6%8F%90%E4%BA%A4%EF%BC%88%E8%B0%83%E7%94%A8submit%E6%96%B9%E6%B3%95%EF%BC%89%E7%BB%99ThreadPoolExecutor%E6%88%96ScheduledThreadPoolExecutor%E6%97%B6%EF%BC%8C%E4%BC%9A%E8%BF%94%E5%9B%9E%E4%B8%80%E4%B8%AAFutureTask%E5%AF%B9%E8%B1%A1%E3%80%82%0A%23%23%23%23%202.3%20Executor%20%E6%A1%86%E6%9E%B6%E7%9A%84%E4%BD%BF%E7%94%A8%E7%A4%BA%E6%84%8F%E5%9B%BE%0A%3E!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/bd80c263-6e11-4ff1-8845-e9016e7905e3.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F623%3A1)%0A%0A1.%20%E4%B8%BB%E7%BA%BF%E7%A8%8B%E9%A6%96%E5%85%88%E8%A6%81**%E5%88%9B%E5%BB%BA%E5%AE%9E%E7%8E%B0Runnable%E6%88%96%E8%80%85Callable%E6%8E%A5%E5%8F%A3%E7%9A%84%E4%BB%BB%E5%8A%A1%E5%AF%B9%E8%B1%A1**%E3%80%82%0A%20%20%20%20%3E%E5%A4%87%E6%B3%A8%EF%BC%9A%C2%A0%E5%B7%A5%E5%85%B7%E7%B1%BBExecutors%E5%8F%AF%E4%BB%A5%E5%AE%9E%E7%8E%B0Runnable%E5%AF%B9%E8%B1%A1%E5%92%8CCallable%E5%AF%B9%E8%B1%A1%E4%B9%8B%E9%97%B4%E7%9A%84%E7%9B%B8%E4%BA%92%E8%BD%AC%E6%8D%A2%E3%80%82%EF%BC%88Executors.callable%EF%BC%88Runnable%20task%EF%BC%89%E6%88%96Executors.callable%EF%BC%88Runnable%20task%EF%BC%8CObject%20resule%EF%BC%89%EF%BC%89%0A%0A2.%20%E7%84%B6%E5%90%8E%E5%8F%AF%E4%BB%A5%E6%8A%8A%E5%88%9B%E5%BB%BA%E5%AE%8C%E6%88%90%E7%9A%84**Runnable%E5%AF%B9%E8%B1%A1%E7%9B%B4%E6%8E%A5%E4%BA%A4%E7%BB%99ExecutorService%E6%89%A7%E8%A1%8C**%EF%BC%88ExecutorService.execute%EF%BC%88Runnable%20command%EF%BC%89%EF%BC%89%EF%BC%9B%E6%88%96%E8%80%85%E4%B9%9F%E5%8F%AF%E4%BB%A5%E6%8A%8ARunnable%E5%AF%B9%E8%B1%A1%E6%88%96Callable%E5%AF%B9%E8%B1%A1%E6%8F%90%E4%BA%A4%E7%BB%99ExecutorService%E6%89%A7%E8%A1%8C%EF%BC%88ExecutorService.submit%EF%BC%88Runnable%20task%EF%BC%89%E6%88%96ExecutorService.submit%EF%BC%88Callable%20task%EF%BC%89%EF%BC%89%0A%20%20%20%20%3E%E6%89%A7%E8%A1%8Cexecute()%E6%96%B9%E6%B3%95%E5%92%8Csubmit()%E6%96%B9%E6%B3%95%E7%9A%84%E5%8C%BA%E5%88%AB%E6%98%AF%E4%BB%80%E4%B9%88%E5%91%A2%EF%BC%9F%0A1)execute()%E6%96%B9%E6%B3%95%E7%94%A8%E4%BA%8E%E6%8F%90%E4%BA%A4%E4%B8%8D%E9%9C%80%E8%A6%81%E8%BF%94%E5%9B%9E%E5%80%BC%E7%9A%84%E4%BB%BB%E5%8A%A1%EF%BC%8C%E6%89%80%E4%BB%A5%E6%97%A0%E6%B3%95%E5%88%A4%E6%96%AD%E4%BB%BB%E5%8A%A1%E6%98%AF%E5%90%A6%E8%A2%AB%E7%BA%BF%E7%A8%8B%E6%B1%A0%E6%89%A7%E8%A1%8C%E6%88%90%E5%8A%9F%E4%B8%8E%E5%90%A6%EF%BC%9B%0A2)submit()%E6%96%B9%E6%B3%95%E7%94%A8%E4%BA%8E%E6%8F%90%E4%BA%A4%E9%9C%80%E8%A6%81%E8%BF%94%E5%9B%9E%E5%80%BC%E7%9A%84%E4%BB%BB%E5%8A%A1%E3%80%82%E7%BA%BF%E7%A8%8B%E6%B1%A0%E4%BC%9A%E8%BF%94%E5%9B%9E%E4%B8%80%E4%B8%AAfuture%E7%B1%BB%E5%9E%8B%E7%9A%84%E5%AF%B9%E8%B1%A1%EF%BC%8C%E9%80%9A%E8%BF%87%E8%BF%99%E4%B8%AAfuture%E5%AF%B9%E8%B1%A1%E5%8F%AF%E4%BB%A5%E5%88%A4%E6%96%AD%E4%BB%BB%E5%8A%A1%E6%98%AF%E5%90%A6%E6%89%A7%E8%A1%8C%E6%88%90%E5%8A%9F%EF%BC%8C%E5%B9%B6%E4%B8%94%E5%8F%AF%E4%BB%A5%E9%80%9A%E8%BF%87future%E7%9A%84get()%E6%96%B9%E6%B3%95%E6%9D%A5%E8%8E%B7%E5%8F%96%E8%BF%94%E5%9B%9E%E5%80%BC%EF%BC%8Cget()%E6%96%B9%E6%B3%95%E4%BC%9A%E9%98%BB%E5%A1%9E%E5%BD%93%E5%89%8D%E7%BA%BF%E7%A8%8B%E7%9B%B4%E5%88%B0%E4%BB%BB%E5%8A%A1%E5%AE%8C%E6%88%90%EF%BC%8C%E8%80%8C%E4%BD%BF%E7%94%A8get%EF%BC%88long%20timeout%EF%BC%8CTimeUnit%20unit%EF%BC%89%E6%96%B9%E6%B3%95%E5%88%99%E4%BC%9A%E9%98%BB%E5%A1%9E%E5%BD%93%E5%89%8D%E7%BA%BF%E7%A8%8B%E4%B8%80%E6%AE%B5%E6%97%B6%E9%97%B4%E5%90%8E%E7%AB%8B%E5%8D%B3%E8%BF%94%E5%9B%9E%EF%BC%8C%E8%BF%99%E6%97%B6%E5%80%99%E6%9C%89%E5%8F%AF%E8%83%BD%E4%BB%BB%E5%8A%A1%E6%B2%A1%E6%9C%89%E6%89%A7%E8%A1%8C%E5%AE%8C%0A%0A3.%20%E5%A6%82%E6%9E%9C**%E6%89%A7%E8%A1%8CExecutorService.submit**%EF%BC%88%E2%80%A6%EF%BC%89%EF%BC%8CExecutorService%E5%B0%86**%E8%BF%94%E5%9B%9E%E4%B8%80%E4%B8%AA%E5%AE%9E%E7%8E%B0Future%E6%8E%A5%E5%8F%A3%E7%9A%84%E5%AF%B9%E8%B1%A1**%EF%BC%88%E6%88%91%E4%BB%AC%E5%88%9A%E5%88%9A%E4%B9%9F%E6%8F%90%E5%88%B0%E8%BF%87%E4%BA%86%E6%89%A7%E8%A1%8Cexecute()%E6%96%B9%E6%B3%95%E5%92%8Csubmit()%E6%96%B9%E6%B3%95%E7%9A%84%E5%8C%BA%E5%88%AB%EF%BC%8C%E5%88%B0%E7%9B%AE%E5%89%8D%E4%B8%BA%E6%AD%A2%E7%9A%84JDK%E4%B8%AD%EF%BC%8C%E8%BF%94%E5%9B%9E%E7%9A%84%E6%98%AFFutureTask%E5%AF%B9%E8%B1%A1%EF%BC%89%E3%80%82%E7%94%B1%E4%BA%8EFutureTask%E5%AE%9E%E7%8E%B0%E4%BA%86Runnable%EF%BC%8C%E7%A8%8B%E5%BA%8F%E5%91%98%E4%B9%9F%E5%8F%AF%E4%BB%A5%E5%88%9B%E5%BB%BAFutureTask%EF%BC%8C%E7%84%B6%E5%90%8E%E7%9B%B4%E6%8E%A5%E4%BA%A4%E7%BB%99ExecutorService%E6%89%A7%E8%A1%8C%E3%80%82%0A4.%20%E6%9C%80%E5%90%8E%EF%BC%8C%E4%B8%BB%E7%BA%BF%E7%A8%8B%E5%8F%AF%E4%BB%A5**%E6%89%A7%E8%A1%8CFutureTask.get()%E6%96%B9%E6%B3%95%E6%9D%A5%E7%AD%89%E5%BE%85%E4%BB%BB%E5%8A%A1%E6%89%A7%E8%A1%8C%E5%AE%8C%E6%88%90**%E3%80%82%E4%B8%BB%E7%BA%BF%E7%A8%8B%E4%B9%9F%E5%8F%AF%E4%BB%A5%E6%89%A7%E8%A1%8CFutureTask.cancel%EF%BC%88boolean%20mayInterruptIfRunning%EF%BC%89%E6%9D%A5%E5%8F%96%E6%B6%88%E6%AD%A4%E4%BB%BB%E5%8A%A1%E7%9A%84%E6%89%A7%E8%A1%8C%E3%80%82%0A%0A%23%23%23%203.%20ThreadPoolExecutor%E8%AF%A6%E8%A7%A3%0A%E7%BA%BF%E7%A8%8B%E6%B1%A0%E5%AE%9E%E7%8E%B0%E7%B1%BBThreadPoolExecutor%E6%98%AFExecutor%20%E6%A1%86%E6%9E%B6%E6%9C%80%E6%A0%B8%E5%BF%83%E7%9A%84%E7%B1%BB%0A%23%23%23%23%203.1%20ThreadPoolExecutor%E7%B1%BB%E7%9A%84%E5%9B%9B%E4%B8%AA%E6%AF%94%E8%BE%83%E9%87%8D%E8%A6%81%E7%9A%84%E5%B1%9E%E6%80%A7%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/0b0da91f-259e-4770-a179-e8598b489ffc.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F625%3A1)%0A%0A%23%23%23%23%203.2%20ThreadPoolExecutor%E7%B1%BB%E4%B8%AD%E6%8F%90%E4%BE%9B%E7%9A%84%E5%9B%9B%E4%B8%AA%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95%0A%60%60%60java%0A%20%2F**%0A%20%20%20%20%20*%20%E7%94%A8%E7%BB%99%E5%AE%9A%E7%9A%84%E5%88%9D%E5%A7%8B%E5%8F%82%E6%95%B0%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E6%96%B0%E7%9A%84ThreadPoolExecutor%E3%80%82%0A%20%20%20%20%20%0A%20%20%20%20%20*%20%40param%20corePoolSize%20%E6%A0%B8%E5%BF%83%E7%BA%BF%E7%A8%8B%E6%B1%A0%E5%A4%A7%E5%B0%8F%0A%20%20%20%20%20%0A%20%20%20%20%20*%20%40param%20maximumPoolSize%20%E6%9C%80%E5%A4%A7%E7%BA%BF%E7%A8%8B%E6%B1%A0%E7%9A%84%E5%A4%A7%E5%B0%8F%0A%20%20%20%20%20%0A%20%20%20%20%20*%20%40param%20keepAliveTime%20%E5%BD%93%E7%BA%BF%E7%A8%8B%E6%B1%A0%E4%B8%AD%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%95%B0%E9%87%8F%E5%A4%A7%E4%BA%8EcorePoolSize%E7%9A%84%E6%97%B6%E5%80%99%EF%BC%8C%E5%A6%82%E6%9E%9C%E8%BF%99%E6%97%B6%E6%B2%A1%E6%9C%89%E6%96%B0%E7%9A%84%E4%BB%BB%E5%8A%A1%E6%8F%90%E4%BA%A4%EF%BC%8C%0A%20%20%20%20%20*%E6%A0%B8%E5%BF%83%E7%BA%BF%E7%A8%8B%E5%A4%96%E7%9A%84%E7%BA%BF%E7%A8%8B%E4%B8%8D%E4%BC%9A%E7%AB%8B%E5%8D%B3%E9%94%80%E6%AF%81%EF%BC%8C%E8%80%8C%E6%98%AF%E4%BC%9A%E7%AD%89%E5%BE%85%EF%BC%8C%E7%9B%B4%E5%88%B0%E7%AD%89%E5%BE%85%E7%9A%84%E6%97%B6%E9%97%B4%E8%B6%85%E8%BF%87%E4%BA%86keepAliveTime%EF%BC%9B%0A%20%20%20%20%20%0A%20%20%20%20%20*%20%40param%20unit%20%20keepAliveTime%E5%8F%82%E6%95%B0%E7%9A%84%E6%97%B6%E9%97%B4%E5%8D%95%E4%BD%8D%0A%20%20%20%20%20%0A%20%20%20%20%20*%20%40param%20workQueue%20%E7%AD%89%E5%BE%85%E9%98%9F%E5%88%97%EF%BC%8C%E5%BD%93%E4%BB%BB%E5%8A%A1%E6%8F%90%E4%BA%A4%E6%97%B6%EF%BC%8C%E5%A6%82%E6%9E%9C%E7%BA%BF%E7%A8%8B%E6%B1%A0%E4%B8%AD%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%95%B0%E9%87%8F%E5%A4%A7%E4%BA%8E%E7%AD%89%E4%BA%8EcorePoolSize%E7%9A%84%E6%97%B6%E5%80%99%EF%BC%8C%E6%8A%8A%E8%AF%A5%E4%BB%BB%E5%8A%A1%E5%B0%81%E8%A3%85%E6%88%90%E4%B8%80%E4%B8%AAWorker%E5%AF%B9%E8%B1%A1%E6%94%BE%E5%85%A5%E7%AD%89%E5%BE%85%E9%98%9F%E5%88%97%EF%BC%9B%0A%20%20%20%20%20*%20%0A%20%20%20%20%20*%20%40param%20threadFactory%20%E6%89%A7%E8%A1%8C%E8%80%85%E5%88%9B%E5%BB%BA%E6%96%B0%E7%BA%BF%E7%A8%8B%E6%97%B6%E4%BD%BF%E7%94%A8%E7%9A%84%E5%B7%A5%E5%8E%82%0A%20%20%20%20%20%0A%20%20%20%20%20*%20%40param%20handler%20RejectedExecutionHandler%E7%B1%BB%E5%9E%8B%E7%9A%84%E5%8F%98%E9%87%8F%EF%BC%8C%E8%A1%A8%E7%A4%BA%E7%BA%BF%E7%A8%8B%E6%B1%A0%E7%9A%84%E9%A5%B1%E5%92%8C%E7%AD%96%E7%95%A5%E3%80%82%0A%20%20%20%20%20*%20%E5%A6%82%E6%9E%9C%E9%98%BB%E5%A1%9E%E9%98%9F%E5%88%97%E6%BB%A1%E4%BA%86%E5%B9%B6%E4%B8%94%E6%B2%A1%E6%9C%89%E7%A9%BA%E9%97%B2%E7%9A%84%E7%BA%BF%E7%A8%8B%EF%BC%8C%E8%BF%99%E6%97%B6%E5%A6%82%E6%9E%9C%E7%BB%A7%E7%BB%AD%E6%8F%90%E4%BA%A4%E4%BB%BB%E5%8A%A1%EF%BC%8C%E5%B0%B1%E9%9C%80%E8%A6%81%E9%87%87%E5%8F%96%E4%B8%80%E7%A7%8D%E7%AD%96%E7%95%A5%E5%A4%84%E7%90%86%E8%AF%A5%E4%BB%BB%E5%8A%A1%E3%80%82%0A%20%20%20%20%20*%20%E7%BA%BF%E7%A8%8B%E6%B1%A0%E6%8F%90%E4%BE%9B%E4%BA%864%E7%A7%8D%E7%AD%96%E7%95%A5%EF%BC%9A%0A%20%20%20%20%20%20%20%201.AbortPolicy%EF%BC%9A%E7%9B%B4%E6%8E%A5%E6%8A%9B%E5%87%BA%E5%BC%82%E5%B8%B8%EF%BC%8C%E8%BF%99%E6%98%AF%E9%BB%98%E8%AE%A4%E7%AD%96%E7%95%A5%EF%BC%9B%0A%20%20%20%20%20%20%20%202.CallerRunsPolicy%EF%BC%9A%E7%94%A8%E8%B0%83%E7%94%A8%E8%80%85%E6%89%80%E5%9C%A8%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%9D%A5%E6%89%A7%E8%A1%8C%E4%BB%BB%E5%8A%A1%EF%BC%9B%0A%20%20%20%20%20%20%20%203.DiscardOldestPolicy%EF%BC%9A%E4%B8%A2%E5%BC%83%E9%98%BB%E5%A1%9E%E9%98%9F%E5%88%97%E4%B8%AD%E9%9D%A0%E6%9C%80%E5%89%8D%E7%9A%84%E4%BB%BB%E5%8A%A1%EF%BC%8C%E5%B9%B6%E6%89%A7%E8%A1%8C%E5%BD%93%E5%89%8D%E4%BB%BB%E5%8A%A1%EF%BC%9B%0A%20%20%20%20%20%20%20%204.DiscardPolicy%EF%BC%9A%E7%9B%B4%E6%8E%A5%E4%B8%A2%E5%BC%83%E4%BB%BB%E5%8A%A1%EF%BC%9B%0A%20%20%20%20%20*%2F%0A%20%20%20%20public%20ThreadPoolExecutor(int%20corePoolSize%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20int%20maximumPoolSize%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20long%20keepAliveTime%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20TimeUnit%20unit%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20BlockingQueue%3CRunnable%3E%20workQueue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20ThreadFactory%20threadFactory%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20RejectedExecutionHandler%20handler)%20%7B%0A%20%20%20%20%20%20%20%20if%20(corePoolSize%20%3C%200%20%7C%7C%0A%20%20%20%20%20%20%20%20%20%20%20%20maximumPoolSize%20%3C%3D%200%20%7C%7C%0A%20%20%20%20%20%20%20%20%20%20%20%20maximumPoolSize%20%3C%20corePoolSize%20%7C%7C%0A%20%20%20%20%20%20%20%20%20%20%20%20keepAliveTime%20%3C%200)%0A%20%20%20%20%20%20%20%20%20%20%20%20throw%20new%20IllegalArgumentException()%3B%0A%20%20%20%20%20%20%20%20if%20(workQueue%20%3D%3D%20null%20%7C%7C%20threadFactory%20%3D%3D%20null%20%7C%7C%20handler%20%3D%3D%20null)%0A%20%20%20%20%20%20%20%20%20%20%20%20throw%20new%20NullPointerException()%3B%0A%20%20%20%20%20%20%20%20this.corePoolSize%20%3D%20corePoolSize%3B%0A%20%20%20%20%20%20%20%20this.maximumPoolSize%20%3D%20maximumPoolSize%3B%0A%20%20%20%20%20%20%20%20this.workQueue%20%3D%20workQueue%3B%0A%20%20%20%20%20%20%20%20this.keepAliveTime%20%3D%20unit.toNanos(keepAliveTime)%3B%0A%20%20%20%20%20%20%20%20this.threadFactory%20%3D%20threadFactory%3B%0A%20%20%20%20%20%20%20%20this.handler%20%3D%20handler%3B%0A%20%20%20%20%7D%0A%60%60%60%0A%0A%23%23%23%23%203.3%20%E5%A6%82%E4%BD%95%E5%88%9B%E5%BB%BAThreadPoolExecutor%0A%E5%9C%A8%E3%80%8A%E9%98%BF%E9%87%8C%E5%B7%B4%E5%B7%B4Java%E5%BC%80%E5%8F%91%E6%89%8B%E5%86%8C%E3%80%8B%E2%80%9C%E5%B9%B6%E5%8F%91%E5%A4%84%E7%90%86%E2%80%9D%E8%BF%99%E4%B8%80%E7%AB%A0%E8%8A%82%EF%BC%8C%E6%98%8E%E7%A1%AE%E6%8C%87%E5%87%BA%E7%BA%BF%E7%A8%8B%E8%B5%84%E6%BA%90%E5%BF%85%E9%A1%BB%E9%80%9A%E8%BF%87%E7%BA%BF%E7%A8%8B%E6%B1%A0%E6%8F%90%E4%BE%9B%EF%BC%8C%E4%B8%8D%E5%85%81%E8%AE%B8%E5%9C%A8%E5%BA%94%E7%94%A8%E4%B8%AD%E8%87%AA%E8%A1%8C%E6%98%BE%E7%A4%BA%E5%88%9B%E5%BB%BA%E7%BA%BF%E7%A8%8B%E3%80%82%0A%0A**%E4%B8%BA%E4%BB%80%E4%B9%88%E5%91%A2%EF%BC%9F**%0A%3E%E4%BD%BF%E7%94%A8%E7%BA%BF%E7%A8%8B%E6%B1%A0%E7%9A%84%E5%A5%BD%E5%A4%84%E6%98%AF%E5%87%8F%E5%B0%91%E5%9C%A8%E5%88%9B%E5%BB%BA%E5%92%8C%E9%94%80%E6%AF%81%E7%BA%BF%E7%A8%8B%E4%B8%8A%E6%89%80%E6%B6%88%E8%80%97%E7%9A%84%E6%97%B6%E9%97%B4%E4%BB%A5%E5%8F%8A%E7%B3%BB%E7%BB%9F%E8%B5%84%E6%BA%90%E5%BC%80%E9%94%80%EF%BC%8C%E8%A7%A3%E5%86%B3%E8%B5%84%E6%BA%90%E4%B8%8D%E8%B6%B3%E7%9A%84%E9%97%AE%E9%A2%98%E3%80%82%E5%A6%82%E6%9E%9C%E4%B8%8D%E4%BD%BF%E7%94%A8%E7%BA%BF%E7%A8%8B%E6%B1%A0%EF%BC%8C%E6%9C%89%E5%8F%AF%E8%83%BD%E4%BC%9A%E9%80%A0%E6%88%90%E7%B3%BB%E7%BB%9F%E5%88%9B%E5%BB%BA%E5%A4%A7%E9%87%8F%E5%90%8C%E7%B1%BB%E7%BA%BF%E7%A8%8B%E8%80%8C%E5%AF%BC%E8%87%B4%E6%B6%88%E8%80%97%E5%AE%8C%E5%86%85%E5%AD%98%E6%88%96%E8%80%85%E2%80%9C%E8%BF%87%E5%BA%A6%E5%88%87%E6%8D%A2%E2%80%9D%E7%9A%84%E9%97%AE%E9%A2%98%E3%80%82%0A%0A%E5%8F%A6%E5%A4%96%E3%80%8A%E9%98%BF%E9%87%8C%E5%B7%B4%E5%B7%B4Java%E5%BC%80%E5%8F%91%E6%89%8B%E5%86%8C%E3%80%8B%E4%B8%AD**%E5%BC%BA%E5%88%B6%E7%BA%BF%E7%A8%8B%E6%B1%A0%E4%B8%8D%E5%85%81%E8%AE%B8%E4%BD%BF%E7%94%A8%20Executors%20%E5%8E%BB%E5%88%9B%E5%BB%BA%EF%BC%8C%E8%80%8C%E6%98%AF%E9%80%9A%E8%BF%87%20ThreadPoolExecutor%20%E7%9A%84%E6%96%B9%E5%BC%8F**%EF%BC%8C%E8%BF%99%E6%A0%B7%E7%9A%84%E5%A4%84%E7%90%86%E6%96%B9%E5%BC%8F%E8%AE%A9%E5%86%99%E7%9A%84%E5%90%8C%E5%AD%A6%E6%9B%B4%E5%8A%A0%E6%98%8E%E7%A1%AE%E7%BA%BF%E7%A8%8B%E6%B1%A0%E7%9A%84%E8%BF%90%E8%A1%8C%E8%A7%84%E5%88%99%EF%BC%8C%E8%A7%84%E9%81%BF%E8%B5%84%E6%BA%90%E8%80%97%E5%B0%BD%E7%9A%84%E9%A3%8E%E9%99%A9%0A%0A%3EExecutors%20%E8%BF%94%E5%9B%9E%E7%BA%BF%E7%A8%8B%E6%B1%A0%E5%AF%B9%E8%B1%A1%E7%9A%84%E5%BC%8A%E7%AB%AF%E5%A6%82%E4%B8%8B%EF%BC%9A%0A%0A%3E*%20FixedThreadPool%20%E5%92%8C%20SingleThreadExecutor%20%EF%BC%9A%20%E5%85%81%E8%AE%B8%E8%AF%B7%E6%B1%82%E7%9A%84%E9%98%9F%E5%88%97%E9%95%BF%E5%BA%A6%E4%B8%BA%20Integer.MAX_VALUE%2C%E5%8F%AF%E8%83%BD%E5%A0%86%E7%A7%AF%E5%A4%A7%E9%87%8F%E7%9A%84%E8%AF%B7%E6%B1%82%EF%BC%8C%E4%BB%8E%E8%80%8C%E5%AF%BC%E8%87%B4OOM%E3%80%82%0A%3E*%20CachedThreadPool%20%E5%92%8C%20ScheduledThreadPool%20%EF%BC%9A%20%E5%85%81%E8%AE%B8%E5%88%9B%E5%BB%BA%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%95%B0%E9%87%8F%E4%B8%BA%20Integer.MAX_VALUE%20%EF%BC%8C%E5%8F%AF%E8%83%BD%E4%BC%9A%E5%88%9B%E5%BB%BA%E5%A4%A7%E9%87%8F%E7%BA%BF%E7%A8%8B%EF%BC%8C%E4%BB%8E%E8%80%8C%E5%AF%BC%E8%87%B4OOM%E3%80%82%0A%0A**%E6%96%B9%E5%BC%8F%E4%B8%80%EF%BC%9A%E9%80%9A%E8%BF%87%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95%E5%AE%9E%E7%8E%B0**%0A%0A**%E6%96%B9%E5%BC%8F%E4%BA%8C%EF%BC%9A%E9%80%9A%E8%BF%87Executor%20%E6%A1%86%E6%9E%B6%E7%9A%84%E5%B7%A5%E5%85%B7%E7%B1%BBExecutors%E6%9D%A5%E5%AE%9E%E7%8E%B0**%0A*%20%E6%88%91%E4%BB%AC%E5%8F%AF%E4%BB%A5%E5%88%9B%E5%BB%BA%E4%B8%89%E7%A7%8D%E7%B1%BB%E5%9E%8B%E7%9A%84ThreadPoolExecutor%EF%BC%9A%0A%20%20%20%20%3E**FixedThreadPool**%0A%20%20%20%20%3E**SingleThreadExecutor**%0A%20%20%20%20%3E**CachedThreadPool**%0A%20%20%20%20%E5%BA%95%E5%B1%82%E9%83%BD%E6%98%AF%E8%B0%83%E7%94%A8%E7%9A%84ThreadPoolExecutor%E7%9A%84%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95%0A%20%20%20%20%0A%23%23%23%23%203.4%20FixedThreadPool%E8%AF%A6%E8%A7%A3%0A%23%23%23%23%23%20FixedThreadPool%E8%A2%AB%E7%A7%B0%E4%B8%BA%E5%8F%AF%E9%87%8D%E7%94%A8%E5%9B%BA%E5%AE%9A%E7%BA%BF%E7%A8%8B%E6%95%B0%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%B1%A0%E3%80%82%0A%60%60%60java%0A%20%2F**%0A%20%20%20%20%20*%20%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E5%8F%AF%E9%87%8D%E7%94%A8%E5%9B%BA%E5%AE%9A%E6%95%B0%E9%87%8F%E7%BA%BF%E7%A8%8B%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%B1%A0%0A%09%20*%E5%9C%A8%E4%BB%BB%E4%BD%95%E6%97%B6%E5%80%99%E8%87%B3%E5%A4%9A%E6%9C%89n%E4%B8%AA%E7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B1%A0%E4%B8%AD%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%95%B0%0A%20%20%20%20%20*%20%40param%20threadFactory%20%E5%88%9B%E5%BB%BA%E6%96%B0%E7%BA%BF%E7%A8%8B%E6%97%B6%E4%BD%BF%E7%94%A8%E7%9A%84factory%0A%20%20%20%20%20*%20%40return%20%E6%96%B0%E5%88%9B%E5%BB%BA%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%B1%A0%0A%20%20%20%20%20*%20%40throws%20NullPointerException%20%E5%A6%82%E6%9E%9CthreadFactory%E4%B8%BAnull%0A%20%20%20%20%20*%20%40throws%20IllegalArgumentException%20if%20%7B%40code%20nThreads%20%3C%3D%200%7D%0A%20%20%20%20%20*%2F%0A%20%20%20%20public%20static%20ExecutorService%20newFixedThreadPool(int%20nThreads%2C%20ThreadFactory%20threadFactory)%20%7B%0A%20%20%20%20%20%20%20%20return%20new%20ThreadPoolExecutor(nThreads%2C%20nThreads%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%200L%2C%20TimeUnit.MILLISECONDS%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20new%20LinkedBlockingQueue%3CRunnable%3E()%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20threadFactory)%3B%0A%20%20%20%20%7D%0A%60%60%60%0A%0A%60%60%60java%0A%20public%20static%20ExecutorService%20newFixedThreadPool(int%20nThreads)%20%7B%0A%20%20%20%20%20%20%20%20return%20new%20ThreadPoolExecutor(nThreads%2C%20nThreads%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%200L%2C%20TimeUnit.MILLISECONDS%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20new%20LinkedBlockingQueue%3CRunnable%3E())%3B%0A%20%20%20%20%7D%0A%60%60%60%0A**%E6%96%B0%E5%88%9B%E5%BB%BA%E7%9A%84FixedThreadPool%E7%9A%84corePoolSize%E5%92%8CmaximumPoolSize%E9%83%BD%E8%A2%AB%E8%AE%BE%E7%BD%AE%E4%B8%BAnThreads%E3%80%82**%0A-%20-%20-%0A%23%23%23%23%23%20FixedThreadPool%E7%9A%84execute()%E6%96%B9%E6%B3%95%E8%BF%90%E8%A1%8C%E7%A4%BA%E6%84%8F%E5%9B%BE%0A%0A%3E!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/35a191dc-67f0-4c67-b824-699c247c1c6f.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F626%3A1)%0A%0A%E4%B8%8A%E5%9B%BE%E8%AF%B4%E6%98%8E%EF%BC%9A%0A%3E1.%20%E5%A6%82%E6%9E%9C%E5%BD%93%E5%89%8D%E8%BF%90%E8%A1%8C%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%95%B0%E5%B0%8F%E4%BA%8EcorePoolSize%EF%BC%8C%E5%88%99%E5%88%9B%E5%BB%BA%E6%96%B0%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%9D%A5%E6%89%A7%E8%A1%8C%E4%BB%BB%E5%8A%A1%EF%BC%9B%0A%3E2.%20%E5%BD%93%E5%89%8D%E8%BF%90%E8%A1%8C%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%95%B0%E7%AD%89%E4%BA%8EcorePoolSize%E5%90%8E%EF%BC%8C%E5%B0%86%E4%BB%BB%E5%8A%A1%E5%8A%A0%E5%85%A5LinkedBlockingQueue%EF%BC%9B%0A%3E3.%20%E7%BA%BF%E7%A8%8B%E6%89%A7%E8%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95%8C%E9%98%9F%E5%88%97%E6%97%B6maximumPoolSize%E5%B0%86%E6%98%AF%E4%B8%80%E4%B8%AA%E6%97%A0%E6%95%88%E5%8F%82%E6%95%B0%EF%BC%9B%0A%3E3.%20%E7%94%B1%E4%BA%8E1%E5%92%8C2%EF%BC%8C%E4%BD%BF%E7%94%A8%E6%97%A0%E7%95%8C%E9%98%9F%E5%88%97%E6%97%B6keepAliveTime%E5%B0%86%E6%98%AF%E4%B8%80%E4%B8%AA%E6%97%A0%E6%95%88%E5%8F%82%E6%95%B0%EF%BC%9B%0A%3E4.%20%E8%BF%90%E8%A1%8C%E4%B8%AD%E7%9A%84FixedThreadPool%EF%BC%88%E6%9C%AA%E6%89%A7%E8%A1%8Cshutdown()%E6%88%96shutdownNow()%E6%96%B9%E6%B3%95%EF%BC%89%E4%B8%8D%E4%BC%9A%E6%8B%92%E7%BB%9D%E4%BB%BB%E5%8A%A1%0A%0A%23%23%23%23%203.5%20SingleThreadExecutor%E8%AF%A6%E8%A7%A3%0A%23%23%23%23%23%20SingleThreadExecutor%E6%98%AF%E4%BD%BF%E7%94%A8%E5%8D%95%E4%B8%AAworker%E7%BA%BF%E7%A8%8B%E7%9A%84Executor%E3%80%82%0A%60%60%60java%0A%2F**%0A%20%20%20%20%20*%E5%88%9B%E5%BB%BA%E4%BD%BF%E7%94%A8%E5%8D%95%E4%B8%AAworker%E7%BA%BF%E7%A8%8B%E8%BF%90%E8%A1%8C%E6%97%A0%E7%95%8C%E9%98%9F%E5%88%97%E7%9A%84Executor%0A%09%20*%E5%B9%B6%E4%BD%BF%E7%94%A8%E6%8F%90%E4%BE%9B%E7%9A%84ThreadFactory%E5%9C%A8%E9%9C%80%E8%A6%81%E6%97%B6%E5%88%9B%E5%BB%BA%E6%96%B0%E7%BA%BF%E7%A8%8B%0A%20%20%20%20%20*%0A%20%20%20%20%20*%20%40param%20threadFactory%20%E5%88%9B%E5%BB%BA%E6%96%B0%E7%BA%BF%E7%A8%8B%E6%97%B6%E4%BD%BF%E7%94%A8%E7%9A%84factory%0A%20%20%20%20%20*%0A%20%20%20%20%20*%20%40return%20%E6%96%B0%E5%88%9B%E5%BB%BA%E7%9A%84%E5%8D%95%E7%BA%BF%E7%A8%8BExecutor%0A%20%20%20%20%20*%20%40throws%20NullPointerException%20%E5%A6%82%E6%9E%9CThreadFactory%E4%B8%BA%E7%A9%BA%0A%20%20%20%20%20*%2F%0A%20%20%20%20public%20static%20ExecutorService%20newSingleThreadExecutor(ThreadFactory%20threadFactory)%20%7B%0A%20%20%20%20%20%20%20%20return%20new%20FinalizableDelegatedExecutorService%0A%20%20%20%20%20%20%20%20%20%20%20%20(new%20ThreadPoolExecutor(1%2C%201%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%200L%2C%20TimeUnit.MILLISECONDS%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20new%20LinkedBlockingQueue%3CRunnable%3E()%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20threadFactory))%3B%0A%20%20%20%20%7D%0A%60%60%60%0A%0A%60%60%60java%0Apublic%20static%20ExecutorService%20newSingleThreadExecutor()%20%7B%0A%20%20%20%20%20%20%20%20return%20new%20FinalizableDelegatedExecutorService%0A%20%20%20%20%20%20%20%20%20%20%20%20(new%20ThreadPoolExecutor(1%2C%201%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%200L%2C%20TimeUnit.MILLISECONDS%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20new%20LinkedBlockingQueue%3CRunnable%3E()))%3B%0A%20%20%20%20%7D%0A%60%60%60%0A**%E6%96%B0%E5%88%9B%E5%BB%BA%E7%9A%84SingleThreadExecutor%E7%9A%84corePoolSize%E5%92%8CmaximumPoolSize%E9%83%BD%E8%A2%AB%E8%AE%BE%E7%BD%AE%E4%B8%BA1.%0A%E5%85%B6%E4%BB%96%E5%8F%82%E6%95%B0%E5%92%8CFixedThreadPool%E7%9B%B8%E5%90%8C%E3%80%82SingleThreadExecutor%E4%BD%BF%E7%94%A8%E6%97%A0%E7%95%8C%E9%98%9F%E5%88%97LinkedBlockingQueue%E4%BD%9C%E4%B8%BA%E7%BA%BF%E7%A8%8B%E6%B1%A0%E7%9A%84%E5%B7%A5%E4%BD%9C%E9%98%9F%E5%88%97%EF%BC%88%E9%98%9F%E5%88%97%E7%9A%84%E5%AE%B9%E9%87%8F%E4%B8%BAIntger.MAX_VALUE%EF%BC%89**%0A%3ESingleThreadExecutor%E4%BD%BF%E7%94%A8%E6%97%A0%E7%95%8C%E9%98%9F%E5%88%97%E4%BD%9C%E4%B8%BA%E7%BA%BF%E7%A8%8B%E6%B1%A0%E7%9A%84%E5%B7%A5%E4%BD%9C%E9%98%9F%E5%88%97%E4%BC%9A%E5%AF%B9%E7%BA%BF%E7%A8%8B%E6%B1%A0%E5%B8%A6%E6%9D%A5%E7%9A%84%E5%BD%B1%E5%93%8D%E4%B8%8EFixedThreadPool%E7%9B%B8%E5%90%8C%E3%80%82%0A%0A%23%23%23%23%23%20%20SingleThreadExecutor%E7%9A%84%E8%BF%90%E8%A1%8C%E7%A4%BA%E6%84%8F%E5%9B%BE%0A%3E!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/4876c176-bb08-445c-ba2b-449e11ef37a8.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F627%3A1)%0A%0A%E4%B8%8A%E5%9B%BE%E8%AF%B4%E6%98%8E%3A%0A%3E1.%20%E5%A6%82%E6%9E%9C%E5%BD%93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A6%81%E5%88%9B%E5%BB%BA%E6%96%B0%E7%BA%BF%E7%A8%8B%EF%BC%8C%E4%BD%86%E4%BC%9A%E5%9C%A8%E5%85%88%E5%89%8D%E6%9E%84%E5%BB%BA%E7%9A%84%E7%BA%BF%E7%A8%8B%E5%8F%AF%E7%94%A8%E6%97%B6%E9%87%8D%E7%94%A8%E5%AE%83%EF%BC%8C%0A%09%20*%E5%B9%B6%E5%9C%A8%E9%9C%80%E8%A6%81%E6%97%B6%E4%BD%BF%E7%94%A8%E6%8F%90%E4%BE%9B%E7%9A%84ThreadFactory%E5%88%9B%E5%BB%BA%E6%96%B0%E7%BA%BF%E7%A8%8B%E3%80%82%0A%20%20%20%20%20*%20%40param%20threadFactory%20%E5%88%9B%E5%BB%BA%E6%96%B0%E7%BA%BF%E7%A8%8B%E4%BD%BF%E7%94%A8%E7%9A%84factory%0A%20%20%20%20%20*%20%40return%20%E6%96%B0%E5%88%9B%E5%BB%BA%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%B1%A0%0A%20%20%20%20%20*%20%40throws%20NullPointerException%20%E5%A6%82%E6%9E%9CthreadFactory%E4%B8%BA%E7%A9%BA%0A%20%20%20%20%20*%2F%0A%20%20%20%20public%20static%20ExecutorService%20newCachedThreadPool(ThreadFactory%20threadFactory)%20%7B%0A%20%20%20%20%20%20%20%20return%20new%20ThreadPoolExecutor(0%2C%20Integer.MAX_VALUE%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2060L%2C%20TimeUnit.SECONDS%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20new%20SynchronousQueue%3CRunnable%3E()%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20threadFactory)%3B%0A%20%20%20%20%7D%0A%60%60%60%0A%0A%60%60%60java%0Apublic%20static%20ExecutorService%20newCachedThreadPool()%20%7B%0A%20%20%20%20%20%20%20%20return%20new%20ThreadPoolExecutor(0%2C%20Integer.MAX_VALUE%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2060L%2C%20TimeUnit.SECONDS%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20new%20SynchronousQueue%3CRunnable%3E())%3B%0A%20%20%20%20%7D%0A%60%60%60%0A**CachedThreadPool%E7%9A%84corePoolSize%E8%A2%AB%E8%AE%BE%E7%BD%AE%E4%B8%BA%E7%A9%BA%EF%BC%880%EF%BC%89%EF%BC%8CmaximumPoolSize%E8%A2%AB%E8%AE%BE%E7%BD%AE%E4%B8%BAInteger.MAX.VALUE%EF%BC%8C%E5%8D%B3%E5%AE%83%E6%98%AF%E6%97%A0%E7%95%8C%E7%9A%84%EF%BC%8C%E8%BF%99%E4%B9%9F%E5%B0%B1%E6%84%8F%E5%91%B3%E7%9D%80%E5%A6%82%E6%9E%9C%E4%B8%BB%E7%BA%BF%E7%A8%8B%E6%8F%90%E4%BA%A4%E4%BB%BB%E5%8A%A1%E7%9A%84%E9%80%9F%E5%BA%A6%E9%AB%98%E4%BA%8EmaximumPool%E4%B8%AD%E7%BA%BF%E7%A8%8B%E5%A4%84%E7%90%86%E4%BB%BB%E5%8A%A1%E7%9A%84%E9%80%9F%E5%BA%A6%E6%97%B6%EF%BC%8CCachedThreadPool%E4%BC%9A%E4%B8%8D%E6%96%AD%E5%88%9B%E5%BB%BA%E6%96%B0%E7%9A%84%E7%BA%BF%E7%A8%8B**%0A%E6%9E%81%E7%AB%AF%E6%83%85%E5%86%B5%E4%B8%8B%EF%BC%8C%E8%BF%99%E6%A0%B7%E4%BC%9A%E5%AF%BC%E8%87%B4%E8%80%97%E5%B0%BDcpu%E5%92%8C%E5%86%85%E5%AD%98%E8%B5%84%E6%BA%90%E3%80%82%0A%0A%23%23%23%23%23%20CachedThreadPool%E7%9A%84execute()%E6%96%B9%E6%B3%95%E7%9A%84%E6%89%A7%E8%A1%8C%E7%A4%BA%E6%84%8F%E5%9B%BE%0A%3E!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/ea5fa959-786e-4c25-a604-ec226a27e230.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F628%3A1)%0A%0A%E4%B8%8A%E5%9B%BE%E8%AF%B4%E6%98%8E%EF%BC%9A%0A%3E1.%20%E9%A6%96%E5%85%88%E6%89%A7%E8%A1%8CSynchronousQueue.offer(Runnable%20task)%E3%80%82%E5%A6%82%E6%9E%9C%E5%BD%93%E5%89%8DmaximumPool%E4%B8%AD%E6%9C%89%E9%97%B2%E7%BA%BF%E7%A8%8B%E6%AD%A3%E5%9C%A8%E6%89%A7%E8%A1%8CSynchronousQueue.poll(keepAliveTime%2CTimeUnit.NANOSECONDS)%EF%BC%8C%E9%82%A3%E4%B9%88%E4%B8%BB%E7%BA%BF%E7%A8%8B%E6%89%A7%E8%A1%8Coffer%E6%93%8D%E4%BD%9C%E4%B8%8E%E7%A9%BA%E9%97%B2%E7%BA%BF%E7%A8%8B%E6%89%A7%E8%A1%8C%E7%9A%84poll%E6%93%8D%E4%BD%9C%E9%85%8D%E5%AF%B9%E6%88%90%E5%8A%9F%EF%BC%8C%E4%B8%BB%E7%BA%BF%E7%A8%8B%E6%8A%8A%E4%BB%BB%E5%8A%A1%E4%BA%A4%E7%BB%99%E7%A9%BA%E9%97%B2%E7%BA%BF%E7%A8%8B%E6%89%A7%E8%A1%8C%EF%BC%8Cexecute()%E6%96%B9%E6%B3%95%E6%89%A7%E8%A1%8C%E5%AE%8C%E6%88%90%EF%BC%8C%E5%90%A6%E5%88%99%E6%89%A7%E8%A1%8C%E4%B8%8B%E9%9D%A2%E7%9A%84%E6%AD%A5%E9%AA%A42%EF%BC%9B%0A%3E2.%20%E5%BD%93%E5%88%9D%E5%A7%8BmaximumPool%E4%B8%BA%E7%A9%BA%EF%BC%8C%E6%88%96%E8%80%85maximumPool%E4%B8%AD%E6%B2%A1%E6%9C%89%E7%A9%BA%E9%97%B2%E7%BA%BF%E7%A8%8B%E6%97%B6%EF%BC%8C%E5%B0%86%E6%B2%A1%E6%9C%89%E7%BA%BF%E7%A8%8B%E6%89%A7%E8%A1%8CSynchronousQueue.poll(keepAliveTime%2CTimeUnit.NANOSECONDS)%E3%80%82%E8%BF%99%E7%A7%8D%E6%83%85%E5%86%B5%E4%B8%8B%EF%BC%8C%E6%AD%A5%E9%AA%A41%E5%B0%86%E5%A4%B1%E8%B4%A5%EF%BC%8C%E6%AD%A4%E6%97%B6CachedThreadPool%E4%BC%9A%E5%88%9B%E5%BB%BA%E6%96%B0%E7%BA%BF%E7%A8%8B%E6%89%A7%E8%A1%8C%E4%BB%BB%E5%8A%A1%EF%BC%8Cexecute%E6%96%B9%E6%B3%95%E6%89%A7%E8%A1%8C%E5%AE%8C%E6%88%90%EF%BC%9B%0A%0A%23%23%23%23%203.7%20ThreadPoolExecutor%E4%BD%BF%E7%94%A8%E7%A4%BA%E4%BE%8B%0A%20%E9%A6%96%E5%85%88%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AARunnable%E6%8E%A5%E5%8F%A3%E7%9A%84%E5%AE%9E%E7%8E%B0%E7%B1%BBWorkerThread%0A%20%60%60%60java%0Apublic%20class%20ThreadPoolExecutorDemo%20%7B%0A%0A%20%20%20%20public%20static%20void%20main(String%5B%5D%20args)%20%7B%0A%20%20%20%20%20%20%20%20%2F%2F%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AAFixedThreadPool%E5%AF%B9%E8%B1%A1%0A%20%20%20%20%20%20%20%20ExecutorService%20executor%20%3D%20Executors.newFixedThreadPool(5)%3B%0A%20%20%20%20%20%20%20%20for%20(int%20i%20%3D%200%3B%20i%20%3C%2010%3B%20i%2B%2B)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%E5%88%9B%E5%BB%BAWorkerThread%E5%AF%B9%E8%B1%A1%EF%BC%88WorkerThread%E7%B1%BB%E5%AE%9E%E7%8E%B0%E4%BA%86Runnable%20%E6%8E%A5%E5%8F%A3%EF%BC%89%0A%20%20%20%20%20%20%20%20%20%20%20%20Runnable%20worker%20%3D%20new%20WorkerThread(%22%22%20%2B%20i)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%E6%89%A7%E8%A1%8CRunnable%0A%20%20%20%20%20%20%20%20%20%20%20%20executor.execute(worker)%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%2F%2F%E7%BB%88%E6%AD%A2%E7%BA%BF%E7%A8%8B%E6%B1%A0%0A%20%20%20%20%20%20%20%20executor.shutdown()%3B%0A%20%20%20%20%20%20%20%20while%20(!executor.isTerminated())%20%7B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20System.out.println(%22Finished%20all%20threads%22)%3B%0A%20%20%20%20%7D%0A%7D%0A%60%60%60%0A-%20-%20-%0A**shutdown%EF%BC%88%EF%BC%89VS%20shutdownNow%EF%BC%88%EF%BC%89**%0A%3E1.%20shutdown%EF%BC%88%EF%BC%89%E6%96%B9%E6%B3%95%E8%A1%A8%E6%98%8E%E5%85%B3%E9%97%AD%E5%B7%B2%E5%9C%A8Executor%E4%B8%8A%E8%B0%83%E7%94%A8%EF%BC%8C%E5%9B%A0%E6%AD%A4%E4%B8%8D%E4%BC%9A%E5%86%8D%E5%90%91DelayedPool%E6%B7%BB%E5%8A%A0%E4%BB%BB%E4%BD%95%E5%85%B6%E4%BB%96%E4%BB%BB%E5%8A%A1%EF%BC%88%E7%94%B1ScheduledThreadPoolExecutor%E7%B1%BB%E5%9C%A8%E5%86%85%E9%83%A8%E4%BD%BF%E7%94%A8%EF%BC%89%2C%C2%A0%E4%BD%86%E6%98%AF%EF%BC%8C%E5%B7%B2%E7%BB%8F%E5%9C%A8%E9%98%9F%E5%88%97%E4%B8%AD%E6%8F%90%E4%BA%A4%E7%9A%84%E4%BB%BB%E5%8A%A1%E5%B0%86%E8%A2%AB%E5%85%81%E8%AE%B8%E5%AE%8C%E6%88%90%E3%80%82%0A%3E2.%20shutdownNow%EF%BC%88%EF%BC%89%E6%96%B9%E6%B3%95%E8%AF%95%E5%9B%BE%E7%BB%88%E6%AD%A2%E5%BD%93%E5%89%8D%E6%AD%A3%E5%9C%A8%E8%BF%90%E8%A1%8C%E7%9A%84%E4%BB%BB%E5%8A%A1%EF%BC%8C%E5%B9%B6%E5%81%9C%E6%AD%A2%E5%A4%84%E7%90%86%E6%8E%92%E9%98%9F%E7%9A%84%E4%BB%BB%E5%8A%A1%E5%B9%B6%E8%BF%94%E5%9B%9E%E6%AD%A3%E5%9C%A8%E7%AD%89%E5%BE%85%E6%89%A7%E8%A1%8C%E7%9A%84List%E3%80%82%0A%0A**isTerminated()%20Vs%20isShutdown()**%0A%3E1.%20isShutDown%E5%BD%93%E8%B0%83%E7%94%A8shutdown()%E6%96%B9%E6%B3%95%E5%90%8E%E8%BF%94%E5%9B%9E%E4%B8%BAtrue%E3%80%82%0A%3E2.%20%C2%A0isTerminated%E5%BD%93%E8%B0%83%E7%94%A8shutdown()%E6%96%B9%E6%B3%95%E5%90%8E%EF%BC%8C%E5%B9%B6%E4%B8%94%E6%89%80%E6%9C%89%E6%8F%90%E4%BA%A4%E7%9A%84%E4%BB%BB%E5%8A%A1%E5%AE%8C%E6%88%90%E5%90%8E%E8%BF%94%E5%9B%9E%E4%B8%BAtrue%0A%0A%23%23%23%204.%20ScheduledThreadPoolExecutor%E8%AF%A6%E8%A7%A3%0A%23%23%23%23%204.1%20ScheduledThreadPoolExecutor%E7%AE%80%E4%BB%8B%0A1.%20ScheduledThreadPoolExecutor%E4%B8%BB%E8%A6%81%E7%94%A8%E6%9D%A5%E5%9C%A8%E7%BB%99%E5%AE%9A%E7%9A%84**%E5%BB%B6%E8%BF%9F%E5%90%8E%E8%BF%90%E8%A1%8C%E4%BB%BB%E5%8A%A1**%EF%BC%8C%E6%88%96%E8%80%85**%E5%AE%9A%E6%9C%9F%E6%89%A7%E8%A1%8C**%E4%BB%BB%E5%8A%A1%E3%80%82%0A2.%20ScheduledThreadPoolExecutor%E4%BD%BF%E7%94%A8%E7%9A%84**%E4%BB%BB%E5%8A%A1%E9%98%9F%E5%88%97DelayQueue%E5%B0%81%E8%A3%85%E4%BA%86%E4%B8%80%E4%B8%AAPriorityQueue**%EF%BC%8CPriorityQueue%E4%BC%9A%E5%AF%B9%E9%98%9F%E5%88%97%E4%B8%AD%E7%9A%84%E4%BB%BB%E5%8A%A1%E8%BF%9B%E8%A1%8C%E6%8E%92%E5%BA%8F%EF%BC%8C%E6%89%A7%E8%A1%8C%E6%89%80%E9%9C%80%E6%97%B6%E9%97%B4%E7%9F%AD%E7%9A%84%E6%94%BE%E5%9C%A8%E5%89%8D%E9%9D%A2%E5%85%88%E8%A2%AB%E6%89%A7%E8%A1%8C(ScheduledFutureTask%E7%9A%84time%E5%8F%98%E9%87%8F%E5%B0%8F%E7%9A%84%E5%85%88%E6%89%A7%E8%A1%8C)%EF%BC%8C%E5%A6%82%E6%9E%9C%E6%89%A7%E8%A1%8C%E6%89%80%E9%9C%80%E6%97%B6%E9%97%B4%E7%9B%B8%E5%90%8C%E5%88%99%E5%85%88%E6%8F%90%E4%BA%A4%E7%9A%84%E4%BB%BB%E5%8A%A1%E5%B0%86%E8%A2%AB%E5%85%88%E6%89%A7%E8%A1%8C(ScheduledFutureTask%E7%9A%84squenceNumber%E5%8F%98%E9%87%8F%E5%B0%8F%E7%9A%84%E5%85%88%E6%89%A7%E8%A1%8C)%E3%80%82%0A%0A%23%23%23%23%204.2%20ScheduledThreadPoolExecutor%E8%BF%90%E8%A1%8C%E6%9C%BA%E5%88%B6%0A%3E!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/d5242572-6958-4e78-a1e6-536026680d7f.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F630%3A1)%0A%0A**ScheduledThreadPoolExecutor%E7%9A%84%E6%89%A7%E8%A1%8C%E4%B8%BB%E8%A6%81%E5%88%86%E4%B8%BA%E4%B8%A4%E5%A4%A7%E9%83%A8%E5%88%86%EF%BC%9A**%0A%3E1.%20%E5%BD%93%E8%B0%83%E7%94%A8ScheduledThreadPoolExecutor%E7%9A%84%20scheduleAtFixedRate()%20%E6%96%B9%E6%B3%95%E6%88%96%E8%80%85scheduleWirhFixedDelay()%20%E6%96%B9%E6%B3%95%E6%97%B6%EF%BC%8C%E4%BC%9A%E5%90%91ScheduledThreadPoolExecutor%E7%9A%84%20DelayQueue%20%E6%B7%BB%E5%8A%A0%E4%B8%80%E4%B8%AA%E5%AE%9E%E7%8E%B0%E4%BA%86%20RunnableScheduledFutur%20%E6%8E%A5%E5%8F%A3%E7%9A%84%20ScheduledFutureTask%20%E3%80%82%0A%3E2.%20%E7%BA%BF%E7%A8%8B%E6%B1%A0%E4%B8%AD%E7%9A%84%E7%BA%BF%E7%A8%8B%E4%BB%8EDelayQueue%E4%B8%AD%E8%8E%B7%E5%8F%96ScheduledFutureTask%EF%BC%8C%E7%84%B6%E5%90%8E%E6%89%A7%E8%A1%8C%E4%BB%BB%E5%8A%A1%E3%80%82%0A%0A**ScheduledThreadPoolExecutor%E4%B8%BA%E4%BA%86%E5%AE%9E%E7%8E%B0%E5%91%A8%E6%9C%9F%E6%80%A7%E7%9A%84%E6%89%A7%E8%A1%8C%E4%BB%BB%E5%8A%A1%EF%BC%8C%E5%AF%B9ThreadPoolExecutor%E5%81%9A%E4%BA%86%E5%A6%82%E4%B8%8B%E4%BF%AE%E6%94%B9%EF%BC%9A**%0A%20%3E%20*%20%E4%BD%BF%E7%94%A8%C2%A0DelayQueue%C2%A0%E4%BD%9C%E4%B8%BA%E4%BB%BB%E5%8A%A1%E9%98%9F%E5%88%97%EF%BC%9B%0A%20%3E*%20%20%E8%8E%B7%E5%8F%96%E4%BB%BB%E5%8A%A1%E7%9A%84%E6%96%B9%E4%B8%8D%E5%90%8C%0A%20%3E%20*%20%E6%89%A7%E8%A1%8C%E5%91%A8%E6%9C%9F%E4%BB%BB%E5%8A%A1%E5%90%8E%EF%BC%8C%E5%A2%9E%E5%8A%A0%E4%BA%86%E9%A2%9D%E5%A4%96%E7%9A%84%E5%A4%84%E7%90%86%0A%0A%23%23%23%23%204.3%20ScheduledThreadPoolExecutor%E6%89%A7%E8%A1%8C%E5%91%A8%E6%9C%9F%E4%BB%BB%E5%8A%A1%E7%9A%84%E6%AD%A5%E9%AA%A4%0A%3E!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/46366e73-3260-4eee-8455-c549e35d981f/f408d157-54c7-4689-8dd3-0860daea27d4.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F631%3A1)%0A%0A%3E1.%20%E7%BA%BF%E7%A8%8B1%E4%BB%8EDelayQueue%E4%B8%AD%E8%8E%B7%E5%8F%96%E5%B7%B2%E5%88%B0%E6%9C%9F%E7%9A%84ScheduledFutureTask%EF%BC%88DelayQueue.take()%EF%BC%89%E3%80%82%E5%88%B0%E6%9C%9F%E4%BB%BB%E5%8A%A1%E6%98%AF%E6%8C%87ScheduledFutureTask%E7%9A%84time%E5%A4%A7%E4%BA%8E%E7%AD%89%E4%BA%8E%E5%BD%93%E5%89%8D%E7%B3%BB%E7%BB%9F%E7%9A%84%E6%97%B6%E9%97%B4%EF%BC%9B%0A%3E2.%20%E7%BA%BF%E7%A8%8B1%E6%89%A7%E8%A1%8C%E8%BF%99%E4%B8%AAScheduledFutureTask%EF%BC%9B%0A%3E3.%20%E7%BA%BF%E7%A8%8B1%E4%BF%AE%E6%94%B9ScheduledFutureTask%E7%9A%84time%E5%8F%98%E9%87%8F%E4%B8%BA%E4%B8%8B%E6%AC%A1%E5%B0%86%E8%A6%81%E8%A2%AB%E6%89%A7%E8%A1%8C%E7%9A%84%E6%97%B6%E9%97%B4%EF%BC%9B%0A%3E4.%20%E7%BA%BF%E7%A8%8B1%E6%8A%8A%E8%BF%99%E4%B8%AA%E4%BF%AE%E6%94%B9time%E4%B9%8B%E5%90%8E%E7%9A%84ScheduledFutureTask%E6%94%BE%E5%9B%9EDelayQueue%E4%B8%AD%EF%BC%88DelayQueue.add())%E3%80%82%0A%0A%23%23%23%23%204.4%20ScheduledThreadPoolExecutor%E4%BD%BF%E7%94%A8%E7%A4%BA%E4%BE%8B%0A%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E7%AE%80%E5%8D%95%E7%9A%84%E5%AE%9E%E7%8E%B0Runnable%E6%8E%A5%E5%8F%A3%E7%9A%84%E7%B1%BB%0A%E6%B5%8B%E8%AF%95%E7%A8%8B%E5%BA%8F%E4%BD%BF%E7%94%A8ScheduledExecutorService%E5%92%8CExecutors.newScheduledThreadPool%E5%AE%9E%E7%8E%B0%E7%9A%84java%E8%B0%83%E5%BA%A6%0A%0A%23%23%23%23%23%204.4.1%20ScheduledExecutorService%20scheduleAtFixedRate(Runnable%20command%2Clong%20initialDelay%2Clong%20period%2CTimeUnit%20unit)%E6%96%B9%E6%B3%95%0A%60%60%60java%0A%2F%2F%E5%8F%AF%E4%BB%A5%E4%BD%BF%E7%94%A8ScheduledExecutorService%20scheduleAtFixedRate%E6%96%B9%E6%B3%95%E6%9D%A5%E5%AE%89%E6%8E%92%E4%BB%BB%E5%8A%A1%E5%9C%A8%E5%88%9D%E5%A7%8B%E5%BB%B6%E8%BF%9F%E5%90%8E%E8%BF%90%E8%A1%8C%EF%BC%8C%E7%84%B6%E5%90%8E%E5%9C%A8%E7%BB%99%E5%AE%9A%E7%9A%84%E6%97%B6%E9%97%B4%E6%AE%B5%E5%86%85%E8%BF%90%E8%A1%8C%E3%80%82%0A%0AscheduledThreadPool.scheduleAtFixedRate(worker%2C%200%2C%2010%2C%20TimeUnit.SECONDS)%3B%0A%60%60%60%0A%0A%23%23%23%23%23%204.4.2%20ScheduledExecutorService%20scheduleWithFixedDelay(Runnable%20command%2Clong%20initialDelay%2Clong%20delay%2CTimeUnit%20unit)%E6%96%B9%E6%B3%95%0A%60%60%60java%0A%2F%2FScheduledExecutorService%20scheduleWithFixedDelay%E6%96%B9%E6%B3%95%E5%8F%AF%E7%94%A8%E4%BA%8E%E4%BB%A5%E5%88%9D%E5%A7%8B%E5%BB%B6%E8%BF%9F%E5%90%AF%E5%8A%A8%E5%91%A8%E6%9C%9F%E6%80%A7%E6%89%A7%E8%A1%8C%EF%BC%8C%E7%84%B6%E5%90%8E%E4%BB%A5%E7%BB%99%E5%AE%9A%E5%BB%B6%E8%BF%9F%E6%89%A7%E8%A1%8C%E3%80%82%20%E5%BB%B6%E8%BF%9F%E6%97%B6%E9%97%B4%E6%98%AF%E7%BA%BF%E7%A8%8B%E5%AE%8C%E6%88%90%E6%89%A7%E8%A1%8C%E7%9A%84%E6%97%B6%E9%97%B4%E3%80%82%0A%0AscheduledThreadPool.scheduleWithFixedDelay(worker%2C%200%2C%201%2C%20TimeUnit.SECONDS)%3B%0A%60%60%60%0A%23%23%23%23%23%204.4.3%20scheduleWithFixedDelay()%20vs%20scheduleAtFixedRate()%0A1.%20**scheduleAtFixedRate**%EF%BC%88%E2%80%A6%EF%BC%89%E5%B0%86%E5%BB%B6%E8%BF%9F%E8%A7%86%E4%B8%BA%E4%B8%A4%E4%B8%AA%E4%BB%BB%E5%8A%A1**%E5%BC%80%E5%A7%8B%E4%B9%8B%E9%97%B4%E7%9A%84%E5%B7%AE%E5%BC%82**%EF%BC%88%E5%8D%B3%E5%AE%9A%E6%9C%9F%E8%B0%83%E7%94%A8%EF%BC%89%0A%E4%B8%8D%E7%AE%A1%E6%98%AF%E5%90%A6%E6%89%A7%E8%A1%8C%E5%AE%8C%0A2.%20**scheduleWithFixedDelay**%EF%BC%88%E2%80%A6%EF%BC%89%E5%B0%86%E5%BB%B6%E8%BF%9F%E8%A7%86%E4%B8%BA**%E4%B8%80%E4%B8%AA%E4%BB%BB%E5%8A%A1%E7%BB%93%E6%9D%9F%E4%B8%8E%E4%B8%8B%E4%B8%80%E4%B8%AA%E4%BB%BB%E5%8A%A1%E5%BC%80%E5%A7%8B**%E4%B9%8B%E9%97%B4%E7%9A%84%E5%B7%AE%E5%BC%82%EF%BC%8C%E6%89%A7%E8%A1%8C%E5%AE%8C%E6%89%8D%E5%BC%80%E5%A7%8B%E4%B8%8B%E4%B8%80%E4%B8%AA%E3%80%82%0A%0A%3E**scheduleAtFixedRate()**%3A%20%E5%9C%A8%E7%BB%99%E5%AE%9A%E7%9A%84%E5%88%9D%E5%A7%8B%E5%BB%B6%E8%BF%9F%E4%B9%8B%E5%90%8E%E5%88%9B%E5%BB%BA%E5%B9%B6%E6%89%A7%E8%A1%8C%EF%BC%8C%E9%9A%8F%E5%90%8E%E4%BB%A5%E7%BB%99%E5%AE%9A%E7%9A%84%E6%97%B6%E9%97%B4%E6%AE%B5%E9%A6%96%E5%85%88%E5%90%AF%E7%94%A8%E7%9A%84%E5%91%A8%E6%9C%9F%E6%80%A7%E5%8A%A8%E4%BD%9C%3B%20%E9%82%A3%E5%B0%B1%E6%98%AF%E6%89%A7%E8%A1%8C%E5%B0%86%E5%9C%A8initialDelay%E4%B9%8B%E5%90%8E%E5%BC%80%E5%A7%8B%EF%BC%8C%E7%84%B6%E5%90%8EinitialDelay%2Bperiod%20%EF%BC%8C%E7%84%B6%E5%90%8E%E6%98%AFinitialDelay%20%2B%202%20*%20period%20%EF%BC%8C%E7%AD%89%E7%AD%89%E3%80%82%20%E5%A6%82%E6%9E%9C%E4%BB%BB%E5%8A%A1%E7%9A%84%E6%89%A7%E8%A1%8C%E9%81%87%E5%88%B0%E5%BC%82%E5%B8%B8%EF%BC%8C%E5%88%99%E5%90%8E%E7%BB%AD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84%E6%89%A7%E8%A1%8C%E9%81%87%E5%88%B0%E5%BC%82%E5%B8%B8%EF%BC%8C%E5%88%99%E5%90%8E%E7%BB%AD%E7%9A%84%E6%89%A7%E8%A1%8C%E8%A2%AB%E6%8A%91%E5%88%B6%E3%80%82%20%E5%90%A6%E5%88%99%EF%BC%8C%E4%BB%BB%E5%8A%A1%E5%B0%86%E4%BB%85%E9%80%9A%E8%BF%87%E5%8F%96%E6%B6%88%E6%88%96%E7%BB%88%E6%AD%A2%E6%89%A7%E8%A1%8C%E7%BB%88%E6%AD%A2%E3%80%82%0A%0A%23%23%23%205.%20%E5%90%84%E7%A7%8D%E7%BA%BF%E7%A8%8B%E6%B1%A0%E7%9A%84%E9%80%82%E7%94%A8%E5%9C%BA%E6%99%AF%E4%BB%8B%E7%BB%8D%0A**FixedThreadPool**%EF%BC%9A%20%E9%80%82%E7%94%A8%E4%BA%8E%E4%B8%BA%E4%BA%86%E6%BB%A1%E8%B6%B3%E8%B5%84%E6%BA%90%E7%AE%A1%E7%90%86%E9%9C%80%E6%B1%82%EF%BC%8C%E8%80%8C%E9%9C%80%E8%A6%81%E9%99%90%E5%88%B6%E5%BD%93%E5%89%8D%E7%BA%BF%E7%A8%8B%E6%95%B0%E9%87%8F%E7%9A%84%E5%BA%94%E7%94%A8%E5%9C%BA%E6%99%AF%E3%80%82%E5%AE%83%E9%80%82%E7%94%A8%E4%BA%8E%E8%B4%9F%E8%BD%BD%E6%AF%94%E8%BE%83%E9%87%8D%E7%9A%84%E6%9C%8D%E5%8A%A1%E5%99%A8%EF%BC%9B%0A%0A**SingleThreadExecutor**%EF%BC%9A%20%E9%80%82%E7%94%A8%E4%BA%8E%E9%9C%80%E8%A6%81%E4%BF%9D%E8%AF%81%E9%A1%BA%E5%BA%8F%E5%9C%B0%E6%89%A7%E8%A1%8C%E5%90%84%E4%B8%AA%E4%BB%BB%E5%8A%A1%E5%B9%B6%E4%B8%94%E5%9C%A8%E4%BB%BB%E6%84%8F%E6%97%B6%E9%97%B4%E7%82%B9%EF%BC%8C%E4%B8%8D%E4%BC%9A%E6%9C%89%E5%A4%9A%E4%B8%AA%E7%BA%BF%E7%A8%8B%E6%98%AF%E6%B4%BB%E5%8A%A8%E7%9A%84%E5%BA%94%E7%94%A8%E5%9C%BA%E6%99%AF%E3%80%82%0A%0A**CachedThreadPool**%EF%BC%9A%20%E9%80%82%E7%94%A8%E4%BA%8E%E6%89%A7%E8%A1%8C%E5%BE%88%E5%A4%9A%E7%9A%84%E7%9F%AD%E6%9C%9F%E5%BC%82%E6%AD%A5%E4%BB%BB%E5%8A%A1%E7%9A%84%E5%B0%8F%E7%A8%8B%E5%BA%8F%EF%BC%8C%E6%88%96%E8%80%85%E6%98%AF%E8%B4%9F%E8%BD%BD%E8%BE%83%E8%BD%BB%E7%9A%84%E6%9C%8D%E5%8A%A1%E5%99%A8%EF%BC%9B%0A%0A**ScheduledThreadPoolExecutor**%EF%BC%9A%20%E9%80%82%E7%94%A8%E4%BA%8E%E9%9C%80%E8%A6%81%E5%A4%9A%E4%B8%AA%E5%90%8E%E5%8F%B0%E6%89%A7%E8%A1%8C%E5%91%A8%E6%9C%9F%E4%BB%BB%E5%8A%A1%EF%BC%8C%E5%90%8C%E6%97%B6%E4%B8%BA%E4%BA%86%E6%BB%A1%E8%B6%B3%E8%B5%84%E6%BA%90%E7%AE%A1%E7%90%86%E9%9C%80%E6%B1%82%E8%80%8C%E9%9C%80%E8%A6%81%E9%99%90%E5%88%B6%E5%90%8E%E5%8F%B0%E7%BA%BF%E7%A8%8B%E7%9A%84%E6%95%B0%E9%87%8F%E7%9A%84%E5%BA%94%E7%94%A8%E5%9C%BA%E6%99%AF%EF%BC%8C%0A%0A**SingleThreadScheduledExecutor**%EF%BC%9A%20%E9%80%82%E7%94%A8%E4%BA%8E%E9%9C%80%E8%A6%81%E5%8D%95%E4%B8%AA%E5%90%8E%E5%8F%B0%E7%BA%BF%E7%A8%8B%E6%89%A7%E8%A1%8C%E5%91%A8%E6%9C%9F%E4%BB%BB%E5%8A%A1%EF%BC%8C%E5%90%8C%E6%97%B6%E4%BF%9D%E8%AF%81%E9%A1%BA%E5%BA%8F%E5%9C%B0%E6%89%A7%E8%A1%8C%E5%90%84%E4%B8%AA%E4%BB%BB%E5%8A%A1%E7%9A%84%E5%BA%94%E7%94%A8%E5%9C%BA%E6%99%AF%E3%80%82%0A&lt;/center&gt;&lt;/div&gt;
</content>
  </entry>
  <entry xml:base="http://linzhiteng.postach.io/feed.xml">
    <title type="text">树</title>
    <id>https://linzhiteng.postach.io/post/shu</id>
    <updated>2019-06-09T13:26:56.406000Z</updated>
    <published>2019-03-04T01:06:28Z</published>
    <link href="https://linzhiteng.postach.io/post/shu" />
    <author>
      <name>linzhi teng</name>
    </author>
    <category term="shu" />
    <content type="html">&lt;div&gt;&lt;div style=&quot;font-size: 14px; margin: 0; padding: 0; width: 100%;&quot;&gt;&lt;div style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;树
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;一. 二叉树
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1. 二叉树的基本概念
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.1 二叉树基本形态
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.2 二叉树类型
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.3 树的相关术语
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.4 二叉树性质
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1.5 二叉树遍历
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2. 完全二叉树
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.1 完全二叉树定义
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.2 完全二叉树性质
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.3 完全二叉树特点
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.4 完全二叉树存储
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.5 完全二叉树判定
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3. 满二叉树
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1 满二叉树定义
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4. 堆
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.1 堆的概念
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.2 堆的实现
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;5. 二叉查找树(排序树)(Binary Search Tree，BST)
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;二叉树查找树的详细解析
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;6. 平衡二叉树(AVL树)
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;6.1 平衡二叉树定义
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;6.2  平衡二叉树性质
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;6.3 平衡二叉树的设计
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;6.3.1 左左单旋转(LL)情景①分析
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;6.3.2 右右单旋转(RR)情景④分析
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;6.3.3 左右双旋转(LR)情景②分析
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;6.3.4 右左双旋转(RL)情景③分析
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;平衡二叉树详细解析
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;二 . 红黑树
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;1. 红黑树简介
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2. 红黑树的修正
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.1 左旋
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;2.2 右旋
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3. 红黑树节点的添加
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1  红黑树插入后节点的调整思想:
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1.1 插入操作-case 1(叔叔节点也为红色)
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1.2 插入操作-case 2
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1.3 插入操作-case 3
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4. 红黑树节点的删除
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.1 红黑树删除之节点调整
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.1.1 删除操作-case 1
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.1.2 删除操作-case 2
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.1.3 删除操作-case 3
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.1.4 删除操作-case 4
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;三 . B树、B+树、B*树
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1 B树(B-树)
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1.1 B树简介
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1.2 B树特点
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1.3 B树的查找
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;查找操作的时间开销
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1.4 B树的插入
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.1.5 B树的删除
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.2 B+树
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.2.1 B+树简介
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;B+树用途
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.2.2 B+树定义
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;B+树与B-树的不同
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.2.3 B+树的特性：
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.2.4 B+树 vs B树
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.3 B*树
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.3.1 B*树简介
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.3.2 B*树 vs B+树
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;3.4 小结：
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;四. LSM树
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.1 LSM由来
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;4.2 LSM树原理
&lt;/a&gt;&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;原理
&lt;/a&gt;&lt;/li&gt;&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;a   style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;实现
&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h1 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 41px; border-bottom: 3px double #999; color: #000; margin-top: 14px;&quot;&gt;树&lt;/h1&gt;
&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;一. 二叉树&lt;/h2&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;1. 二叉树的基本概念&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;二叉树是每个结点最多有两个子树的树结构。通常子树被称作&quot;左子树&quot;（left subtree）和&quot;右子树&quot;（right subtree）。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;一棵深度为k，且有2^k-1个节点的二叉树，称为&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;满二叉树&lt;/strong&gt;，这种树的特点是每一层上的节点数都是最大节点数。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.1 二叉树基本形态&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;二叉树是递归定义的，其结点有左右子树之分，逻辑上二叉树有五种基本形态：&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/ce3accb7-b2b8-412f-9aa6-33be7af3a070.gif&quot; /&gt;&lt;br/&gt;
(1)空二叉树——如图(a)；&lt;br/&gt;
(2)只有一个根结点的二叉树——如图(b)；&lt;br/&gt;
(3)只有左子树——如图(c)；&lt;br/&gt;
(4)只有右子树——如图(d)；&lt;br/&gt;
(5)完全二叉树——如图(e)。&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;注意：尽管二叉树与树有许多相似之处，但二叉树不是树的特殊情形。&lt;/strong&gt;&lt;br/&gt;
树和二叉树有两个主要差别：&lt;/p&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;树中结点的最大度数没有限制，而二叉树结点的最大度数为2；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;树的结点无左、右之分，而二叉树的结点有左、右之分。&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.2 二叉树类型&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;(1)&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;完全二叉树&lt;/strong&gt;——若设二叉树的高度为h，除第 h 层外，其它各层 (1～h-1) 的结点数都达到最大个数，第h层有叶子结点，并且叶子结点都是从左到右依次排布，这就是完全二叉树。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;(2)&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;满二叉树&lt;/strong&gt;——除了叶结点外每一个结点都有左右子叶且叶子结点都处在最底层的二叉树。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;(3)&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;平衡二叉树&lt;/strong&gt;——平衡二叉树又被称为AVL树（区别于AVL算法），它是一棵二叉排序树，且具有以下性质：它是一棵空树或它的左右两个子树的高度差的绝对值不超过1，并且左右两个子树都是一棵平衡二叉树。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.3 树的相关术语&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;结点的度：结点子树的个数&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;树的度： 树中最大的结点度。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;叶子结点：也叫终端结点，是度为 0 的结点；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;分枝结点：度不为0的结点；&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.4 二叉树性质&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;(1) 在非空二叉树中，第i层的结点总数不超过 &lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;2^(i-1)&lt;/code&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;(2) 深度为h的二叉树最多有 &lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;2^h - 1&lt;/code&gt; 个结点,最少有h个结点&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;(3) 对于任意一棵二叉树，如果其叶子结点数为N0，而度数为2的结点总数为N2，则N0=N2+1；&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;(4)给定N个节点，能构成h(N)种不同的二叉树。&lt;br/&gt;
h(N)为卡特兰数的第N项。&lt;code style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;&quot;&gt;h(n)=C(2*n，n)/(n+1)&lt;/code&gt;&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;1.5 二叉树遍历&lt;/h4&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;先序遍历&lt;br/&gt;
首先访问根，再先序遍历左（右）子树，最后先序遍历右（左）子树&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;中序遍历&lt;br/&gt;
首先中序遍历左（右）子树，再访问根，最后中序遍历右（左）子树&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;后序遍历&lt;br/&gt;
首先后序遍历左（右）子树，再后序遍历右（左）子树，最后访问根&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;层次遍历&lt;br/&gt;
即按照层次访问，通常用队列来做。访问根，访问子女，再访问子女的子女（越往后的层次越低）（两个子女的级别相同）&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;2. 完全二叉树&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.1 完全二叉树定义&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/db46dcc7-a4f3-44b9-ac7f-68c8ddb85049.jpg&quot; /&gt;&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; color: #333; margin: 0;&quot;&gt;若设二叉树的深度为h，除第 h 层外，其它各层 (1～h-1) 的结点数都达到最大个数，&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;第 h 层所有的结点都连续集中在最左边&lt;/strong&gt;，这就是完全二叉树。&lt;/p&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; color: #333; margin: 0;&quot;&gt;完全二叉树是由满二叉树而引出来的。对于深度为K的，有n个结点的二叉树，当且仅当其每一个结点都与深度为K的满二叉树中编号从1至n的结点一一对应时称之为完全二叉树。&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;(1)所有的叶结点都出现在第k层或k-l层（层次最大的两层）&lt;br/&gt;
(2)对任一结点，如果其右子树的最大层次为L，则其左子树的最大层次为L或L+l。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.2 完全二叉树性质&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;假设n0是度为0的结点总数（即叶子结点数），n1是度为1的结点总数， n2是度为2的结点总数，  n是结点总数 则 ：&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;n0=n/2，其中n为奇数时（n1=0）向上取整；n为偶数时（n1=1）。可根据完全二叉树的结点总数计算出叶子结点数。&lt;/strong&gt;&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.3 完全二叉树特点&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;完全二叉树的特点是：&lt;br/&gt;
(1）只允许最后一层有空缺结点且空缺在右边，即叶子结点只能在层次最大的两层上出现；&lt;br/&gt;
(2）对任一结点，如果其右子树的深度为j，则其左子树的深度必为j或j+1。 即度为1的点只有1个或0个&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.4 完全二叉树存储&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;出于简便起见,完全二叉树通常采用数组而不是链表存储&lt;br/&gt;
其存储结构如下:&lt;br/&gt;
var tree:array[1..n]of longint;{n:integer;n&gt;=1}&lt;br/&gt;
对于tree[i]，有如下特点：&lt;br/&gt;
（1）若i为奇数且i&gt;1，那么tree的左兄弟为tree[i-1]；&lt;br/&gt;
（2）若i为偶数且i&lt;n，那么tree的右兄弟为tree[i+1]；&lt;br/&gt;
（3）若i&gt;1，tree的父亲节点为tree[i/2]；&lt;br/&gt;
（4）若2* i&lt;=n，那么tree的左孩子为tree[2* i];若2* i+1&lt;=n,那么tree的右孩子为tree[2* i+1]；&lt;br/&gt;
（5）若i&gt;n/2,那么tree[i]为叶子结点（对应于（3））；&lt;br/&gt;
（6）若i&lt;(n-1)/2.那么tree[i]必有两个孩子（对应于（4））。&lt;br/&gt;
（7）满二叉树一定是完全二叉树，完全二叉树不一定是满二叉树。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.5 完全二叉树判定&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;判断一棵树是否是完全二叉树的思路&lt;br/&gt;
1&gt;如果树为空，则直接返回错&lt;br/&gt;
2&gt;如果树不为空：层序遍历二叉树&lt;br/&gt;
　　      2.1&gt;如果一个结点左右孩子都不为空，则pop该节点，将其左右孩子入队列；&lt;br/&gt;
　　      2.1&gt;如果遇到一个结点，左孩子为空，右孩子不为空，则该树一定不是完全二叉树；&lt;br/&gt;
　　      2.2&gt;如果遇到一个结点，左孩子不为空，右孩子为空；或者左右孩子都为空；则该节点之后的队列中的结点都为叶子节点；该树才是完全二叉树，否则就不是完全二叉树；&lt;/p&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;3. 满二叉树&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.1 满二叉树定义&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; color: #333; margin: 0;&quot;&gt;对于国内的满二叉树&lt;/p&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;一个层数为k 的满二叉树总结点数为：2^k - 1,因此满二叉的结点树一定是奇数个。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;第i层上的结点数为：2^i -1 ;&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;一个层数为k的满二叉树的叶子结点个数（也就是最后一层）:2^(k-1) ;&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/011640c0-e095-4085-9983-6dd5d106869a.jpg&quot; /&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; color: #333; margin: 0;&quot;&gt;对于国外的满二叉树&lt;br/&gt;
满二叉树的任意节点，要么度为0，要么度为2.换个说法即要么为叶子结点，要么同时具有左右孩子。&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/fdc39200-b9a1-4b20-9997-f97dc2396a43.jpg&quot; /&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;4. 堆&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;4.1 堆的概念&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;堆是具有以下性质的完全二叉树：&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;每个结点的值都大于或等于其左右孩子结点的值，称为大顶堆；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;或者每个结点的值都小于或等于其左右孩子结点的值，称为小顶堆&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/91db10fa-6d65-417a-9088-d007c6ae2b72.jpg&quot; /&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;在一个堆有序的二叉树中，父节点的位置是K/2,它的两个子节点的位置是2k,2k+1。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;4.2 堆的实现&lt;/h4&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;
&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//最大堆&lt;/span&gt;
&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;MaxPQ&lt;/span&gt; &lt;/span&gt;{
    &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;private&lt;/span&gt; List&lt;Integer&gt; arr;      &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//定义一个数组&lt;/span&gt;
    &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;private&lt;/span&gt;  &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; N;                   &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//定义队列中的元素个数&lt;/span&gt;

    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;MaxPQ&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{
        arr = &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;new&lt;/span&gt; ArrayList();
        arr.add(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1&lt;/span&gt;);
        N = &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0&lt;/span&gt;;
    }

    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;boolean&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;isEmpty&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{                   &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//方法，返回队列是否为空&lt;/span&gt;
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt; N == &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;0&lt;/span&gt;;                                              
    }

    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;size&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{                                 &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//方法，返回队列中元素的个数&lt;/span&gt;
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt; N;
    }

    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;inSert&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; number)&lt;/span&gt; &lt;/span&gt;{       &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//添加方法，添加元素到结合末尾，并且使用上浮方法到指定的位置&lt;/span&gt;
        arr.add(number);
        swim(++N);
    }

    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;deleteMax&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{                &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//删除方法，删除最大元素并把最小的元素放到第一个，然后使用下浮方法&lt;/span&gt;
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; max = arr.get(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1&lt;/span&gt;);
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; min  = arr.get(N);
        arr.set(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1&lt;/span&gt;, min);
        arr.remove(N--);
        sink(&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1&lt;/span&gt;);
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt; max;
    }
    &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//上浮&lt;/span&gt;
    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;swim&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; N)&lt;/span&gt; &lt;/span&gt;{
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;while&lt;/span&gt;(N &gt; &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1&lt;/span&gt; &amp;&amp; (arr.get(N/&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;2&lt;/span&gt;) &lt; arr.get(N))){
            &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; max = arr.get(N);
            &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; min = arr.get(N/&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;2&lt;/span&gt;);
            arr.set(N,min );
            arr.set(N/&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;2&lt;/span&gt;, max);
            N = N/&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;2&lt;/span&gt;;
        }
    }
    &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//下沉&lt;/span&gt;
    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;sink&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; number)&lt;/span&gt; &lt;/span&gt;{
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;while&lt;/span&gt;(number*&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;2&lt;/span&gt; &lt;= N) {
            &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; index = number*&lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;2&lt;/span&gt;;
            &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;if&lt;/span&gt;(index &lt; N &amp;&amp; (arr.get(index) &lt; arr.get(index + &lt;span style=&quot;color: #b8d7a3; line-height: 160%; box-sizing: content-box;&quot;&gt;1&lt;/span&gt;))) {
                index++;
            }
            &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;if&lt;/span&gt;(!(arr.get(number) &lt; arr.get(index))) {
                &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;break&lt;/span&gt;;
            }
            &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; max = arr.get(index);
            &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;int&lt;/span&gt; min = arr.get(number);
            arr.set(number, max);
            arr.set(index, min);
            number = index;
        }

    }

    &lt;span style=&quot;color: #9b9b9b; line-height: 160%; box-sizing: content-box;&quot;&gt;@Override&lt;/span&gt;
    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; String &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;toString&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;MaxPQ [arr=&quot;&lt;/span&gt; + arr + &lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;, N=&quot;&lt;/span&gt; + N + &lt;span style=&quot;color: #d69d85; line-height: 160%; box-sizing: content-box;&quot;&gt;&quot;]&quot;&lt;/span&gt;;
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;5. 二叉查找树(排序树)(Binary Search Tree，BST)&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;二叉排序树或者是一棵空树，或者是具有下列性质的二叉树：&lt;/p&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;（1）若左子树不空，则左子树上所有结点的值均小于它的根节点点的值；
（2）若右子树不空，则右子树上所有结点的值均大于或等于它的根结点的值；
（3）左、右子树也分别为二叉排序树；
（4）没有键值相等的节点。
&lt;/code&gt;&lt;/pre&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;例子：&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;a href=&quot;https://www.nowcoder.com/questionTerminal/dfdfc7f18a234a768aabd4021eda3652&quot; style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;二叉查找树例题&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;&lt;a href=&quot;https://blog.csdn.net/javazejian/article/details/53727333&quot; style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;二叉树查找树的详细解析&lt;/a&gt;&lt;/h4&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;6. 平衡二叉树(AVL树)&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;6.1 平衡二叉树定义&lt;/h4&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;对于一般的二叉搜索树（Binary Search Tree），其期望高度（即为一棵平衡树时）为logN，其各操作的时间复杂度（O(logN)）同时也由此而决定。但是，在某些极端的情况下（如在插入的序列是有序的时），二叉搜索树将退化成近似链或链，此时，其操作的时间复杂度将退化成线性的，即O(n)。&lt;/p&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;为了解决这个问题，要加上一个称为平衡的附加结构条件即：任何结点的深度不得过深&lt;br/&gt;
（子树高度相差不超过1），就是平衡二叉树（Balanced Binary Tree），它是G.M. Adelson-Velsky 和 E.M. Landis在1962年在论文中发表的，因此又叫AVL树。&lt;/p&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;AVL树只是实现平衡二叉树的一种方法，它还有很多的其他实现方法如红黑树、替罪羊树、Treap、伸展树等&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;6.2  平衡二叉树性质&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;它是一棵空树或它的左右两个子树的高度差的绝对值不超过1，并且左右两个子树都是一棵平衡二叉树。这个差值也称为平衡因子（其取值可以是1，0，-1，平衡因子是某个结点左右子树层数的差值)&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;6.3 平衡二叉树的设计&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; color: #333; margin: 0;&quot;&gt;理解了平衡二叉树的概念后，我们在思考一下，那些操作可能引起平衡发生变化呢？&lt;br/&gt;
显然只有那些引起结点数量变化的操作才可能导致平衡被改变，也就是删除和插入操作了。&lt;/p&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; color: #333; margin: 0;&quot;&gt;实际上也总是可以通过对树进行简单的修复来让其重新恢复到平衡，而这样的简单操作我们就称之为旋转，当然旋转也有单旋转和双旋转之分。&lt;/p&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; color: #333; margin: 0;&quot;&gt;无论是插入还是删除，只有那些从插入点或者删除点到根结点的路径上的结点的平衡才有可能被改变，因为只有这些结点的子树才可能发生变化，所以最终也只需针对这些点进行平衡修复操作即可。&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;如何通过旋转来修复一棵失衡的二叉树，这里假设结点X是失衡点，它必须重新恢复平衡，由于任意结点的孩子结点最多有两个，而且导致失衡的必要条件是X结点的两棵子树高度差为2(大于1)，因此一般只有以下4种情况可能导致X点失去平衡：&lt;br/&gt;
① 在结点X的左孩子结点的左子树中插入元素&lt;br/&gt;
② 在结点X的左孩子结点的右子树中插入元素&lt;br/&gt;
③ 在结点X的右孩子结点的左子树中插入元素&lt;br/&gt;
④ 在结点X的右孩子结点的右子树中插入元素&lt;br/&gt;
以上4种情况，其中第①情况和第④情况是对称的，可以通过&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;单旋转&lt;/strong&gt;来解决，而第②种情况和第③情况是对称的，需要&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;双旋转&lt;/strong&gt;来解决。&lt;/p&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;6.3.1 左左单旋转(LL)情景①分析&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;在结点X的左孩子结点的左子树中插入元素&lt;/strong&gt;&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/1b048f56-8e11-479d-9839-2e426451d878.png&quot; /&gt;&lt;/p&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;6.3.2 右右单旋转(RR)情景④分析&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;在结点X的右孩子结点的右子树中插入元素&lt;/strong&gt;&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/797c2c03-3243-4750-aebf-60bd924826dd.png&quot; /&gt;&lt;/p&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;6.3.3 左右双旋转(LR)情景②分析&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;在结点X的左孩子结点的右子树中插入元素&lt;/strong&gt;&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/d5a66920-e3ed-4334-bdb9-ef0f7d4dd380.png&quot; /&gt;&lt;/p&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;6.3.4 右左双旋转(RL)情景③分析&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;在结点X的右孩子结点的左子树中插入元素&lt;/strong&gt;&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/07f321ba-5398-4001-ae9d-3c192c7f2f33.png&quot; /&gt;&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;&lt;a href=&quot;https://blog.csdn.net/javazejian/article/details/53892797&quot; style=&quot;line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;&quot;&gt;平衡二叉树详细解析&lt;/a&gt;&lt;/h4&gt;
&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;二 . 红黑树&lt;/h2&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;1. 红黑树简介&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;红黑树是每个节点都带有颜色属性的二叉查找树，颜色或红色或黑色。在二叉查找树强制一般要求以外，对于任何有效的红黑树我们增加了如下的额外要求:&lt;/p&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;节点是红色或黑色。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;根节点是黑色。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;每个叶子节点都是黑色的空节点（NIL节点）。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;每个红色节点的两个子节点都是黑色。(从每个叶子到根的所有路径上不能有两个连续的红色节点)&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;从任一节点到其每个叶子的所有路径都包含相同数目的黑色节点。&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/8dd8f54f-d736-49a0-8b05-40f53351c934.jpg&quot; /&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;2. 红黑树的修正&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;变色、左旋、右旋是红黑树在二叉树上的扩展操作，同时也是基于这三个操作才能遵守红黑树的五个特性。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.1 左旋&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/7907fc1e-dc0e-4829-b883-072a2bc13600.jpg&quot; /&gt;&lt;/p&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;    &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;/*
     * 左旋做了三件事：

     * 1. 将y的左子节点赋给x的右子节点,并将x赋给y左子节点的父节点(y左子节点非空时)

     * 2. 将x的父节点p(非空时)赋给y的父节点，同时更新p的子节点为y(左或右)

     * 3. 将y的左子节点设为x，将x的父节点设为y

     */&lt;/span&gt;
    &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;leftRotate&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(RBNode&lt;T&gt; x)&lt;/span&gt; &lt;/span&gt;{
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;if&lt;/span&gt; (x == &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;null&lt;/span&gt;) &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt;;
        &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//1. 将y的左子节点赋给x的右子节点,并将x赋给y左子节点的父节点(y左子节点非空时)&lt;/span&gt;
        RBNode&lt;T&gt; y = x.right;
        x.right = y.left;
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;if&lt;/span&gt; (y.left != &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;null&lt;/span&gt;) {
            y.left.parent = x;
        }
        &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//2. 将x的父节点p(非空时)赋给y的父节点，同时更新p的子节点为y(左或右)&lt;/span&gt;
        y.parent = x.parent;
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;if&lt;/span&gt; (x.parent == &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;null&lt;/span&gt;) {
            &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;this&lt;/span&gt;.mRoot = y;
        } &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;else&lt;/span&gt; {
            &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;if&lt;/span&gt; (x == x.parent.left) {
                x.parent.left = y;
            } &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;else&lt;/span&gt; {
                x.parent.right = y;
            }
        }
        &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//3. 将y的左子节点设为x，将x的父节点设为y&lt;/span&gt;
        y.left = x;
        x.parent = y;
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;2.2 右旋&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/8cd8bedd-e9dd-48fd-a698-5929a1693a38.jpg&quot; /&gt;&lt;/p&gt;
&lt;pre style=&quot;line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;&quot;&gt;&lt;code style=&quot;display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;/*      右旋做了三件事：
     * 1. 将x的右子节点赋给y的左子节点,并将y赋给x右子节点的父节点(x右子节点非空时)
     * 2. 将y的父节点p(非空时)赋给x的父节点，同时更新p的子节点为x(左或右)
     * 3. 将x的右子节点设为y，将y的父节点设为x
     */&lt;/span&gt;
   &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;&lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;rightRotate&lt;/span&gt;&lt;span style=&quot;color: #dcdcdc; line-height: 160%; box-sizing: content-box;&quot;&gt;(RBNode&lt;T&gt; y)&lt;/span&gt; &lt;/span&gt;{
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;if&lt;/span&gt; (y == &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;null&lt;/span&gt;) &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;return&lt;/span&gt;;
        &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//1. 将x的右子节点赋给y的左子节点,并将y赋给x右子节点的父节点(x右子节点非空时)&lt;/span&gt;
        RBNode&lt;T&gt; x = y.left;
        y.left = x.right;
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;if&lt;/span&gt; (x.right != &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;null&lt;/span&gt;) {
            x.right.parent = y;
        }
        &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//2. 将y的父节点p(非空时)赋给x的父节点，同时更新p的子节点为x(左或右)&lt;/span&gt;
        x.parent = y.parent;
        &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;if&lt;/span&gt; (y.parent == &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;null&lt;/span&gt;) {
            &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;this&lt;/span&gt;.mRoot = x;
        } &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;else&lt;/span&gt; {
            &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;if&lt;/span&gt; (y == y.parent.left) {
                y.parent.left = x;
            } &lt;span style=&quot;color: #569cd6; line-height: 160%; box-sizing: content-box;&quot;&gt;else&lt;/span&gt; {
                y.parent.right = x;
            }
        }
        &lt;span style=&quot;color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;&quot;&gt;//3. 将x的右子节点设为y，将y的父节点设为x&lt;/span&gt;
        x.right = y;
        y.parent = x;
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;3. 红黑树节点的添加&lt;/h3&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;红黑树的第 5 条特征规定，任一节点到它子树的每个叶子节点的路径中都包含同样数量的黑节点。也就是说当我们往红黑树中插入一个黑色节点时，会违背这条特征。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;同时第 4 条特征规定红色节点的左右孩子一定都是黑色节点，当我们给一个红色节点下插入一个红色节点时，会违背这条特征。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;因此我们需要在插入黑色节点后进行结构调整，保证红黑树始终满足这 5 条特征。&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.1  红黑树插入后节点的调整思想:&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;插入黑色节点的时候担心违背第5条，插入红色节点时担心违背第4条，所以我们将将&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;插入的节点改为红色，然后判断插入的节点的父亲是不是红色&lt;/strong&gt;，是的话进行修改调整（变色、左旋、右旋）。同时在调整的过程中我们需要遵守5条特性。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;新插入的节点是红色的，插入修复操作如果遇到父节点的颜色为黑则修复操作结束&lt;/strong&gt;。也就是说，&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;只有在父节点为红色节点的时候是需要插入修复操作的&lt;/strong&gt;。&lt;br/&gt;
插入修复操作分为以下的三种情况，而且新插入的节点的父节点都是红色的：&lt;/p&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;叔叔节点也为红色。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;叔叔节点为空，且祖父节点、父节点和新节点处于一条斜线上。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;叔叔节点为空，且祖父节点、父节点和新节点不处于一条斜线上。&lt;/li&gt;
&lt;/ol&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;3.1.1 插入操作-case 1(叔叔节点也为红色)&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/10517f91-8106-4bde-8205-f2b10f8bc1f3.jpg&quot; /&gt;&lt;br/&gt;
&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;叔叔节点也为红色。&lt;/strong&gt;&lt;br/&gt;
case 1的操作是将 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;父节点和叔叔节点&lt;/strong&gt; 与 &lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;祖父节点&lt;/strong&gt; 的&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;颜色互换&lt;/strong&gt;，这样就符合了RBTRee的定义。即维持了高度的平衡，修复后颜色也符合RBTree定义的第三条和第四条。下图中，操作完成后A节点变成了新的节点。如果A节点的父节点不是黑色的话，则继续做修复操作。&lt;/p&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;3.1.2 插入操作-case 2&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/047f18a2-5281-460a-ac15-d66006d7ca6d.jpg&quot; /&gt;&lt;br/&gt;
&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;叔叔节点为空，且祖父节点、父节点和新节点处于一条斜线上。&lt;/strong&gt;&lt;br/&gt;
case 2的操作是：&lt;/p&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;B和C都是左节点，将B节点进行右旋操作，并且和父节点A互换颜色。通过该修复操作RBTRee的高度和颜色都符合红黑树的定义。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;如果B和C节点都是右节点的话，只要将操作变成B节点左旋就可以了。&lt;/li&gt;
&lt;/ol&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;3.1.3 插入操作-case 3&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/5fc67456-0d73-44cc-be2f-111054b2636e.jpg&quot; /&gt;&lt;br/&gt;
&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;叔叔节点为空，且祖父节点、父节点和新节点不处于一条斜线上。&lt;/strong&gt;&lt;br/&gt;
case 3的操作是：&lt;/p&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;C是右节点，将C节点进行左旋，这样就从case 3转换成case 2了，然后针对case 2进行操作处理就行了。case2操作C节点做了一个右旋操作和颜色互换来达到目的。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;如果C是左节点，将C节点进行右旋，转换成case2，再左旋就可以了。&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;4. 红黑树节点的删除&lt;/h3&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;如果删除节点的左孩子和右孩子不同时为null，那么只需要让其子树继承删除该节点的位置&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;如果删除的节点是叶子节点，我们直接进行调整；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;假如删除节点的左右孩子都不是null，需要后继节点替换被删除的节点和值和颜色，这样才不会引起红黑树平衡的破坏，只需要对 后继节点删除后进行调整，这样我们就回归处理情况 1 和 2 的状态；
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;后继节点为左子树最右边的子叶节点&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;后继节点为右子树最左边的叶子节点；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;如果需要删除的节点颜色为红色，那么红黑树的结构不被破坏，也就不需要进行调整。&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;如果我们判断删除节点的颜色为黑色，那么就进行调整；&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;4.1 红黑树删除之节点调整&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;调整思想：&lt;br/&gt;
为了保证删除节点的父节点左右两边黑色节点数一致，需要重点关注父节点没删除的那一边节点是不是黑色。&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;如果删除后父亲节点另一边比删除的一边黑色多，就要想办法搞到平衡。
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;1、把父亲节点另一边（即删除节点的兄弟树）其中一个节点弄成红色，也少了一个黑色。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;2、或者把另一边多的节点（染成黑色）转过来一个&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr style=&quot;line-height: 160%; box-sizing: content-box; border-top: 1px solid #eee; margin: 16px 0;&quot;/&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;删除修复操作是针对删除黑色节点才有的&lt;/strong&gt;，当黑色节点被删除后会让整个树不符合RBTree的定义的第四条。&lt;/li&gt;
&lt;/ul&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;当前节点是黑色的，且兄弟节点是红色的（那么父节点和兄弟节点的子节点肯定是黑色的）；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;当前节点是黑色的，且兄弟节点是黑色的，&lt;br/&gt;
1）、兄弟节点的两个子节点均为黑色的；&lt;br/&gt;
2）、兄弟节点的左子节点是红色，右子节点时黑色的；&lt;br/&gt;
3）、兄弟节点的右子节点是红色，左子节点任意颜色；&lt;/li&gt;
&lt;/ol&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.1.1 删除操作-case 1&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/0cb5499f-7521-49b4-930e-172fa42df8db.jpg&quot; /&gt;&lt;br/&gt;
&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;待删除的节点的兄弟节点是红色的节点。&lt;/strong&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;将父节点涂红，将兄弟节点涂黑，然后将当前节点的父节点进行支点左旋。&lt;br/&gt;
case 1这样转换之后就会变成后面的case 2，case 3，或者case 4进行处理了。&lt;/p&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.1.2 删除操作-case 2&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/a7df5f53-ed76-4bf3-91ed-65b04883b96d.jpg&quot; /&gt;&lt;br/&gt;
&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;待删除的节点的兄弟节点是黑色的节点，且兄弟节点的子节点都是黑色的。&lt;/strong&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;将兄弟节点涂红，将当前节点指向其父节点，将其父节点指向当前节点的祖父节点，继续往树根递归判断以及调整；&lt;/p&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.1.3 删除操作-case 3&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/6362ebe6-440b-4123-b108-0dbbac880159.jpg&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;待调整的节点的兄弟节点是黑色的节点，且和兄弟节点在一条斜线上的子节点也是黑色，另一个子节点是红色。&lt;/strong&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;把当前节点的兄弟节点涂红，把兄弟节点的左子节点涂黑，然后以兄弟节点作为支点做右旋操作。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;case 3的删除操作是一个中间步骤，它的目的是将左边的红色节点借调过来，这样就可以转换成case 4&lt;/p&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;4.1.4 删除操作-case 4&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/988225d6-f979-4d6a-b48a-238d1d9bb043.jpg&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;待调整的节点的兄弟节点是黑色的节点，且和兄弟节点在一条斜线上的子节点是红色，另一个子节点任意&lt;/strong&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;把兄弟节点涂成父节点的颜色，再把父节点涂黑，把兄弟节点的右子节点涂黑，然后以当前节点的父节点为支点做左旋操作。&lt;/p&gt;
&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;三 . B树、B+树、B*树&lt;/h2&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;3.1 B树(B-树)&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.1.1 B树简介&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;B-树是一种多路搜索树（并不一定是二叉的）&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;1970年，R.Bayer和E.mccreight提出了一种适用于外查找的树，它是一种平衡的多叉树，称为B树（或B-树、B_树）。&lt;/li&gt;
&lt;/ul&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;B-Tree的接点结构B-tree中，每个&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;结点&lt;/strong&gt;包含：&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;本结点所含关键字的个数；&lt;br/&gt;
指向父结点的指针；&lt;br/&gt;
关键字；&lt;br/&gt;
指向子结点的指针数组；&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/7bf500f5-bbc5-4e20-9cd8-5656e610ce61.jpg&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;一棵m阶B树(balanced tree of order m)是一棵平衡的m路搜索树。它或者是空树，或者是满足下列性质的树：&lt;br/&gt;
1、根结点至少有两个子女；&lt;br/&gt;
2、每个非根节点所包含的关键字个数 j 满足：m/2 - 1 &lt;= j &lt;= m - 1；&lt;br/&gt;
3、除根结点以外的所有结点（不包括叶子结点）的度数正好是关键字总数加1，故内部子树个数 k 满足：m/2 &lt;= k &lt;= m ；&lt;br/&gt;
4、所有的叶子结点都位于同一层。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.1.2 B树特点&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;是一种多路搜索树（并不是二叉的）：&lt;/p&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;定义任意非叶子结点最多只有M个儿子；且M&gt;2；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;根结点的儿子数为[2, M]；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;除根结点以外的非叶子结点的儿子数为[M/2, M]；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;每个结点存放至少M/2-1（取上整）和至多M-1个关键字；（至少2个关键字）&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;非叶子结点的关键字个数=指向儿子的指针个数-1；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;非叶子结点的关键字：K[1], K[2], …, K[M-1]；且K[i] &lt; K[i+1]；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;非叶子结点的指针：P[1], P[2], …, P[M]；其中P[1]指向关键字小于K[1]的子树，P[M]指向关键字大于K[M-1]的子树，其它P[i]指向关键字属于(K[i-1], K[i])的子树；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;所有叶子结点位于同一层；&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.1.3 B树的查找&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/90d33d44-16aa-4bdb-a1a4-71b6b453bfb9.png&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;在B-树中查找给定关键字的方法类似于二叉排序树上的查找。不同的是在每个结点上确定向下查找的路径不一定是二路而是keynum+1路的。&lt;br/&gt;
对&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;结点内的存放有序关键字序列&lt;/strong&gt;的向量key[l..keynum] 用&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;顺序查找或折半查找方法查找&lt;/strong&gt;。&lt;/p&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;若在某结点内找到待查的关键字K，则返回该结点的地址及K在key[1..keynum]中的位置；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;否则，确定K在某个key[i]和key[i+1]之间结点后，从磁盘中读son[i]所指的结点继续查找。直到在某结点中查找成功；或直至找到叶结点且叶结点中的查找仍不成功时，查找过程失败。&lt;/li&gt;
&lt;/ol&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;查找操作的时间开销&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;B-树上的查找有两个基本步骤：&lt;/p&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;在B-树中查找结点，该查找涉及读盘DiskRead操作，属外查找；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;在结点内查找，该查找属内查找。&lt;/li&gt;
&lt;/ol&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;查找操作的时间为：&lt;/p&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;外查找的读盘次数不超过树高h，故其时间是O(h)；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;内查找中，每个结点内的关键字数目keynum&lt;m(m是B-树的阶数)，故其时间为O(nh)。&lt;/li&gt;
&lt;/ol&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;注意：&lt;/p&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;实际上外查找时间可能远远大于内查找时间。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;B-树作为数据库文件时，打开文件之后就必须将根结点读人内存，而直至文件关闭之前，此根一直驻留在内存中，故查找时可以不计读入根结点的时间。&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.1.4 B树的插入&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;插入一个元素时：&lt;/p&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;首先判断在B树中是否存在，如果不存在，即在叶子结点处结束，然后在叶子结点中插入该新的元素&lt;/li&gt;
&lt;/ol&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;注意：&lt;br/&gt;
1.1 如果叶子结点空间足够，这里需要向右移动该叶子结点中大于新插入关键字的元素，&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;1.2 如果叶子节点空间满了以致没有足够的空间去添加新的元素，则将该结点进行&quot;分裂&quot;，将一半数量的关键字元素分裂到新的其相邻右结点中，中间关键字元素上移到父结点中（当然，如果父结点空间满了，也同样需要&quot;分裂&quot;操作），而且当结点中关键元素向右移动了，相关的指针也需要向右移。&lt;br/&gt;
1.3 如果在根结点插入新元素，空间满了，则进行分裂操作，这样原来的根结点中的中间关键字元素向上移动到新的根结点中，因此导致树的高度增加一层。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.1.5 B树的删除&lt;/h4&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;首先查找B树中需删除的元素,如果该元素在B树中存在，则将该元素在其结点中进行删除，&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;如果删除该元素后，首先判断该元素是否有左右孩子结点，如果有，则上移孩子结点中的某相近元素到父节点中，然后是移动之后的情况；如果没有，直接删除后，移动之后的情况。&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;3.2 B+树&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.2.1 B+树简介&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;B+ 树是一种树数据结构，是一个n叉树，每个节点通常有多个孩子。&lt;br/&gt;
一棵B+树包含根节点、内部节点和叶子节点。根节点可能是一个叶子节点，也可能是一个包含两个或两个以上孩子节点的节点。&lt;/p&gt;
&lt;h5 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 16px; color: #333;&quot;&gt;B+树用途&lt;/h5&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;B+ 树通常用于数据库和操作系统的文件系统中。NTFS, ReiserFS, NSS, XFS, JFS, ReFS 和BFS等文件系统都在使用B+树作为元数据索引。B+ 树的特点是能够保持数据稳定有序，其插入与修改拥有较稳定的对数时间复杂度。B+ 树元素自底向上插入。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.2.2 B+树定义&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;B+树是应文件系统所需而出的一种B-树的变型树。&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/f4b81940-c17e-4625-b0a7-849a6cc69cdc.jpg&quot; /&gt;&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;一棵m阶的B+树和m阶的B-树的差异在于：&lt;br/&gt;
1.有n棵子树的结点中含有n个关键字，每个&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;关键字不保存数据，只用来索引&lt;/strong&gt;，所有&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;数据都保存在叶子节点&lt;/strong&gt;。&lt;br/&gt;
2.所有的叶子结点中包含了全部关键字的信息，及指向含这些关键字记录的指针，且&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;叶子结点本身依关键字的大小自小而大顺序链接&lt;/strong&gt;。&lt;br/&gt;
3.所有的非终端结点可以看成是索引部分，结点中仅含其子树（根结点）中的最大（或最小）关键字。 &lt;br/&gt;
通常在B+树上有两个头指针，一个指向根结点，一个指向关键字最小的叶子结点。&lt;/p&gt;
&lt;hr style=&quot;line-height: 160%; box-sizing: content-box; border-top: 1px solid #eee; margin: 16px 0;&quot;/&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;B+树与B-树的不同&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;B+树是B-树的变体，也是一种多路搜索树：&lt;/p&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;定义基本与B-树同，除了：&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;叶子结点的子树指针与关键字个数相同；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;叶子结点的子树指针P[i]，指向关键字值属于[K[i], K[i+1])的子树（B-树是开区间）；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;为&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;所有叶子结点增加一个链指针&lt;/strong&gt;；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;所有关键字都在叶子结点出现；&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.2.3 B+树的特性：&lt;/h4&gt;
&lt;ol style=&quot;line-height: 160%; box-sizing: content-box; display: block; padding-left: 30px; margin: 6px 0 10px; color: #333; list-style-type: decimal;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;所有关键字都出现在叶子结点的链表中（稠密索引），且链表中的关键字恰好是有序的；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;不可能在非叶子结点命中；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;非叶子结点相当于是叶子结点的索引（稀疏索引），叶子结点相当于是存储（关键字）数据的数据层；&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box;&quot;&gt;更适合文件索引系统；&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.2.4 B+树 vs B树&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;为什么说B+-tree比B 树更适合实际应用中操作系统的文件索引和数据库索引？&lt;/p&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;B+-tree的磁盘读写代价更低&lt;br/&gt;
B+-tree的内部结点并没有指向关键字具体信息的指针。因此其内部结点相对B 树更小。如果把所有同一内部结点的关键字存放在同一盘块中，那么盘块所能容纳的关键字数量也越多。一次性读入内存中的需要查找的关键字也就越多。相对来说IO读写次数也就降低了。&lt;br/&gt;
举个例子，假设磁盘中的一个盘块容纳16bytes，而一个关键字2bytes，一个关键字具体信息指针2bytes。一棵9阶B-tree(一个结点最多8个关键字)的内部结点需要2个盘快。而B+ 树内部结点只需要1个盘快。当需要把内部结点读入内存中的时候，B 树就比B+ 树多一次盘块查找时间(在磁盘中就是盘片旋转的时间)。&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;B+-tree的查询效率更加稳定&lt;br/&gt;
由于非终结点并不是最终指向文件内容的结点，而只是叶子结点中关键字的索引。所以任何关键字的查找必须走一条从根结点到叶子结点的路。所有关键字查询的路径长度相同，导致每一个数据的查询效率相当。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;3.3 B*树&lt;/h3&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.3.1 B*树简介&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;是B+树的变体，在B+树的非根和非叶子结点再增加指向兄弟的指针；&lt;br/&gt;
B*树定义了非叶子结点关键字个数至少为(2/3)*M，即块的最低使用率为2/3（代替B+树的1/2）；&lt;br/&gt;
&lt;img src=&quot;https://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/2306ffe6-b58e-4a04-bd0b-5bb567c5604a.jpg&quot; /&gt;&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;3.3.2 B*树 vs B+树&lt;/h4&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; color: #333; margin: 0;&quot;&gt;B+树的分裂：&lt;br/&gt;
当一个结点满时，分配一个新的结点，并将原结点中1/2的数据复制到新结点，最后在父结点中增加新结点的指针；B+树的分裂只影响原结点和父结点，而不会影响兄弟结点，所以它不需要指向兄弟的指针；&lt;/p&gt;
&lt;/li&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; color: #333; margin: 0;&quot;&gt;B*树的分裂：&lt;br/&gt;
当一个结点满时，如果它的下一个兄弟结点未满，那么将一部分数据移到兄弟结点中，再在原结点插入关键字，最后修改父结点中兄弟结点的关键字（因为兄弟结点的关键字范围改变了）；如果兄弟也满了，则在原结点与兄弟结点之间增加新结点，并各复制1/3的数据到新结点，最后在父结点增加新结点的指针；&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;所以，B*树分配新结点的概率比B+树要低，空间使用率更高；&lt;/p&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;3.4 小结：&lt;/h3&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;B-树：&lt;br/&gt;
多路搜索树，每个结点存储M/2到M个关键字，非叶子结点存储指向关键字范围的子结点；&lt;br/&gt;
所有关键字在整颗树中出现，且只出现一次，非叶子结点可以命中；&lt;/li&gt;
&lt;/ul&gt;
&lt;hr style=&quot;line-height: 160%; box-sizing: content-box; border-top: 1px solid #eee; margin: 16px 0;&quot;/&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;B+树：在B-树基础上，为叶子结点增加链表指针，所有关键字都在叶子结点中出现，非叶子结点作为叶子结点的索引；&lt;br/&gt;
B+树总是到叶子结点才命中；&lt;/li&gt;
&lt;/ul&gt;
&lt;hr style=&quot;line-height: 160%; box-sizing: content-box; border-top: 1px solid #eee; margin: 16px 0;&quot;/&gt;
&lt;ul style=&quot;line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;&quot;&gt;
&lt;li style=&quot;line-height: 160%; box-sizing: content-box; position: relative;&quot;&gt;B*树：在B+树基础上，为非叶子结点也增加链表指针，将结点的最低利用率从1/2提高到2/3；&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 34px; border-bottom: 1px solid #dbdbdb; color: #333;&quot;&gt;四. LSM树&lt;/h2&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;4.1 LSM由来&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;B+树最大的性能问题是&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;会产生大量的随机IO&lt;/strong&gt;，随着新数据的插入，叶子节点会慢慢分裂，逻辑上连续的叶子节点在物理上往往不连续，甚至分离的很远，但做范围查询时，会产生大量读随机IO。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;对于大量的随机写也一样，举一个插入key跨度很大的例子，如7-&gt;1000-&gt;3-&gt;2000 ... 新插入的数据存储在磁盘上相隔很远，会产生大量的随机写IO.&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;从上面可以看出，低下的磁盘寻道速度严重影响性能（近些年来，磁盘寻道速度的发展几乎处于停滞的状态）。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;为了克服B+树的弱点，HBase引入了LSM树的概念，即Log-Structured Merge-Trees。&lt;/p&gt;
&lt;h3 style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;&quot;&gt;4.2 LSM树原理&lt;/h3&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;为了更好的说明LSM树的原理，下面举个比较极端的例子：&lt;/p&gt;
&lt;blockquote style=&quot;line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;&quot;&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;&quot;&gt;现在假设有1000个节点的随机key，对于磁盘来说，肯定是把这1000个节点顺序写入磁盘最快，但是这样一来，读就悲剧了，因为key在磁盘中完全无序，每次读取都要全扫描；&lt;br/&gt;
那么，为了让读性能尽量高，数据在磁盘中必须得有序，这就是B+树的原理，但是写就悲剧了，因为会产生大量的随机IO，磁盘寻道速度跟不上。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;LSM树本质上就是在读写之间取得平衡，和B+树相比，它&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;牺牲了部分读性能，用来大幅提高写性能。&lt;/strong&gt;&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;原理&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;它的原理是把一颗&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;大树拆分成N棵小树&lt;/strong&gt;， 它&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;首先写入到内存&lt;/strong&gt;中（内存没有寻道速度的问题，随机写的性能得到大幅提升），在内存中构建一颗&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;有序小树&lt;/strong&gt;，随着小树越来越大，&lt;strong style=&quot;line-height: 160%; box-sizing: content-box; font-weight: 700;&quot;&gt;内存的小树会flush到磁盘上&lt;/strong&gt;。当读时，由于不知道数据在哪棵小树上，因此必须遍历所有的小树，但在每颗小树内部数据是有序的。&lt;/p&gt;
&lt;h4 style=&quot;line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;&quot;&gt;实现&lt;/h4&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;以上就是LSM树最本质的原理，有了原理，再看具体的技术就很简单了。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;1）首先说说为什么要有WAL（Write Ahead Log），很简单，因为数据是先写到内存中，如果断电，内存中的数据会丢失，因此为了保护内存中的数据，需要在磁盘上先记录logfile，当内存中的数据flush到磁盘上时，就可以抛弃相应的Logfile。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;2）什么是memstore, storefile？很简单，上面说过，LSM树就是一堆小树，在内存中的小树即memstore，每次flush，内存中的memstore变成磁盘上一个新的storefile。&lt;/p&gt;
&lt;p style=&quot;line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;&quot;&gt;3）为什么会有compact？很简单，随着小树越来越多，读的性能会越来越差，因此需要在适当的时候，对磁盘中的小树进行merge，多棵小树变成一颗大树。&lt;/p&gt;
&lt;/div&gt;&lt;center style='display:none !important;visibility:collapse !important;height:0 !important;white-space:nowrap;width:100%;overflow:hidden'&gt;%5Btoc%5D%0A%23%20%E6%A0%91%0A%0A%23%23%20%E4%B8%80.%20%E4%BA%8C%E5%8F%89%E6%A0%91%0A%23%23%23%201.%20%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5%0A%0A%E4%BA%8C%E5%8F%89%E6%A0%91%E6%98%AF%E6%AF%8F%E4%B8%AA%E7%BB%93%E7%82%B9%E6%9C%80%E5%A4%9A%E6%9C%89%E4%B8%A4%E4%B8%AA%E5%AD%90%E6%A0%91%E7%9A%84%E6%A0%91%E7%BB%93%E6%9E%84%E3%80%82%E9%80%9A%E5%B8%B8%E5%AD%90%E6%A0%91%E8%A2%AB%E7%A7%B0%E4%BD%9C%E2%80%9C%E5%B7%A6%E5%AD%90%E6%A0%91%E2%80%9D%EF%BC%88left%20subtree%EF%BC%89%E5%92%8C%E2%80%9C%E5%8F%B3%E5%AD%90%E6%A0%91%E2%80%9D%EF%BC%88right%20subtree%EF%BC%89%E3%80%82%0A%0A%E4%B8%80%E6%A3%B5%E6%B7%B1%E5%BA%A6%E4%B8%BAk%EF%BC%8C%E4%B8%94%E6%9C%892%5Ek-1%E4%B8%AA%E8%8A%82%E7%82%B9%E7%9A%84%E4%BA%8C%E5%8F%89%E6%A0%91%EF%BC%8C%E7%A7%B0%E4%B8%BA**%E6%BB%A1%E4%BA%8C%E5%8F%89%E6%A0%91**%EF%BC%8C%E8%BF%99%E7%A7%8D%E6%A0%91%E7%9A%84%E7%89%B9%E7%82%B9%E6%98%AF%E6%AF%8F%E4%B8%80%E5%B1%82%E4%B8%8A%E7%9A%84%E8%8A%82%E7%82%B9%E6%95%B0%E9%83%BD%E6%98%AF%E6%9C%80%E5%A4%A7%E8%8A%82%E7%82%B9%E6%95%B0%E3%80%82%0A%23%23%23%23%201.1%20%E4%BA%8C%E5%8F%89%E6%A0%91%E5%9F%BA%E6%9C%AC%E5%BD%A2%E6%80%81%0A%20%E4%BA%8C%E5%8F%89%E6%A0%91%E6%98%AF%E9%80%92%E5%BD%92%E5%AE%9A%E4%B9%89%E7%9A%84%EF%BC%8C%E5%85%B6%E7%BB%93%E7%82%B9%E6%9C%89%E5%B7%A6%E5%8F%B3%E5%AD%90%E6%A0%91%E4%B9%8B%E5%88%86%EF%BC%8C%E9%80%BB%E8%BE%91%E4%B8%8A%E4%BA%8C%E5%8F%89%E6%A0%91%E6%9C%89%E4%BA%94%E7%A7%8D%E5%9F%BA%E6%9C%AC%E5%BD%A2%E6%80%81%EF%BC%9A%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/ce3accb7-b2b8-412f-9aa6-33be7af3a070.gif.gif%5D(en-resource%3A%2F%2Fdatabase%2F532%3A1)%0A(1)%E7%A9%BA%E4%BA%8C%E5%8F%89%E6%A0%91%E2%80%94%E2%80%94%E5%A6%82%E5%9B%BE(a)%EF%BC%9B%0A(2)%E5%8F%AA%E6%9C%89%E4%B8%80%E4%B8%AA%E6%A0%B9%E7%BB%93%E7%82%B9%E7%9A%84%E4%BA%8C%E5%8F%89%E6%A0%91%E2%80%94%E2%80%94%E5%A6%82%E5%9B%BE(b)%EF%BC%9B%0A(3)%E5%8F%AA%E6%9C%89%E5%B7%A6%E5%AD%90%E6%A0%91%E2%80%94%E2%80%94%E5%A6%82%E5%9B%BE(c)%EF%BC%9B%0A(4)%E5%8F%AA%E6%9C%89%E5%8F%B3%E5%AD%90%E6%A0%91%E2%80%94%E2%80%94%E5%A6%82%E5%9B%BE(d)%EF%BC%9B%0A(5)%E5%AE%8C%E5%85%A8%E4%BA%8C%E5%8F%89%E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88%E5%B7%A6%EF%BC%89%E5%AD%90%E6%A0%91%EF%BC%8C%E6%9C%80%E5%90%8E%E8%AE%BF%E9%97%AE%E6%A0%B9%0A4.%20%E5%B1%82%E6%AC%A1%E9%81%8D%E5%8E%86%0A%E5%8D%B3%E6%8C%89%E7%85%A7%E5%B1%82%E6%AC%A1%E8%AE%BF%E9%97%AE%EF%BC%8C%E9%80%9A%E5%B8%B8%E7%94%A8%E9%98%9F%E5%88%97%E6%9D%A5%E5%81%9A%E3%80%82%E8%AE%BF%E9%97%AE%E6%A0%B9%EF%BC%8C%E8%AE%BF%E9%97%AE%E5%AD%90%E5%A5%B3%EF%BC%8C%E5%86%8D%E8%AE%BF%E9%97%AE%E5%AD%90%E5%A5%B3%E7%9A%84%E5%AD%90%E5%A5%B3%EF%BC%88%E8%B6%8A%E5%BE%80%E5%90%8E%E7%9A%84%E5%B1%82%E6%AC%A1%E8%B6%8A%E4%BD%8E%EF%BC%89%EF%BC%88%E4%B8%A4%E4%B8%AA%E5%AD%90%E5%A5%B3%E7%9A%84%E7%BA%A7%E5%88%AB%E7%9B%B8%E5%90%8C%EF%BC%89%0A%0A%23%23%23%202.%20%E5%AE%8C%E5%85%A8%E4%BA%8C%E5%8F%89%E6%A0%91%0A%23%23%23%23%202.1%20%E5%AE%8C%E5%85%A8%E4%BA%8C%E5%8F%89%E6%A0%91%E5%AE%9A%E4%B9%89%0A%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/db46dcc7-a4f3-44b9-ac7f-68c8ddb85049.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F533%3A1)%0A%0A*%20%E8%8B%A5%E8%AE%BE%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E6%B7%B1%E5%BA%A6%E4%B8%BAh%EF%BC%8C%E9%99%A4%E7%AC%AC%20h%20%E5%B1%82%E5%A4%96%EF%BC%8C%E5%85%B6%E5%AE%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%87%E6%95%B0%E4%B8%AA%E3%80%82%0A%20%20%20%202.%20%20%E7%AC%ACi%E5%B1%82%E4%B8%8A%E7%9A%84%E7%BB%93%E7%82%B9%E6%95%B0%E4%B8%BA%EF%BC%9A2%5Ei%20-1%20%3B%0A%20%20%20%203.%20%20%E4%B8%80%E4%B8%AA%E5%B1%82%E6%95%B0%E4%B8%BAk%E7%9A%84%E6%BB%A1%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E5%8F%B6%E5%AD%90%E7%BB%93%E7%82%B9%E4%B8%AA%E6%95%B0%EF%BC%88%E4%B9%9F%E5%B0%B1%E6%98%AF%E6%9C%80%E5%90%8E%E4%B8%80%E5%B1%82%EF%BC%89%3A2%5E(k-1)%20%3B%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/011640c0-e095-4085-9983-6dd5d106869a.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F535%3A1)%0A%0A*%20%E5%AF%B9%E4%BA%8E%E5%9B%BD%E5%A4%96%E7%9A%84%E6%BB%A1%E4%BA%8C%E5%8F%89%E6%A0%91%0A%E6%BB%A1%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E4%BB%BB%E6%84%8F%E8%8A%82%E7%82%B9%EF%BC%8C%E8%A6%81%E4%B9%88%E5%BA%A6%E4%B8%BA0%EF%BC%8C%E8%A6%81%E4%B9%88%E5%BA%A6%E4%B8%BA2.%E6%8D%A2%E4%B8%AA%E8%AF%B4%E6%B3%95%E5%8D%B3%E8%A6%81%E4%B9%88%E4%B8%BA%E5%8F%B6%E5%AD%90%E7%BB%93%E7%82%B9%EF%BC%8C%E8%A6%81%E4%B9%88%E5%90%8C%E6%97%B6%E5%85%B7%E6%9C%89%E5%B7%A6%E5%8F%B3%E5%AD%A9%E5%AD%90%E3%80%82%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/fdc39200-b9a1-4b20-9997-f97dc2396a43.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F534%3A1)%0A%0A%23%23%23%204.%20%E5%A0%86%0A%23%23%23%23%204.1%20%E5%A0%86%E7%9A%84%E6%A6%82%E5%BF%B5%0A%0A%E5%A0%86%E6%98%AF%E5%85%B7%E6%9C%89%E4%BB%A5%E4%B8%8B%E6%80%A7%E8%B4%A8%E7%9A%84%E5%AE%8C%E5%85%A8%E4%BA%8C%E5%8F%89%E6%A0%91%EF%BC%9A%0A*%20%E6%AF%8F%E4%B8%AA%E7%BB%93%E7%82%B9%E7%9A%84%E5%80%BC%E9%83%BD%E5%A4%A7%E4%BA%8E%E6%88%96%E7%AD%89%E4%BA%8E%E5%85%B6%E5%B7%A6%E5%8F%B3%E5%AD%A9%E5%AD%90%E7%BB%93%E7%82%B9%E7%9A%84%E5%80%BC%EF%BC%8C%E7%A7%B0%E4%B8%BA%E5%A4%A7%E9%A1%B6%E5%A0%86%EF%BC%9B%0A*%20%E6%88%96%E8%80%85%E6%AF%8F%E4%B8%AA%E7%BB%93%E7%82%B9%E7%9A%84%E5%80%BC%E9%83%BD%E5%B0%8F%E4%BA%8E%E6%88%96%E7%AD%89%E4%BA%8E%E5%85%B6%E5%B7%A6%E5%8F%B3%E5%AD%A9%E5%AD%90%E7%BB%93%E7%82%B9%E7%9A%84%E5%80%BC%EF%BC%8C%E7%A7%B0%E4%B8%BA%E5%B0%8F%E9%A1%B6%E5%A0%86%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/91db10fa-6d65-417a-9088-d007c6ae2b72.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F536%3A1)%0A%0A%E5%9C%A8%E4%B8%80%E4%B8%AA%E5%A0%86%E6%9C%89%E5%BA%8F%E7%9A%84%E4%BA%8C%E5%8F%89%E6%A0%91%E4%B8%AD%EF%BC%8C%E7%88%B6%E8%8A%82%E7%82%B9%E7%9A%84%E4%BD%8D%E7%BD%AE%E6%98%AFK%2F2%2C%E5%AE%83%E7%9A%84%E4%B8%A4%E4%B8%AA%E5%AD%90%E8%8A%82%E7%82%B9%E7%9A%84%E4%BD%8D%E7%BD%AE%E6%98%AF2k%2C2k%2B1%E3%80%82%0A%0A%23%23%23%23%204.2%20%E5%A0%86%E7%9A%84%E5%AE%9E%E7%8E%B0%0A%60%60%60java%0A%0A%2F%2F%E6%9C%80%E5%A4%A7%E5%A0%86%0Apublic%20class%20MaxPQ%20%7B%0A%20%20%20%20private%20List%3CInteger%3E%20arr%3B%20%20%20%20%20%20%2F%2F%E5%AE%9A%E4%B9%89%E4%B8%80%E4%B8%AA%E6%95%B0%E7%BB%84%0A%20%20%20%20private%20%20int%20N%3B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%E5%AE%9A%E4%B9%89%E9%98%9F%E5%88%97%E4%B8%AD%E7%9A%84%E5%85%83%E7%B4%A0%E4%B8%AA%E6%95%B0%0A%0A%20%20%20%20public%20MaxPQ()%20%7B%0A%20%20%20%20%20%20%20%20arr%20%3D%20new%20ArrayList()%3B%0A%20%20%20%20%20%20%20%20arr.add(1)%3B%0A%20%20%20%20%20%20%20%20N%20%3D%200%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20public%20boolean%20isEmpty()%20%7B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%E6%96%B9%E6%B3%95%EF%BC%8C%E8%BF%94%E5%9B%9E%E9%98%9F%E5%88%97%E6%98%AF%E5%90%A6%E4%B8%BA%E7%A9%BA%0A%20%20%20%20%20%20%20%20return%20N%20%3D%3D%200%3B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%7D%0A%0A%20%20%20%20public%20int%20size()%20%7B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%E6%96%B9%E6%B3%95%EF%BC%8C%E8%BF%94%E5%9B%9E%E9%98%9F%E5%88%97%E4%B8%AD%E5%85%83%E7%B4%A0%E7%9A%84%E4%B8%AA%E6%95%B0%0A%20%20%20%20%20%20%20%20return%20N%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20public%20void%20inSert(int%20number)%20%7B%20%20%20%20%20%20%20%2F%2F%E6%B7%BB%E5%8A%A0%E6%96%B9%E6%B3%95%EF%BC%8C%E6%B7%BB%E5%8A%A0%E5%85%83%E7%B4%A0%E5%88%B0%E7%BB%93%E5%90%88%E6%9C%AB%E5%B0%BE%EF%BC%8C%E5%B9%B6%E4%B8%94%E4%BD%BF%E7%94%A8%E4%B8%8A%E6%B5%AE%E6%96%B9%E6%B3%95%E5%88%B0%E6%8C%87%E5%AE%9A%E7%9A%84%E4%BD%8D%E7%BD%AE%0A%20%20%20%20%20%20%20%20arr.add(number)%3B%0A%20%20%20%20%20%20%20%20swim(%2B%2BN)%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20public%20int%20deleteMax()%20%7B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%E5%88%A0%E9%99%A4%E6%96%B9%E6%B3%95%EF%BC%8C%E5%88%A0%E9%99%A4%E6%9C%80%E5%A4%A7%E5%85%83%E7%B4%A0%E5%B9%B6%E6%8A%8A%E6%9C%80%E5%B0%8F%E7%9A%84%E5%85%83%E7%B4%A0%E6%94%BE%E5%88%B0%E7%AC%AC%E4%B8%80%E4%B8%AA%EF%BC%8C%E7%84%B6%E5%90%8E%E4%BD%BF%E7%94%A8%E4%B8%8B%E6%B5%AE%E6%96%B9%E6%B3%95%0A%20%20%20%20%20%20%20%20int%20max%20%3D%20arr.get(1)%3B%0A%20%20%20%20%20%20%20%20int%20min%20%20%3D%20arr.get(N)%3B%0A%20%20%20%20%20%20%20%20arr.set(1%2C%20min)%3B%0A%20%20%20%20%20%20%20%20arr.remove(N--)%3B%0A%20%20%20%20%20%20%20%20sink(1)%3B%0A%20%20%20%20%20%20%20%20return%20max%3B%0A%20%20%20%20%7D%0A%20%20%20%20%2F%2F%E4%B8%8A%E6%B5%AE%0A%20%20%20%20public%20void%20swim(int%20N)%20%7B%0A%20%20%20%20%20%20%20%20while(N%20%3E%201%20%26%26%20(arr.get(N%2F2)%20%3C%20arr.get(N)))%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20int%20max%20%3D%20arr.get(N)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20int%20min%20%3D%20arr.get(N%2F2)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20arr.set(N%2Cmin%20)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20arr.set(N%2F2%2C%20max)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20N%20%3D%20N%2F2%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%20%20%2F%2F%E4%B8%8B%E6%B2%89%0A%20%20%20%20public%20void%20sink(int%20number)%20%7B%0A%20%20%20%20%20%20%20%20while(number*2%20%3C%3D%20N)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20int%20index%20%3D%20number*2%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20if(index%20%3C%20N%20%26%26%20(arr.get(index)%20%3C%20arr.get(index%20%2B%201)))%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20index%2B%2B%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20if(!(arr.get(number)%20%3C%20arr.get(index)))%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20break%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20int%20max%20%3D%20arr.get(index)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20int%20min%20%3D%20arr.get(number)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20arr.set(number%2C%20max)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20arr.set(index%2C%20min)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20number%20%3D%20index%3B%0A%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%7D%0A%0A%20%20%20%20%40Override%0A%20%20%20%20public%20String%20toString()%20%7B%0A%20%20%20%20%20%20%20%20return%20%22MaxPQ%20%5Barr%3D%22%20%2B%20arr%20%2B%20%22%2C%20N%3D%22%20%2B%20N%20%2B%20%22%5D%22%3B%0A%20%20%20%20%7D%0A%7D%0A%60%60%60%0A%0A%0A%0A%0A%23%23%23%205.%20%E4%BA%8C%E5%8F%89%E6%9F%A5%E6%89%BE%E6%A0%91(%E6%8E%92%E5%BA%8F%E6%A0%91)(Binary%20Search%20Tree%EF%BC%8CBST)%0A%0A%E4%BA%8C%E5%8F%89%E6%8E%92%E5%BA%8F%E6%A0%91%E6%88%96%E8%80%85%E6%98%AF%E4%B8%80%E6%A3%B5%E7%A9%BA%E6%A0%91%EF%BC%8C%E6%88%96%E8%80%85%E6%98%AF%E5%85%B7%E6%9C%89%E4%B8%8B%E5%88%97%E6%80%A7%E8%B4%A8%E7%9A%84%E4%BA%8C%E5%8F%89%E6%A0%91%EF%BC%9A%0A%0A%60%60%60%0A%EF%BC%881%EF%BC%89%E8%8B%A5%E5%B7%A6%E5%AD%90%E6%A0%91%E4%B8%8D%E7%A9%BA%EF%BC%8C%E5%88%99%E5%B7%A6%E5%AD%90%E6%A0%91%E4%B8%8A%E6%89%80%E6%9C%89%E7%BB%93%E7%82%B9%E7%9A%84%E5%80%BC%E5%9D%87%E5%B0%8F%E4%BA%8E%E5%AE%83%E7%9A%84%E6%A0%B9%E8%8A%82%E7%82%B9%E7%82%B9%E7%9A%84%E5%80%BC%EF%BC%9B%0A%EF%BC%882%EF%BC%89%E8%8B%A5%E5%8F%B3%E5%AD%90%E6%A0%91%E4%B8%8D%E7%A9%BA%EF%BC%8C%E5%88%99%E5%8F%B3%E5%AD%90%E6%A0%91%E4%B8%8A%E6%89%80%E6%9C%89%E7%BB%93%E7%82%B9%E7%9A%84%E5%80%BC%E5%9D%87%E5%A4%A7%E4%BA%8E%E6%88%96%E7%AD%89%E4%BA%8E%E5%AE%83%E7%9A%84%E6%A0%B9%E7%BB%93%E7%82%B9%E7%9A%84%E5%80%BC%EF%BC%9B%0A%EF%BC%883%EF%BC%89%E5%B7%A6%E3%80%81%E5%8F%B3%E5%AD%90%E6%A0%91%E4%B9%9F%E5%88%86%E5%88%AB%E4%B8%BA%E4%BA%8C%E5%8F%89%E6%8E%92%E5%BA%8F%E6%A0%91%EF%BC%9B%0A%EF%BC%884%EF%BC%89%E6%B2%A1%E6%9C%89%E9%94%AE%E5%80%BC%E7%9B%B8%E7%AD%89%E7%9A%84%E8%8A%82%E7%82%B9%E3%80%82%0A%60%60%60%0A%E4%BE%8B%E5%AD%90%EF%BC%9A%0A%3E%20%5B%E4%BA%8C%E5%8F%89%E6%9F%A5%E6%89%BE%E6%A0%91%E4%BE%8B%E9%A2%98%5D(https%3A%2F%2Fwww.nowcoder.com%2FquestionTerminal%2Fdfdfc7f18a234a768aabd4021eda3652)%0A%0A%23%23%23%23%20%5B%E4%BA%8C%E5%8F%89%E6%A0%91%E6%9F%A5%E6%89%BE%E6%A0%91%E7%9A%84%E8%AF%A6%E7%BB%86%E8%A7%A3%E6%9E%90%5D(https%3A%2F%2Fblog.csdn.net%2Fjavazejian%2Farticle%2Fdetails%2F53727333)%0A%0A%23%23%23%206.%20%E5%B9%B3%E8%A1%A1%E4%BA%8C%E5%8F%89%E6%A0%91(AVL%E6%A0%91)%0A%23%23%23%23%206.1%20%E5%B9%B3%E8%A1%A1%E4%BA%8C%E5%8F%89%E6%A0%91%E5%AE%9A%E4%B9%89%0A1.%20%E5%AF%B9%E4%BA%8E%E4%B8%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%A0**%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/1b048f56-8e11-479d-9839-2e426451d878.png.png%5D(en-resource%3A%2F%2Fdatabase%2F548%3A1)%0A%0A%23%23%23%23%23%206.3.2%20%E5%8F%B3%E5%8F%B3%E5%8D%95%E6%97%8B%E8%BD%AC(RR)%E6%83%85%E6%99%AF%E2%91%A3%E5%88%86%E6%9E%90%0A**%E5%9C%A8%E7%BB%93%E7%82%B9X%E7%9A%84%E5%8F%B3%E5%AD%A9%E5%AD%90%E7%BB%93%E7%82%B9%E7%9A%84%E5%8F%B3%E5%AD%90%E6%A0%91%E4%B8%AD%E6%8F%92%E5%85%A5%E5%85%83%E7%B4%A0**%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/797c2c03-3243-4750-aebf-60bd924826dd.png.png%5D(en-resource%3A%2F%2Fdatabase%2F549%3A1)%0A%0A%23%23%23%23%23%206.3.3%20%E5%B7%A6%E5%8F%B3%E5%8F%8C%E6%97%8B%E8%BD%AC(LR)%E6%83%85%E6%99%AF%E2%91%A1%E5%88%86%E6%9E%90%0A**%E5%9C%A8%E7%BB%93%E7%82%B9X%E7%9A%84%E5%B7%A6%E5%AD%A9%E5%AD%90%E7%BB%93%E7%82%B9%E7%9A%84%E5%8F%B3%E5%AD%90%E6%A0%91%E4%B8%AD%E6%8F%92%E5%85%A5%E5%85%83%E7%B4%A0**%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/d5a66920-e3ed-4334-bdb9-ef0f7d4dd380.png.png%5D(en-resource%3A%2F%2Fdatabase%2F547%3A1)%0A%0A%23%23%23%23%23%206.3.4%20%E5%8F%B3%E5%B7%A6%E5%8F%8C%E6%97%8B%E8%BD%AC(RL)%E6%83%85%E6%99%AF%E2%91%A2%E5%88%86%E6%9E%90%0A**%E5%9C%A8%E7%BB%93%E7%82%B9X%E7%9A%84%E5%8F%B3%E5%AD%A9%E5%AD%90%E7%BB%93%E7%82%B9%E7%9A%84%E5%B7%A6%E5%AD%90%E6%A0%91%E4%B8%AD%E6%8F%92%E5%85%A5%E5%85%83%E7%B4%A0**%20%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/07f321ba-5398-4001-ae9d-3c192c7f2f33.png.png%5D(en-resource%3A%2F%2Fdatabase%2F550%3A1)%0A%0A%0A%0A%0A%0A%23%23%23%23%20%5B%E5%B9%B3%E8%A1%A1%E4%BA%8C%E5%8F%89%E6%A0%91%E8%AF%A6%E7%BB%86%E8%A7%A3%E6%9E%90%5D(https%3A%2F%2Fblog.csdn.net%2Fjavazejian%2Farticle%2Fdetails%2F53892797)%0A%0A%23%23%20%E4%BA%8C%20.%20%E7%BA%A2%E9%BB%91%E6%A0%91%0A%23%23%23%201.%20%E7%BA%A2%E9%BB%91%E6%A0%91%E7%AE%80%E4%BB%8B%0A%E7%BA%A2%E9%BB%91%E6%A0%91%E6%98%AF%E6%AF%8F%E4%B8%AA%E8%8A%82%E7%82%B9%E9%83%BD%E5%B8%A6%E6%9C%89%E9%A2%9C%E8%89%B2%E5%B1%9E%E6%80%A7%E7%9A%84%E4%BA%8C%E5%8F%89%E6%9F%A5%E6%89%BE%E6%A0%91%EF%BC%8C%E9%A2%9C%E8%89%B2%E6%88%96%E7%BA%A2%E8%89%B2%E6%88%96%E9%BB%91%E8%89%B2%E3%80%82%E5%9C%A8%E4%BA%8C%E5%8F%89%E6%9F%A5%E6%89%BE%E6%A0%91%E5%BC%BA%E5%88%B6%E4%B8%80%E8%88%AC%E8%A6%81%E6%B1%82%E4%BB%A5%E5%A4%96%EF%BC%8C%E5%AF%B9%E4%BA%8E%E4%BB%BB%E4%BD%95%E6%9C%89%E6%95%88%E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E8%8A%82%E7%82%B9%E3%80%82%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/8dd8f54f-d736-49a0-8b05-40f53351c934.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F537%3A1)%0A%0A%23%23%23%202.%20%E7%BA%A2%E9%BB%91%E6%A0%91%E7%9A%84%E4%BF%AE%E6%AD%A3%0A%0A%E5%8F%98%E8%89%B2%E3%80%81%E5%B7%A6%E6%97%8B%E3%80%81%E5%8F%B3%E6%97%8B%E6%98%AF%E7%BA%A2%E9%BB%91%E6%A0%91%E5%9C%A8%E4%BA%8C%E5%8F%89%E6%A0%91%E4%B8%8A%E7%9A%84%E6%89%A9%E5%B1%95%E6%93%8D%E4%BD%9C%EF%BC%8C%E5%90%8C%E6%97%B6%E4%B9%9F%E6%98%AF%E5%9F%BA%E4%BA%8E%E8%BF%99%E4%B8%89%E4%B8%AA%E6%93%8D%E4%BD%9C%E6%89%8D%E8%83%BD%E9%81%B5%E5%AE%88%E7%BA%A2%E9%BB%91%E6%A0%91%E7%9A%84%E4%BA%94%E4%B8%AA%E7%89%B9%E6%80%A7%E3%80%82%0A%0A%23%23%23%23%202.1%20%E5%B7%A6%E6%97%8B%0A%20%20%20!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/7907fc1e-dc0e-4829-b883-072a2bc13600.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F538%3A1)%0A%20%20%20%0A%60%60%60java%0A%C2%A0%C2%A0%C2%A0%20%2F*%0A%C2%A0%C2%A0%C2%A0%C2%A0%20*%20%E5%B7%A6%E6%97%8B%E5%81%9A%E4%BA%86%E4%B8%89%E4%BB%B6%E4%BA%8B%EF%BC%9A%0A%0A%C2%A0%C2%A0%C2%A0%C2%A0%20*%201.%20%E5%B0%86y%E7%9A%84%E5%B7%A6%E5%AD%90%E8%8A%82%E7%82%B9%E8%B5%8B%E7%BB%99x%E7%9A%84%E5%8F%B3%E5%AD%90%E8%8A%82%E7%82%B9%2C%E5%B9%B6%E5%B0%86x%E8%B5%8B%E7%BB%99y%E5%B7%A6%E5%AD%90%E8%8A%82%E7%82%B9%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9(y%E5%B7%A6%E5%AD%90%E8%8A%82%E7%82%B9%E9%9D%9E%E7%A9%BA%E6%97%B6)%0A%0A%C2%A0%C2%A0%C2%A0%C2%A0%20*%202.%20%E5%B0%86x%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9p(%E9%9D%9E%E7%A9%BA%E6%97%B6)%E8%B5%8B%E7%BB%99y%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9%EF%BC%8C%E5%90%8C%E6%97%B6%E6%9B%B4%E6%96%B0p%E7%9A%84%E5%AD%90%E8%8A%82%E7%82%B9%E4%B8%BAy(%E5%B7%A6%E6%88%96%E5%8F%B3)%0A%0A%C2%A0%C2%A0%C2%A0%C2%A0%20*%203.%20%E5%B0%86y%E7%9A%84%E5%B7%A6%E5%AD%90%E8%8A%82%E7%82%B9%E8%AE%BE%E4%B8%BAx%EF%BC%8C%E5%B0%86x%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9%E8%AE%BE%E4%B8%BAy%0A%0A%C2%A0%C2%A0%C2%A0%C2%A0%20*%2F%0A%C2%A0%C2%A0%C2%A0%20public%20void%20leftRotate(RBNode%3CT%3E%20x)%20%7B%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20if%20(x%20%3D%3D%20null)%20return%3B%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%2F%2F1.%20%E5%B0%86y%E7%9A%84%E5%B7%A6%E5%AD%90%E8%8A%82%E7%82%B9%E8%B5%8B%E7%BB%99x%E7%9A%84%E5%8F%B3%E5%AD%90%E8%8A%82%E7%82%B9%2C%E5%B9%B6%E5%B0%86x%E8%B5%8B%E7%BB%99y%E5%B7%A6%E5%AD%90%E8%8A%82%E7%82%B9%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9(y%E5%B7%A6%E5%AD%90%E8%8A%82%E7%82%B9%E9%9D%9E%E7%A9%BA%E6%97%B6)%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20RBNode%3CT%3E%20y%20%3D%20x.right%3B%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20x.right%20%3D%20y.left%3B%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20if%20(y.left%20!%3D%20null)%20%7B%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20y.left.parent%20%3D%20x%3B%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%7D%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%2F%2F2.%20%E5%B0%86x%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9p(%E9%9D%9E%E7%A9%BA%E6%97%B6)%E8%B5%8B%E7%BB%99y%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9%EF%BC%8C%E5%90%8C%E6%97%B6%E6%9B%B4%E6%96%B0p%E7%9A%84%E5%AD%90%E8%8A%82%E7%82%B9%E4%B8%BAy(%E5%B7%A6%E6%88%96%E5%8F%B3)%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20y.parent%20%3D%20x.parent%3B%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20if%20(x.parent%20%3D%3D%20null)%20%7B%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20this.mRoot%20%3D%20y%3B%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%7D%20else%20%7B%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20if%20(x%20%3D%3D%20x.parent.left)%20%7B%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20x.parent.left%20%3D%20y%3B%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%7D%20else%20%7B%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20x.parent.right%20%3D%20y%3B%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%7D%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%7D%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%2F%2F3.%20%E5%B0%86y%E7%9A%84%E5%B7%A6%E5%AD%90%E8%8A%82%E7%82%B9%E8%AE%BE%E4%B8%BAx%EF%BC%8C%E5%B0%86x%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9%E8%AE%BE%E4%B8%BAy%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20y.left%20%3D%20x%3B%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20x.parent%20%3D%20y%3B%0A%C2%A0%C2%A0%C2%A0%20%7D%0A%60%60%60%0A%0A%23%23%23%23%202.2%20%E5%8F%B3%E6%97%8B%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/8cd8bedd-e9dd-48fd-a698-5929a1693a38.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F539%3A1)%0A%60%60%60java%0A%2F*%20%20%20%20%20%20%E5%8F%B3%E6%97%8B%E5%81%9A%E4%BA%86%E4%B8%89%E4%BB%B6%E4%BA%8B%EF%BC%9A%0A%C2%A0%C2%A0%C2%A0%C2%A0%20*%201.%20%E5%B0%86x%E7%9A%84%E5%8F%B3%E5%AD%90%E8%8A%82%E7%82%B9%E8%B5%8B%E7%BB%99y%E7%9A%84%E5%B7%A6%E5%AD%90%E8%8A%82%E7%82%B9%2C%E5%B9%B6%E5%B0%86y%E8%B5%8B%E7%BB%99x%E5%8F%B3%E5%AD%90%E8%8A%82%E7%82%B9%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9(x%E5%8F%B3%E5%AD%90%E8%8A%82%E7%82%B9%E9%9D%9E%E7%A9%BA%E6%97%B6)%0A%C2%A0%C2%A0%C2%A0%C2%A0%20*%202.%20%E5%B0%86y%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9p(%E9%9D%9E%E7%A9%BA%E6%97%B6)%E8%B5%8B%E7%BB%99x%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9%EF%BC%8C%E5%90%8C%E6%97%B6%E6%9B%B4%E6%96%B0p%E7%9A%84%E5%AD%90%E8%8A%82%E7%82%B9%E4%B8%BAx(%E5%B7%A6%E6%88%96%E5%8F%B3)%0A%C2%A0%C2%A0%C2%A0%C2%A0%20*%203.%20%E5%B0%86x%E7%9A%84%E5%8F%B3%E5%AD%90%E8%8A%82%E7%82%B9%E8%AE%BE%E4%B8%BAy%EF%BC%8C%E5%B0%86y%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9%E8%AE%BE%E4%B8%BAx%0A%C2%A0%C2%A0%C2%A0%C2%A0%20*%2F%0A%C2%A0%C2%A0%20public%20void%20rightRotate(RBNode%3CT%3E%20y)%20%7B%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20if%20(y%20%3D%3D%20null)%20return%3B%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%2F%2F1.%20%E5%B0%86x%E7%9A%84%E5%8F%B3%E5%AD%90%E8%8A%82%E7%82%B9%E8%B5%8B%E7%BB%99y%E7%9A%84%E5%B7%A6%E5%AD%90%E8%8A%82%E7%82%B9%2C%E5%B9%B6%E5%B0%86y%E8%B5%8B%E7%BB%99x%E5%8F%B3%E5%AD%90%E8%8A%82%E7%82%B9%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9(x%E5%8F%B3%E5%AD%90%E8%8A%82%E7%82%B9%E9%9D%9E%E7%A9%BA%E6%97%B6)%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20RBNode%3CT%3E%20x%20%3D%20y.left%3B%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20y.left%20%3D%20x.right%3B%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20if%20(x.right%20!%3D%20null)%20%7B%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20x.right.parent%20%3D%20y%3B%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%7D%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%2F%2F2.%20%E5%B0%86y%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9p(%E9%9D%9E%E7%A9%BA%E6%97%B6)%E8%B5%8B%E7%BB%99x%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9%EF%BC%8C%E5%90%8C%E6%97%B6%E6%9B%B4%E6%96%B0p%E7%9A%84%E5%AD%90%E8%8A%82%E7%82%B9%E4%B8%BAx(%E5%B7%A6%E6%88%96%E5%8F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E9%BB%91%E8%89%B2%E8%8A%82%E7%82%B9%EF%BC%8C%E5%BD%93%E6%88%91%E4%BB%AC%E7%BB%99%E4%B8%80%E4%B8%AA%E7%BA%A2%E8%89%B2%E8%8A%82%E7%82%B9%E4%B8%8B%E6%8F%92%E5%85%A5%E4%B8%80%E4%B8%AA%E7%BA%A2%E8%89%B2%E8%8A%82%E7%82%B9%E6%97%B6%EF%BC%8C%E4%BC%9A%E8%BF%9D%E8%83%8C%E8%BF%99%E6%9D%A1%E7%89%B9%E5%BE%81%E3%80%82%0A*%20%E5%9B%A0%E6%AD%A4%E6%88%91%E4%BB%AC%E9%9C%80%E8%A6%81%E5%9C%A8%E6%8F%92%E5%85%A5%E9%BB%91%E8%89%B2%E8%8A%82%E7%82%B9%E5%90%8E%E8%BF%9B%E8%A1%8C%E7%BB%93%E6%9E%84%E8%B0%83%E6%95%B4%EF%BC%8C%E4%BF%9D%E8%AF%81%E7%BA%A2%E9%BB%91%E6%A0%91%E5%A7%8B%E7%BB%88%E6%BB%A1%E8%B6%B3%E8%BF%99%205%20%E6%9D%A1%E7%89%B9%E5%BE%81%E3%80%82%0A%0A%23%23%23%23%203.1%20%20%E7%BA%A2%E9%BB%91%E6%A0%91%E6%8F%92%E5%85%A5%E5%90%8E%E8%8A%82%E7%82%B9%E7%9A%84%E8%B0%83%E6%95%B4%E6%80%9D%E6%83%B3%3A%0A%0A%E6%8F%92%E5%85%A5%E9%BB%91%E8%89%B2%E8%8A%82%E7%82%B9%E7%9A%84%E6%97%B6%E5%80%99%E6%8B%85%E5%BF%83%E8%BF%9D%E8%83%8C%E7%AC%AC5%E6%9D%A1%EF%BC%8C%E6%8F%92%E5%85%A5%E7%BA%A2%E8%89%B2%E8%8A%82%E7%82%B9%E6%97%B6%E6%8B%85%E5%BF%83%E8%BF%9D%E8%83%8C%E7%AC%AC4%E6%9D%A1%EF%BC%8C%E6%89%80%E4%BB%A5%E6%88%91%E4%BB%AC%E5%B0%86%E5%B0%86**%E6%8F%92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E9%9C%80%E8%A6%81%E6%8F%92%E5%85%A5%E4%BF%AE%E5%A4%8D%E6%93%8D%E4%BD%9C%E7%9A%84**%E3%80%82%0A%E6%8F%92%E5%85%A5%E4%BF%AE%E5%A4%8D%E6%93%8D%E4%BD%9C%E5%88%86%E4%B8%BA%E4%BB%A5%E4%B8%8B%E7%9A%84%E4%B8%89%E7%A7%8D%E6%83%85%E5%86%B5%EF%BC%8C%E8%80%8C%E4%B8%94%E6%96%B0%E6%8F%92%E5%85%A5%E7%9A%84%E8%8A%82%E7%82%B9%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9%E9%83%BD%E6%98%AF%E7%BA%A2%E8%89%B2%E7%9A%84%EF%BC%9A%0A1.%20%E5%8F%94%E5%8F%94%E8%8A%82%E7%82%B9%E4%B9%9F%E4%B8%BA%E7%BA%A2%E8%89%B2%E3%80%82%0A2.%20%E5%8F%94%E5%8F%94%E8%8A%82%E7%82%B9%E4%B8%BA%E7%A9%BA%EF%BC%8C%E4%B8%94%E7%A5%96%E7%88%B6%E8%8A%82%E7%82%B9%E3%80%81%E7%88%B6%E8%8A%82%E7%82%B9%E5%92%8C%E6%96%B0%E8%8A%82%E7%82%B9%E5%A4%84%E4%BA%8E%E4%B8%80%E6%9D%A1%E6%96%9C%E7%BA%BF%E4%B8%8A%E3%80%82%0A3.%20%E5%8F%94%E5%8F%94%E8%8A%82%E7%82%B9%E4%B8%BA%E7%A9%BA%EF%BC%8C%E4%B8%94%E7%A5%96%E7%88%B6%E8%8A%82%E7%82%B9%E3%80%81%E7%88%B6%E8%8A%82%E7%82%B9%E5%92%8C%E6%96%B0%E8%8A%82%E7%82%B9%E4%B8%8D%E5%A4%84%E4%BA%8E%E4%B8%80%E6%9D%A1%E6%96%9C%E7%BA%BF%E4%B8%8A%E3%80%82%0A%0A%23%23%23%23%23%203.1.1%20%E6%8F%92%E5%85%A5%E6%93%8D%E4%BD%9C-case%201(%E5%8F%94%E5%8F%94%E8%8A%82%E7%82%B9%E4%B9%9F%E4%B8%BA%E7%BA%A2%E8%89%B2)%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/10517f91-8106-4bde-8205-f2b10f8bc1f3.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F540%3A1)%0A**%E5%8F%94%E5%8F%94%E8%8A%82%E7%82%B9%E4%B9%9F%E4%B8%BA%E7%BA%A2%E8%89%B2%E3%80%82**%0Acase%201%E7%9A%84%E6%93%8D%E4%BD%9C%E6%98%AF%E5%B0%86%20**%E7%88%B6%E8%8A%82%E7%82%B9%E5%92%8C%E5%8F%94%E5%8F%94%E8%8A%82%E7%82%B9**%20%E4%B8%8E%20**%E7%A5%96%E7%88%B6%E8%8A%82%E7%82%B9**%20%E7%9A%84**%E9%A2%9C%E8%89%B2%E4%BA%92%E6%8D%A2**%EF%BC%8C%E8%BF%99%E6%A0%B7%E5%B0%B1%E7%AC%A6%E5%90%88%E4%BA%86RBTRee%E7%9A%84%E5%AE%9A%E4%B9%89%E3%80%82%E5%8D%B3%E7%BB%B4%E6%8C%81%E4%BA%86%E9%AB%98%E5%BA%A6%E7%9A%84%E5%B9%B3%E8%A1%A1%EF%BC%8C%E4%BF%AE%E5%A4%8D%E5%90%8E%E9%A2%9C%E8%89%B2%E4%B9%9F%E7%AC%A6%E5%90%88RBTree%E5%AE%9A%E4%B9%89%E7%9A%84%E7%AC%AC%E4%B8%89%E6%9D%A1%E5%92%8C%E7%AC%AC%E5%9B%9B%E6%9D%A1%E3%80%82%E4%B8%8B%E5%9B%BE%E4%B8%AD%EF%BC%8C%E6%93%8D%E4%BD%9C%E5%AE%8C%E6%88%90%E5%90%8EA%E8%8A%82%E7%82%B9%E5%8F%98%E6%88%90%E4%BA%86%E6%96%B0%E7%9A%84%E8%8A%82%E7%82%B9%E3%80%82%E5%A6%82%E6%9E%9CA%E8%8A%82%E7%82%B9%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9%E4%B8%8D%E6%98%AF%E9%BB%91%E8%89%B2%E7%9A%84%E8%AF%9D%EF%BC%8C%E5%88%99%E7%BB%A7%E7%BB%AD%E5%81%9A%E4%BF%AE%E5%A4%8D%E6%93%8D%E4%BD%9C%E3%80%82%0A%0A%23%23%23%23%23%203.1.2%20%E6%8F%92%E5%85%A5%E6%93%8D%E4%BD%9C-case%202%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/047f18a2-5281-460a-ac15-d66006d7ca6d.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F541%3A1)%0A**%E5%8F%94%E5%8F%94%E8%8A%82%E7%82%B9%E4%B8%BA%E7%A9%BA%EF%BC%8C%E4%B8%94%E7%A5%96%E7%88%B6%E8%8A%82%E7%82%B9%E3%80%81%E7%88%B6%E8%8A%82%E7%82%B9%E5%92%8C%E6%96%B0%E8%8A%82%E7%82%B9%E5%A4%84%E4%BA%8E%E4%B8%80%E6%9D%A1%E6%96%9C%E7%BA%BF%E4%B8%8A%E3%80%82**%0Acase%202%E7%9A%84%E6%93%8D%E4%BD%9C%E6%98%AF%EF%BC%9A%0A1.%20B%E5%92%8CC%E9%83%BD%E6%98%AF%E5%B7%A6%E8%8A%82%E7%82%B9%EF%BC%8C%E5%B0%86B%E8%8A%82%E7%82%B9%E8%BF%9B%E8%A1%8C%E5%8F%B3%E6%97%8B%E6%93%8D%E4%BD%9C%EF%BC%8C%E5%B9%B6%E4%B8%94%E5%92%8C%E7%88%B6%E8%8A%82%E7%82%B9A%E4%BA%92%E6%8D%A2%E9%A2%9C%E8%89%B2%E3%80%82%E9%80%9A%E8%BF%87%E8%AF%A5%E4%BF%AE%E5%A4%8D%E6%93%8D%E4%BD%9CRBTRee%E7%9A%84%E9%AB%98%E5%BA%A6%E5%92%8C%E9%A2%9C%E8%89%B2%E9%83%BD%E7%AC%A6%E5%90%88%E7%BA%A2%E9%BB%91%E6%A0%91%E7%9A%84%E5%AE%9A%E4%B9%89%E3%80%82%0A2.%20%E5%A6%82%E6%9E%9CB%E5%92%8CC%E8%8A%82%E7%82%B9%E9%83%BD%E6%98%AF%E5%8F%B3%E8%8A%82%E7%82%B9%E7%9A%84%E8%AF%9D%EF%BC%8C%E5%8F%AA%E8%A6%81%E5%B0%86%E6%93%8D%E4%BD%9C%E5%8F%98%E6%88%90B%E8%8A%82%E7%82%B9%E5%B7%A6%E6%97%8B%E5%B0%B1%E5%8F%AF%E4%BB%A5%E4%BA%86%E3%80%82%0A%0A%23%23%23%23%23%203.1.3%20%E6%8F%92%E5%85%A5%E6%93%8D%E4%BD%9C-case%203%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/5fc67456-0d73-44cc-be2f-111054b2636e.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F542%3A1)%0A**%E5%8F%94%E5%8F%94%E8%8A%82%E7%82%B9%E4%B8%BA%E7%A9%BA%EF%BC%8C%E4%B8%94%E7%A5%96%E7%88%B6%E8%8A%82%E7%82%B9%E3%80%81%E7%88%B6%E8%8A%82%E7%82%B9%E5%92%8C%E6%96%B0%E8%8A%82%E7%82%B9%E4%B8%8D%E5%A4%84%E4%BA%8E%E4%B8%80%E6%9D%A1%E6%96%9C%E7%BA%BF%E4%B8%8A%E3%80%82**%0Acase%203%E7%9A%84%E6%93%8D%E4%BD%9C%E6%98%AF%EF%BC%9A%0A1.%20C%E6%98%AF%E5%8F%B3%E8%8A%82%E7%82%B9%EF%BC%8C%E5%B0%86C%E8%8A%82%E7%82%B9%E8%BF%9B%E8%A1%8C%E5%B7%A6%E6%97%8B%EF%BC%8C%E8%BF%99%E6%A0%B7%E5%B0%B1%E4%BB%8Ecase%203%E8%BD%AC%E6%8D%A2%E6%88%90case%202%E4%BA%86%EF%BC%8C%E7%84%B6%E5%90%8E%E9%92%88%E5%AF%B9case%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7%82%B9%E5%85%B3%E6%B3%A8%E7%88%B6%E8%8A%82%E7%82%B9%E6%B2%A1%E5%88%A0%E9%99%A4%E7%9A%84%E9%82%A3%E4%B8%80%E8%BE%B9%E8%8A%82%E7%82%B9%E6%98%AF%E4%B8%8D%E6%98%AF%E9%BB%91%E8%89%B2%E3%80%82%0A*%20%E5%A6%82%E6%9E%9C%E5%88%A0%E9%99%A4%E5%90%8E%E7%88%B6%E4%BA%B2%E8%8A%82%E7%82%B9%E5%8F%A6%E4%B8%80%E8%BE%B9%E6%AF%94%E5%88%A0%E9%99%A4%E7%9A%84%E4%B8%80%E8%BE%B9%E9%BB%91%E8%89%B2%E5%A4%9A%EF%BC%8C%E5%B0%B1%E8%A6%81%E6%83%B3%E5%8A%9E%E6%B3%95%E6%90%9E%E5%88%B0%E5%B9%B3%E8%A1%A1%E3%80%82%0A%20%20%20%20*%201%E3%80%81%E6%8A%8A%E7%88%B6%E4%BA%B2%E8%8A%82%E7%82%B9%E5%8F%A6%E4%B8%80%E8%BE%B9%EF%BC%88%E5%8D%B3%E5%88%A0%E9%99%A4%E8%8A%82%E7%82%B9%E7%9A%84%E5%85%84%E5%BC%9F%E6%A0%91%EF%BC%89%E5%85%B6%E4%B8%AD%E4%B8%80%E4%B8%AA%E8%8A%82%E7%82%B9%E5%BC%84%E6%88%90%E7%BA%A2%E8%89%B2%EF%BC%8C%E4%B9%9F%E5%B0%91%E4%BA%86%E4%B8%80%E4%B8%AA%E9%BB%91%E8%89%B2%E3%80%82%20%0A%20%20%20%20*%202%E3%80%81%E6%88%96%E8%80%85%E6%8A%8A%E5%8F%A6%E4%B8%80%E8%BE%B9%E5%A4%9A%E7%9A%84%E8%8A%82%E7%82%B9%EF%BC%88%E6%9F%93%E6%88%90%E9%BB%91%E8%89%B2%EF%BC%89%E8%BD%AC%E8%BF%87%E6%9D%A5%E4%B8%80%E4%B8%AA%0A-%20-%20-%20%0A%0A*%20**%E5%88%A0%E9%99%A4%E4%BF%AE%E5%A4%8D%E6%93%8D%E4%BD%9C%E6%98%AF%E9%92%88%E5%AF%B9%E5%88%A0%E9%99%A4%E9%BB%91%E8%89%B2%E8%8A%82%E7%82%B9%E6%89%8D%E6%9C%89%E7%9A%84**%EF%BC%8C%E5%BD%93%E9%BB%91%E8%89%B2%E8%8A%82%E7%82%B9%E8%A2%AB%E5%88%A0%E9%99%A4%E5%90%8E%E4%BC%9A%E8%AE%A9%E6%95%B4%E4%B8%AA%E6%A0%91%E4%B8%8D%E7%AC%A6%E5%90%88RBTree%E7%9A%84%E5%AE%9A%E4%B9%89%E7%9A%84%E7%AC%AC%E5%9B%9B%E6%9D%A1%E3%80%82%0A%0A1.%20%E5%BD%93%E5%89%8D%E8%8A%82%E7%82%B9%E6%98%AF%E9%BB%91%E8%89%B2%E7%9A%84%EF%BC%8C%E4%B8%94%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E6%98%AF%E7%BA%A2%E8%89%B2%E7%9A%84%EF%BC%88%E9%82%A3%E4%B9%88%E7%88%B6%E8%8A%82%E7%82%B9%E5%92%8C%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E7%9A%84%E5%AD%90%E8%8A%82%E7%82%B9%E8%82%AF%E5%AE%9A%E6%98%AF%E9%BB%91%E8%89%B2%E7%9A%84%EF%BC%89%EF%BC%9B%0A2.%20%E5%BD%93%E5%89%8D%E8%8A%82%E7%82%B9%E6%98%AF%E9%BB%91%E8%89%B2%E7%9A%84%EF%BC%8C%E4%B8%94%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E6%98%AF%E9%BB%91%E8%89%B2%E7%9A%84%EF%BC%8C%0A%20%20%20%201%EF%BC%89%E3%80%81%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E7%9A%84%E4%B8%A4%E4%B8%AA%E5%AD%90%E8%8A%82%E7%82%B9%E5%9D%87%E4%B8%BA%E9%BB%91%E8%89%B2%E7%9A%84%EF%BC%9B%0A%20%20%20%202%EF%BC%89%E3%80%81%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E7%9A%84%E5%B7%A6%E5%AD%90%E8%8A%82%E7%82%B9%E6%98%AF%E7%BA%A2%E8%89%B2%EF%BC%8C%E5%8F%B3%E5%AD%90%E8%8A%82%E7%82%B9%E6%97%B6%E9%BB%91%E8%89%B2%E7%9A%84%EF%BC%9B%0A%20%20%20%203%EF%BC%89%E3%80%81%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E7%9A%84%E5%8F%B3%E5%AD%90%E8%8A%82%E7%82%B9%E6%98%AF%E7%BA%A2%E8%89%B2%EF%BC%8C%E5%B7%A6%E5%AD%90%E8%8A%82%E7%82%B9%E4%BB%BB%E6%84%8F%E9%A2%9C%E8%89%B2%EF%BC%9B%0A%0A%0A%23%23%23%23%23%204.1.1%20%E5%88%A0%E9%99%A4%E6%93%8D%E4%BD%9C-case%201%20%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/0cb5499f-7521-49b4-930e-172fa42df8db.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F543%3A1)%0A**%E5%BE%85%E5%88%A0%E9%99%A4%E7%9A%84%E8%8A%82%E7%82%B9%E7%9A%84%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E6%98%AF%E7%BA%A2%E8%89%B2%E7%9A%84%E8%8A%82%E7%82%B9%E3%80%82**%0A%0A%E5%B0%86%E7%88%B6%E8%8A%82%E7%82%B9%E6%B6%82%E7%BA%A2%EF%BC%8C%E5%B0%86%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E6%B6%82%E9%BB%91%EF%BC%8C%E7%84%B6%E5%90%8E%E5%B0%86%E5%BD%93%E5%89%8D%E8%8A%82%E7%82%B9%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9%E8%BF%9B%E8%A1%8C%E6%94%AF%E7%82%B9%E5%B7%A6%E6%97%8B%E3%80%82%0Acase%201%E8%BF%99%E6%A0%B7%E8%BD%AC%E6%8D%A2%E4%B9%8B%E5%90%8E%E5%B0%B1%E4%BC%9A%E5%8F%98%E6%88%90%E5%90%8E%E9%9D%A2%E7%9A%84case%202%EF%BC%8Ccase%203%EF%BC%8C%E6%88%96%E8%80%85case%204%E8%BF%9B%E8%A1%8C%E5%A4%84%E7%90%86%E4%BA%86%E3%80%82%0A%0A%23%23%23%23%23%204.1.2%20%E5%88%A0%E9%99%A4%E6%93%8D%E4%BD%9C-case%202%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/a7df5f53-ed76-4bf3-91ed-65b04883b96d.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F544%3A1)%0A**%E5%BE%85%E5%88%A0%E9%99%A4%E7%9A%84%E8%8A%82%E7%82%B9%E7%9A%84%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E6%98%AF%E9%BB%91%E8%89%B2%E7%9A%84%E8%8A%82%E7%82%B9%EF%BC%8C%E4%B8%94%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E7%9A%84%E5%AD%90%E8%8A%82%E7%82%B9%E9%83%BD%E6%98%AF%E9%BB%91%E8%89%B2%E7%9A%84%E3%80%82**%0A%0A%E5%B0%86%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E6%B6%82%E7%BA%A2%EF%BC%8C%E5%B0%86%E5%BD%93%E5%89%8D%E8%8A%82%E7%82%B9%E6%8C%87%E5%90%91%E5%85%B6%E7%88%B6%E8%8A%82%E7%82%B9%EF%BC%8C%E5%B0%86%E5%85%B6%E7%88%B6%E8%8A%82%E7%82%B9%E6%8C%87%E5%90%91%E5%BD%93%E5%89%8D%E8%8A%82%E7%82%B9%E7%9A%84%E7%A5%96%E7%88%B6%E8%8A%82%E7%82%B9%EF%BC%8C%E7%BB%A7%E7%BB%AD%E5%BE%80%E6%A0%91%E6%A0%B9%E9%80%92%E5%BD%92%E5%88%A4%E6%96%AD%E4%BB%A5%E5%8F%8A%E8%B0%83%E6%95%B4%EF%BC%9B%0A%0A%23%23%23%23%23%204.1.3%20%E5%88%A0%E9%99%A4%E6%93%8D%E4%BD%9C-case%203%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/6362ebe6-440b-4123-b108-0dbbac880159.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F546%3A1)%0A%0A**%E5%BE%85%E8%B0%83%E6%95%B4%E7%9A%84%E8%8A%82%E7%82%B9%E7%9A%84%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E6%98%AF%E9%BB%91%E8%89%B2%E7%9A%84%E8%8A%82%E7%82%B9%EF%BC%8C%E4%B8%94%E5%92%8C%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E5%9C%A8%E4%B8%80%E6%9D%A1%E6%96%9C%E7%BA%BF%E4%B8%8A%E7%9A%84%E5%AD%90%E8%8A%82%E7%82%B9%E4%B9%9F%E6%98%AF%E9%BB%91%E8%89%B2%EF%BC%8C%E5%8F%A6%E4%B8%80%E4%B8%AA%E5%AD%90%E8%8A%82%E7%82%B9%E6%98%AF%E7%BA%A2%E8%89%B2%E3%80%82**%0A%0A%E6%8A%8A%E5%BD%93%E5%89%8D%E8%8A%82%E7%82%B9%E7%9A%84%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E6%B6%82%E7%BA%A2%EF%BC%8C%E6%8A%8A%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E7%9A%84%E5%B7%A6%E5%AD%90%E8%8A%82%E7%82%B9%E6%B6%82%E9%BB%91%EF%BC%8C%E7%84%B6%E5%90%8E%E4%BB%A5%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E4%BD%9C%E4%B8%BA%E6%94%AF%E7%82%B9%E5%81%9A%E5%8F%B3%E6%97%8B%E6%93%8D%E4%BD%9C%E3%80%82%0A%0Acase%203%E7%9A%84%E5%88%A0%E9%99%A4%E6%93%8D%E4%BD%9C%E6%98%AF%E4%B8%80%E4%B8%AA%E4%B8%AD%E9%97%B4%E6%AD%A5%E9%AA%A4%EF%BC%8C%E5%AE%83%E7%9A%84%E7%9B%AE%E7%9A%84%E6%98%AF%E5%B0%86%E5%B7%A6%E8%BE%B9%E7%9A%84%E7%BA%A2%E8%89%B2%E8%8A%82%E7%82%B9%E5%80%9F%E8%B0%83%E8%BF%87%E6%9D%A5%EF%BC%8C%E8%BF%99%E6%A0%B7%E5%B0%B1%E5%8F%AF%E4%BB%A5%E8%BD%AC%E6%8D%A2%E6%88%90case%204%0A%0A%23%23%23%23%23%204.1.4%20%E5%88%A0%E9%99%A4%E6%93%8D%E4%BD%9C-case%204%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/988225d6-f979-4d6a-b48a-238d1d9bb043.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F545%3A1)%0A%0A**%E5%BE%85%E8%B0%83%E6%95%B4%E7%9A%84%E8%8A%82%E7%82%B9%E7%9A%84%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E6%98%AF%E9%BB%91%E8%89%B2%E7%9A%84%E8%8A%82%E7%82%B9%EF%BC%8C%E4%B8%94%E5%92%8C%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E5%9C%A8%E4%B8%80%E6%9D%A1%E6%96%9C%E7%BA%BF%E4%B8%8A%E7%9A%84%E5%AD%90%E8%8A%82%E7%82%B9%E6%98%AF%E7%BA%A2%E8%89%B2%EF%BC%8C%E5%8F%A6%E4%B8%80%E4%B8%AA%E5%AD%90%E8%8A%82%E7%82%B9%E4%BB%BB%E6%84%8F**%0A%0A%E6%8A%8A%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E6%B6%82%E6%88%90%E7%88%B6%E8%8A%82%E7%82%B9%E7%9A%84%E9%A2%9C%E8%89%B2%EF%BC%8C%E5%86%8D%E6%8A%8A%E7%88%B6%E8%8A%82%E7%82%B9%E6%B6%82%E9%BB%91%EF%BC%8C%E6%8A%8A%E5%85%84%E5%BC%9F%E8%8A%82%E7%82%B9%E7%9A%84%E5%8F%B3%E5%AD%90%E8%8A%82%E7%82%B9%E6%B6%82%E9%BB%91%EF%BC%8C%E7%84%B6%E5%90%8E%E4%BB%A5%E5%BD%93%E5%89%8D%E8%8A%82%E7%82%B9%E7%9A%84%E7%88%B6%E8%8A%82%E7%82%B9%E4%B8%BA%E6%94%AF%E7%82%B9%E5%81%9A%E5%B7%A6%E6%97%8B%E6%93%8D%E4%BD%9C%E3%80%82%0A%0A%0A%23%23%20%E4%B8%89%20.%20B%E6%A0%91%E3%80%81B%2B%E6%A0%91%E3%80%81B*%E6%A0%91%20%0A%0A%23%23%23%203.1%20B%E6%A0%91(B-%E6%A0%91)%0A%23%23%23%23%203.1.1%20B%E6%A0%91%E7%AE%80%E4%BB%8B%0A*%20B-%E6%A0%91%E6%98%AF%E4%B8%80%E7%A7%8D%E5%A4%9A%E8%B7%AF%E6%90%9C%E7%B4%A2%E6%A0%91%EF%BC%88%E5%B9%B6%E4%B8%8D%E4%B8%80%E5%AE%9A%E6%98%AF%E4%BA%8C%E5%8F%89%E7%9A%84%EF%BC%89%0A*%201970%E5%B9%B4%EF%BC%8CR.Bayer%E5%92%8CE.mccreight%E6%8F%90%E5%87%BA%E4%BA%86%E4%B8%80%E7%A7%8D%E9%80%82%E7%94%A8%E4%BA%8E%E5%A4%96%E6%9F%A5%E6%89%BE%E7%9A%84%E6%A0%91%EF%BC%8C%E5%AE%83%E6%98%AF%E4%B8%80%E7%A7%8D%E5%B9%B3%E8%A1%A1%E7%9A%84%E5%A4%9A%E5%8F%89%E6%A0%91%EF%BC%8C%E7%A7%B0%E4%B8%BAB%E6%A0%91%EF%BC%88%E6%88%96B-%E6%A0%91%E3%80%81B_%E6%A0%91%EF%BC%89%E3%80%82%0A%0A%0AB-Tree%E7%9A%84%E6%8E%A5%E7%82%B9%E7%BB%93%E6%9E%84B-tree%E4%B8%AD%EF%BC%8C%E6%AF%8F%E4%B8%AA**%E7%BB%93%E7%82%B9**%E5%8C%85%E5%90%AB%EF%BC%9A%0A%3E%E6%9C%AC%E7%BB%93%E7%82%B9%E6%89%80%E5%90%AB%E5%85%B3%E9%94%AE%E5%AD%97%E7%9A%84%E4%B8%AA%E6%95%B0%EF%BC%9B%0A%E6%8C%87%E5%90%91%E7%88%B6%E7%BB%93%E7%82%B9%E7%9A%84%E6%8C%87%E9%92%88%EF%BC%9B%0A%E5%85%B3%E9%94%AE%E5%AD%97%EF%BC%9B%0A%E6%8C%87%E5%90%91%E5%AD%90%E7%BB%93%E7%82%B9%E7%9A%84%E6%8C%87%E9%92%88%E6%95%B0%E7%BB%84%EF%BC%9B%0A%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/7bf500f5-bbc5-4e20-9cd8-5656e610ce61.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F551%3A1)%0A%0A%0A%E4%B8%80%E6%A3%B5m%E9%98%B6B%E6%A0%91(balanced%20tree%20of%20order%20m)%E6%98%AF%E4%B8%80%E6%A3%B5%E5%B9%B3%E8%A1%A1%E7%9A%84m%E8%B7%AF%E6%90%9C%E7%B4%A2%E6%A0%91%E3%80%82%E5%AE%83%E6%88%96%E8%80%85%E6%98%AF%E7%A9%BA%E6%A0%91%EF%BC%8C%E6%88%96%E8%80%85%E6%98%AF%E6%BB%A1%E8%B6%B3%E4%B8%8B%E5%88%97%E6%80%A7%E8%B4%A8%E7%9A%84%E6%A0%91%EF%BC%9A%0A1%E3%80%81%E6%A0%B9%E7%BB%93%E7%82%B9%E8%87%B3%E5%B0%91%E6%9C%89%E4%B8%A4%E4%B8%AA%E5%AD%90%E5%A5%B3%EF%BC%9B%0A2%E3%80%81%E6%AF%8F%E4%B8%AA%E9%9D%9E%E6%A0%B9%E8%8A%82%E7%82%B9%E6%89%80%E5%8C%85%E5%90%AB%E7%9A%84%E5%85%B3%E9%94%AE%E5%AD%97%E4%B8%AA%E6%95%B0%20j%20%E6%BB%A1%E8%B6%B3%EF%BC%9Am%2F2%20-%201%20%3C%3D%20j%20%3C%3D%20m%20-%201%EF%BC%9B%0A3%E3%80%81%E9%99%A4%E6%A0%B9%E7%BB%93%E7%82%B9%E4%BB%A5%E5%A4%96%E7%9A%84%E6%89%80%E6%9C%89%E7%BB%93%E7%82%B9%EF%BC%88%E4%B8%8D%E5%8C%85%E6%8B%AC%E5%8F%B6%E5%AD%90%E7%BB%93%E7%82%B9%EF%BC%89%E7%9A%84%E5%BA%A6%E6%95%B0%E6%AD%A3%E5%A5%BD%E6%98%AF%E5%85%B3%E9%94%AE%E5%AD%97%E6%80%BB%E6%95%B0%E5%8A%A01%EF%BC%8C%E6%95%85%E5%86%85%E9%83%A8%E5%AD%90%E6%A0%91%E4%B8%AA%E6%95%B0%20k%20%E6%BB%A1%E8%B6%B3%EF%BC%9Am%2F2%20%3C%3D%20k%20%3C%3D%20m%20%EF%BC%9B%0A4%E3%80%81%E6%89%80%E6%9C%89%E7%9A%84%E5%8F%B6%E5%AD%90%E7%BB%93%E7%82%B9%E9%83%BD%E4%BD%8D%E4%BA%8E%E5%90%8C%E4%B8%80%E5%B1%82%E3%80%82%0A%0A%23%23%23%23%203.1.2%20B%E6%A0%91%E7%89%B9%E7%82%B9%0A%0A%E6%98%AF%E4%B8%80%E7%A7%8D%E5%A4%9A%E8%B7%AF%E6%90%9C%E7%B4%A2%E6%A0%91%EF%BC%88%E5%B9%B6%E4%B8%8D%E6%98%AF%E4%BA%8C%E5%8F%89%E7%9A%84%EF%BC%89%EF%BC%9A%0A1.%20%E5%AE%9A%E4%B9%89%E4%BB%BB%E6%84%8F%E9%9D%9E%E5%8F%B6%E5%AD%90%E7%BB%93%E7%82%B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D%90%E7%BB%93%E7%82%B9%E7%9A%84%E6%8C%87%E9%92%88%EF%BC%9AP%5B1%5D%2C%20P%5B2%5D%2C%20%E2%80%A6%2C%20P%5BM%5D%EF%BC%9B%E5%85%B6%E4%B8%ADP%5B1%5D%E6%8C%87%E5%90%91%E5%85%B3%E9%94%AE%E5%AD%97%E5%B0%8F%E4%BA%8EK%5B1%5D%E7%9A%84%E5%AD%90%E6%A0%91%EF%BC%8CP%5BM%5D%E6%8C%87%E5%90%91%E5%85%B3%E9%94%AE%E5%AD%97%E5%A4%A7%E4%BA%8EK%5BM-1%5D%E7%9A%84%E5%AD%90%E6%A0%91%EF%BC%8C%E5%85%B6%E5%AE%83P%5Bi%5D%E6%8C%87%E5%90%91%E5%85%B3%E9%94%AE%E5%AD%97%E5%B1%9E%E4%BA%8E(K%5Bi-1%5D%2C%20K%5Bi%5D)%E7%9A%84%E5%AD%90%E6%A0%91%EF%BC%9B%0A8.%20%E6%89%80%E6%9C%89%E5%8F%B6%E5%AD%90%E7%BB%93%E7%82%B9%E4%BD%8D%E4%BA%8E%E5%90%8C%E4%B8%80%E5%B1%82%EF%BC%9B%0A%0A%23%23%23%23%203.1.3%20B%E6%A0%91%E7%9A%84%E6%9F%A5%E6%89%BE%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/90d33d44-16aa-4bdb-a1a4-71b6b453bfb9.png.png%5D(en-resource%3A%2F%2Fdatabase%2F552%3A1)%0A%0A%E5%9C%A8B-%E6%A0%91%E4%B8%AD%E6%9F%A5%E6%89%BE%E7%BB%99%E5%AE%9A%E5%85%B3%E9%94%AE%E5%AD%97%E7%9A%84%E6%96%B9%E6%B3%95%E7%B1%BB%E4%BC%BC%E4%BA%8E%E4%BA%8C%E5%8F%89%E6%8E%92%E5%BA%8F%E6%A0%91%E4%B8%8A%E7%9A%84%E6%9F%A5%E6%89%BE%E3%80%82%E4%B8%8D%E5%90%8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9C%89%E5%BA%8F%EF%BC%8C%E5%85%B6%E6%8F%92%E5%85%A5%E4%B8%8E%E4%BF%AE%E6%94%B9%E6%8B%A5%E6%9C%89%E8%BE%83%E7%A8%B3%E5%AE%9A%E7%9A%84%E5%AF%B9%E6%95%B0%E6%97%B6%E9%97%B4%E5%A4%8D%E6%9D%82%E5%BA%A6%E3%80%82B%2B%20%E6%A0%91%E5%85%83%E7%B4%A0%E8%87%AA%E5%BA%95%E5%90%91%E4%B8%8A%E6%8F%92%E5%85%A5%E3%80%82%0A%0A%23%23%23%23%203.2.2%20B%2B%E6%A0%91%E5%AE%9A%E4%B9%89%0AB%2B%E6%A0%91%E6%98%AF%E5%BA%94%E6%96%87%E4%BB%B6%E7%B3%BB%E7%BB%9F%E6%89%80%E9%9C%80%E8%80%8C%E5%87%BA%E7%9A%84%E4%B8%80%E7%A7%8DB-%E6%A0%91%E7%9A%84%E5%8F%98%E5%9E%8B%E6%A0%91%E3%80%82%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/f4b81940-c17e-4625-b0a7-849a6cc69cdc.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F553%3A1)%0A%0A%E4%B8%80%E6%A3%B5m%E9%98%B6%E7%9A%84B%2B%E6%A0%91%E5%92%8Cm%E9%98%B6%E7%9A%84B-%E6%A0%91%E7%9A%84%E5%B7%AE%E5%BC%82%E5%9C%A8%E4%BA%8E%EF%BC%9A%0A1.%E6%9C%89n%E6%A3%B5%E5%AD%90%E6%A0%91%E7%9A%84%E7%BB%93%E7%82%B9%E4%B8%AD%E5%90%AB%E6%9C%89n%E4%B8%AA%E5%85%B3%E9%94%AE%E5%AD%97%EF%BC%8C%E6%AF%8F%E4%B8%AA**%E5%85%B3%E9%94%AE%E5%AD%97%E4%B8%8D%E4%BF%9D%E5%AD%98%E6%95%B0%E6%8D%AE%EF%BC%8C%E5%8F%AA%E7%94%A8%E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%E5%BD%93%E4%BA%8E%E6%98%AF%E5%AD%98%E5%82%A8%EF%BC%88%E5%85%B3%E9%94%AE%E5%AD%97%EF%BC%89%E6%95%B0%E6%8D%AE%E7%9A%84%E6%95%B0%E6%8D%AE%E5%B1%82%EF%BC%9B%0A4.%20%E6%9B%B4%E9%80%82%E5%90%88%E6%96%87%E4%BB%B6%E7%B4%A2%E5%BC%95%E7%B3%BB%E7%BB%9F%EF%BC%9B%0A%0A%23%23%23%23%203.2.4%20B%2B%E6%A0%91%20vs%20B%E6%A0%91%0A%E4%B8%BA%E4%BB%80%E4%B9%88%E8%AF%B4B%2B-tree%E6%AF%94B%20%E6%A0%91%E6%9B%B4%E9%80%82%E5%90%88%E5%AE%9E%E9%99%85%E5%BA%94%E7%94%A8%E4%B8%AD%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E7%9A%84%E6%96%87%E4%BB%B6%E7%B4%A2%E5%BC%95%E5%92%8C%E6%95%B0%E6%8D%AE%E5%BA%93%E7%B4%A2%E5%BC%95%EF%BC%9F%0A%0A*%20B%2B-tree%E7%9A%84%E7%A3%81%E7%9B%98%E8%AF%BB%E5%86%99%E4%BB%A3%E4%BB%B7%E6%9B%B4%E4%BD%8E%0AB%2B-tree%E7%9A%84%E5%86%85%E9%83%A8%E7%BB%93%E7%82%B9%E5%B9%B6%E6%B2%A1%E6%9C%89%E6%8C%87%E5%90%91%E5%85%B3%E9%94%AE%E5%AD%97%E5%85%B7%E4%BD%93%E4%BF%A1%E6%81%AF%E7%9A%84%E6%8C%87%E9%92%88%E3%80%82%E5%9B%A0%E6%AD%A4%E5%85%B6%E5%86%85%E9%83%A8%E7%BB%93%E7%82%B9%E7%9B%B8%E5%AF%B9B%20%E6%A0%91%E6%9B%B4%E5%B0%8F%E3%80%82%E5%A6%82%E6%9E%9C%E6%8A%8A%E6%89%80%E6%9C%89%E5%90%8C%E4%B8%80%E5%86%85%E9%83%A8%E7%BB%93%E7%82%B9%E7%9A%84%E5%85%B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E8%A6%812%E4%B8%AA%E7%9B%98%E5%BF%AB%E3%80%82%E8%80%8CB%2B%20%E6%A0%91%E5%86%85%E9%83%A8%E7%BB%93%E7%82%B9%E5%8F%AA%E9%9C%80%E8%A6%811%E4%B8%AA%E7%9B%98%E5%BF%AB%E3%80%82%E5%BD%93%E9%9C%80%E8%A6%81%E6%8A%8A%E5%86%85%E9%83%A8%E7%BB%93%E7%82%B9%E8%AF%BB%E5%85%A5%E5%86%85%E5%AD%98%E4%B8%AD%E7%9A%84%E6%97%B6%E5%80%99%EF%BC%8CB%20%E6%A0%91%E5%B0%B1%E6%AF%94B%2B%20%E6%A0%91%E5%A4%9A%E4%B8%80%E6%AC%A1%E7%9B%98%E5%9D%97%E6%9F%A5%E6%89%BE%E6%97%B6%E9%97%B4(%E5%9C%A8%E7%A3%81%E7%9B%98%E4%B8%AD%E5%B0%B1%E6%98%AF%E7%9B%98%E7%89%87%E6%97%8B%E8%BD%AC%E7%9A%84%E6%97%B6%E9%97%B4)%E3%80%82%0A*%20B%2B-tree%E7%9A%84%E6%9F%A5%E8%AF%A2%E6%95%88%E7%8E%87%E6%9B%B4%E5%8A%A0%E7%A8%B3%E5%AE%9A%0A%E7%94%B1%E4%BA%8E%E9%9D%9E%E7%BB%88%E7%BB%93%E7%82%B9%E5%B9%B6%E4%B8%8D%E6%98%AF%E6%9C%80%E7%BB%88%E6%8C%87%E5%90%91%E6%96%87%E4%BB%B6%E5%86%85%E5%AE%B9%E7%9A%84%E7%BB%93%E7%82%B9%EF%BC%8C%E8%80%8C%E5%8F%AA%E6%98%AF%E5%8F%B6%E5%AD%90%E7%BB%93%E7%82%B9%E4%B8%AD%E5%85%B3%E9%94%AE%E5%AD%97%E7%9A%84%E7%B4%A2%E5%BC%95%E3%80%82%E6%89%80%E4%BB%A5%E4%BB%BB%E4%BD%95%E5%85%B3%E9%94%AE%E5%AD%97%E7%9A%84%E6%9F%A5%E6%89%BE%E5%BF%85%E9%A1%BB%E8%B5%B0%E4%B8%80%E6%9D%A1%E4%BB%8E%E6%A0%B9%E7%BB%93%E7%82%B9%E5%88%B0%E5%8F%B6%E5%AD%90%E7%BB%93%E7%82%B9%E7%9A%84%E8%B7%AF%E3%80%82%E6%89%80%E6%9C%89%E5%85%B3%E9%94%AE%E5%AD%97%E6%9F%A5%E8%AF%A2%E7%9A%84%E8%B7%AF%E5%BE%84%E9%95%BF%E5%BA%A6%E7%9B%B8%E5%90%8C%EF%BC%8C%E5%AF%BC%E8%87%B4%E6%AF%8F%E4%B8%80%E4%B8%AA%E6%95%B0%E6%8D%AE%E7%9A%84%E6%9F%A5%E8%AF%A2%E6%95%88%E7%8E%87%E7%9B%B8%E5%BD%93%E3%80%82%0A%0A%23%23%23%203.3%20B*%E6%A0%91%0A%23%23%23%23%203.3.1%20B*%E6%A0%91%E7%AE%80%E4%BB%8B%0A%E6%98%AFB%2B%E6%A0%91%E7%9A%84%E5%8F%98%E4%BD%93%EF%BC%8C%E5%9C%A8B%2B%E6%A0%91%E7%9A%84%E9%9D%9E%E6%A0%B9%E5%92%8C%E9%9D%9E%E5%8F%B6%E5%AD%90%E7%BB%93%E7%82%B9%E5%86%8D%E5%A2%9E%E5%8A%A0%E6%8C%87%E5%90%91%E5%85%84%E5%BC%9F%E7%9A%84%E6%8C%87%E9%92%88%EF%BC%9B%0AB*%E6%A0%91%E5%AE%9A%E4%B9%89%E4%BA%86%E9%9D%9E%E5%8F%B6%E5%AD%90%E7%BB%93%E7%82%B9%E5%85%B3%E9%94%AE%E5%AD%97%E4%B8%AA%E6%95%B0%E8%87%B3%E5%B0%91%E4%B8%BA(2%2F3)*M%EF%BC%8C%E5%8D%B3%E5%9D%97%E7%9A%84%E6%9C%80%E4%BD%8E%E4%BD%BF%E7%94%A8%E7%8E%87%E4%B8%BA2%2F3%EF%BC%88%E4%BB%A3%E6%9B%BFB%2B%E6%A0%91%E7%9A%841%2F2%EF%BC%89%EF%BC%9B%0A!%5Bhttps://cdn-images.postach.io/5193531f-2650-40fd-90d9-0c7df1b66f2d/65bebcb3-042a-47e2-ae94-527bb73cc220/2306ffe6-b58e-4a04-bd0b-5bb567c5604a.jpg.jpeg%5D(en-resource%3A%2F%2Fdatabase%2F554%3A1)%0A%0A%23%23%23%23%203.3.2%20B*%E6%A0%91%20vs%20B%2B%E6%A0%91%0A%0A*%20B%2B%E6%A0%91%E7%9A%84%E5%88%86%E8%A3%82%EF%BC%9A%0A%E5%BD%93%E4%B8%80%E4%B8%AA%E7%BB%93%E7%82%B9%E6%BB%A1%E6%97%B6%EF%BC%8C%E5%88%86%E9%85%8D%E4%B8%80%E4%B8%AA%E6%96%B0%E7%9A%84%E7%BB%93%E7%82%B9%EF%BC%8C%E5%B9%B6%E5%B0%86%E5%8E%9F%E7%BB%93%E7%82%B9%E4%B8%AD1%2F2%E7%9A%84%E6%95%B0%E6%8D%AE%E5%A4%8D%E5%88%B6%E5%88%B0%E6%96%B0%E7%BB%93%E7%82%B9%EF%BC%8C%E6%9C%80%E5%90%8E%E5%9C%A8%E7%88%B6%E7%BB%93%E7%82%B9%E4%B8%AD%E5%A2%9E%E5%8A%A0%E6%96%B0%E7%BB%93%E7%82%B9%E7%9A%84%E6%8C%87%E9%92%88%EF%BC%9BB%2B%E6%A0%91%E7%9A%84%E5%88%86%E8%A3%82%E5%8F%AA%E5%BD%B1%E5%93%8D%E5%8E%9F%E7%BB%93%E7%82%B9%E5%92%8C%E7%88%B6%E7%BB%93%E7%82%B9%EF%BC%8C%E8%80%8C%E4%B8%8D%E4%BC%9A%E5%BD%B1%E5%93%8D%E5%85%84%E5%BC%9F%E7%BB%93%E7%82%B9%EF%BC%8C%E6%89%80%E4%BB%A5%E5%AE%83%E4%B8%8D%E9%9C%80%E8%A6%81%E6%8C%87%E5%90%91%E5%85%84%E5%BC%9F%E7%9A%84%E6%8C%87%E9%92%88%EF%BC%9B%0A%0A*%20B*%E6%A0%91%E7%9A%84%E5%88%86%E8%A3%82%EF%BC%9A%0A%E5%BD%93%E4%B8%80%E4%B8%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B0%B1%E6%98%AF%E5%9C%A8%E8%AF%BB%E5%86%99%E4%B9%8B%E9%97%B4%E5%8F%96%E5%BE%97%E5%B9%B3%E8%A1%A1%EF%BC%8C%E5%92%8CB%2B%E6%A0%91%E7%9B%B8%E6%AF%94%EF%BC%8C%E5%AE%83**%E7%89%BA%E7%89%B2%E4%BA%86%E9%83%A8%E5%88%86%E8%AF%BB%E6%80%A7%E8%83%BD%EF%BC%8C%E7%94%A8%E6%9D%A5%E5%A4%A7%E5%B9%85%E6%8F%90%E9%AB%98%E5%86%99%E6%80%A7%E8%83%BD%E3%80%82**%0A%0A%23%23%23%23%20%E5%8E%9F%E7%90%86%0A%0A%E5%AE%83%E7%9A%84%E5%8E%9F%E7%90%86%E6%98%AF%E6%8A%8A%E4%B8%80%E9%A2%97**%E5%A4%A7%E6%A0%91%E6%8B%86%E5%88%86%E6%88%90N%E6%A3%B5%E5%B0%8F%E6%A0%91**%EF%BC%8C%20%E5%AE%83**%E9%A6%96%E5%85%88%E5%86%99%E5%85%A5%E5%88%B0%E5%86%85%E5%AD%98**%E4%B8%AD%EF%BC%88%E5%86%85%E5%AD%98%E6%B2%A1%E6%9C%89%E5%AF%BB%E9%81%93%E9%80%9F%E5%BA%A6%E7%9A%84%E9%97%AE%E9%A2%98%EF%BC%8C%E9%9A%8F%E6%9C%BA%E5%86%99%E7%9A%84%E6%80%A7%E8%83%BD%E5%BE%97%E5%88%B0%E5%A4%A7%E5%B9%85%E6%8F%90%E5%8D%87%EF%BC%89%EF%BC%8C%E5%9C%A8%E5%86%85%E5%AD%98%E4%B8%AD%E6%9E%84%E5%BB%BA%E4%B8%80%E9%A2%97**%E6%9C%89%E5%BA%8F%E5%B0%8F%E6%A0%91**%EF%BC%8C%E9%9A%8F%E7%9D%80%E5%B0%8F%E6%A0%91%E8%B6%8A%E6%9D%A5%E8%B6%8A%E5%A4%A7%EF%BC%8C**%E5%86%85%E5%AD%98%E7%9A%84%E5%B0%8F%E6%A0%91%E4%BC%9Afl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98%E4%B8%AD%E7%9A%84%E6%95%B0%E6%8D%AE%E4%BC%9A%E4%B8%A2%E5%A4%B1%EF%BC%8C%E5%9B%A0%E6%AD%A4%E4%B8%BA%E4%BA%86%E4%BF%9D%E6%8A%A4%E5%86%85%E5%AD%98%E4%B8%AD%E7%9A%84%E6%95%B0%E6%8D%AE%EF%BC%8C%E9%9C%80%E8%A6%81%E5%9C%A8%E7%A3%81%E7%9B%98%E4%B8%8A%E5%85%88%E8%AE%B0%E5%BD%95logfile%EF%BC%8C%E5%BD%93%E5%86%85%E5%AD%98%E4%B8%AD%E7%9A%84%E6%95%B0%E6%8D%AEflush%E5%88%B0%E7%A3%81%E7%9B%98%E4%B8%8A%E6%97%B6%EF%BC%8C%E5%B0%B1%E5%8F%AF%E4%BB%A5%E6%8A%9B%E5%BC%83%E7%9B%B8%E5%BA%94%E7%9A%84Logfile%E3%80%82%0A%0A2%EF%BC%89%E4%BB%80%E4%B9%88%E6%98%AFmemstore%2C%20storefile%EF%BC%9F%E5%BE%88%E7%AE%80%E5%8D%95%EF%BC%8C%E4%B8%8A%E9%9D%A2%E8%AF%B4%E8%BF%87%EF%BC%8CLSM%E6%A0%91%E5%B0%B1%E6%98%AF%E4%B8%80%E5%A0%86%E5%B0%8F%E6%A0%91%EF%BC%8C%E5%9C%A8%E5%86%85%E5%AD%98%E4%B8%AD%E7%9A%84%E5%B0%8F%E6%A0%91%E5%8D%B3memstore%EF%BC%8C%E6%AF%8F%E6%AC%A1flush%EF%BC%8C%E5%86%85%E5%AD%98%E4%B8%AD%E7%9A%84memstore%E5%8F%98%E6%88%90%E7%A3%81%E7%9B%98%E4%B8%8A%E4%B8%80%E4%B8%AA%E6%96%B0%E7%9A%84storefile%E3%80%82%0A%0A3%EF%BC%89%E4%B8%BA%E4%BB%80%E4%B9%88%E4%BC%9A%E6%9C%89compact%EF%BC%9F%E5%BE%88%E7%AE%80%E5%8D%95%EF%BC%8C%E9%9A%8F%E7%9D%80%E5%B0%8F%E6%A0%91%E8%B6%8A%E6%9D%A5%E8%B6%8A%E5%A4%9A%EF%BC%8C%E8%AF%BB%E7%9A%84%E6%80%A7%E8%83%BD%E4%BC%9A%E8%B6%8A%E6%9D%A5%E8%B6%8A%E5%B7%AE%EF%BC%8C%E5%9B%A0%E6%AD%A4%E9%9C%80%E8%A6%81%E5%9C%A8%E9%80%82%E5%BD%93%E7%9A%84%E6%97%B6%E5%80%99%EF%BC%8C%E5%AF%B9%E7%A3%81%E7%9B%98%E4%B8%AD%E7%9A%84%E5%B0%8F%E6%A0%91%E8%BF%9B%E8%A1%8Cmerge%EF%BC%8C%E5%A4%9A%E6%A3%B5%E5%B0%8F%E6%A0%91%E5%8F%98%E6%88%90%E4%B8%80%E9%A2%97%E5%A4%A7%E6%A0%91%E3%80%82%0A&lt;/center&gt;&lt;/div&gt;
</content>
  </entry>
</feed>
