<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

 <title>张爱强的博客/Eric Zhang's Blog</title>
 <link href="https://zaqweb.github.io/atom.xml" rel="self"/>
 <link href="https://zaqweb.github.io"/>
 <updated>2018-04-26T04:52:53+00:00</updated>
 <id>https://zaqweb.github.io</id>
 <author>
   <name>zaqweb</name>
   <email>zaqweb@live.com</email>
 </author>

 
 <entry>
   <title>Spring 核心之IOC容器</title>
   <link href="https://zaqweb.github.io/spring/2017/12/02/spring-ioc/"/>
   <updated>2017-12-02T17:30:09+00:00</updated>
   <id>https://zaqweb.github.io/spring/2017/12/02/spring-ioc</id>
   <content type="html">&lt;p&gt;不得不说Spring框架非常强大而复杂；要想全面掌握Spring框架的方方面面需要大量的学习时间以及项目实践。而理解Spring核心原理是真正精通Spring必不可少的一环。利用本篇文章带领大家复习一下Spring的核心之一IOC容器，即控制反转或依赖注入。&lt;/p&gt;

&lt;h1 id=&quot;spring-framework&quot;&gt;Spring Framework&lt;/h1&gt;
&lt;p&gt;笔者最初接触Spring框架只是使用Spring framework作为bean的管理容器，使用Struts作为web MVC框架，使用JDBC原生Dao类访问数据库来开发Web项目。我想2012年以前参加工作的Java工程师应该都有类似的经验。而今天谈论Spring框架我们就应该说清楚讨论的是&lt;code class=&quot;highlighter-rouge&quot;&gt;Spring core&lt;/code&gt;? &lt;code class=&quot;highlighter-rouge&quot;&gt;Spring web Mvc&lt;/code&gt;? &lt;code class=&quot;highlighter-rouge&quot;&gt;Spring cloud&lt;/code&gt;? &lt;code class=&quot;highlighter-rouge&quot;&gt;Spring Data&lt;/code&gt;? &lt;code class=&quot;highlighter-rouge&quot;&gt;Spring security&lt;/code&gt;? 还是&lt;code class=&quot;highlighter-rouge&quot;&gt;Spring boot&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;越来越多的分支项目被加入Spring框架，理解好Spring核心分支(Spring Framework)对于掌握好Spring其他项目的重要性不言而喻。下面这幅图来源于Spring.io官网，很好的展示了Spring Framework讨论的范畴，希望能将这幅图闹记于心。
&lt;img src=&quot;/assets/img/spring/spring-overview.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;framework-modules框架模块&quot;&gt;Framework Modules（框架模块）&lt;/h2&gt;
&lt;p&gt;根据上图能够清晰的看到Spring Framework主要包含6个方面的内容：&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;核心容器(Core Container) – 核心中的核心&lt;/li&gt;
  &lt;li&gt;切面编程(AOP)&lt;/li&gt;
  &lt;li&gt;消息(Messaging)&lt;/li&gt;
  &lt;li&gt;数据访问(Data Access)&lt;/li&gt;
  &lt;li&gt;Web编程(MVC)&lt;/li&gt;
  &lt;li&gt;测试(Test)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;本章主要讨论第一点内容核心容器(IOC)。&lt;/p&gt;

&lt;h1 id=&quot;核心容器core-container&quot;&gt;核心容器(Core Container)&lt;/h1&gt;
&lt;p&gt;相信所有工程师都知道Spring框架最原始最基本最核心的功能是帮助我们管理Bean，那么将Spring的核心称之为一个存储Bean的容器是不是不难理解？  &lt;br /&gt;
所以，Spring的核心是一个容器，这个容器实现了控制反转(IoC)和依赖注入(DI)的特性，又称为IoC容器。&lt;/p&gt;

&lt;h2 id=&quot;ioc容器如何创建bean&quot;&gt;IoC容器如何创建Bean？&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;/assets/img/spring/container-magic.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;简单的回答就是IoC容器根据配置（XML或注解）来创建Bean，Bean在创建后被维护在Spring容器中随时可被使用，同时Spring容器负责维护Bean的生命周期。&lt;/p&gt;

&lt;p&gt;复杂点讲，需要说明容器创建，维护，销毁Bean的机制性细节，如&lt;code class=&quot;highlighter-rouge&quot;&gt;Bean生命周期&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;DI实现机制&lt;/code&gt;,&lt;code class=&quot;highlighter-rouge&quot;&gt;集合值配置&lt;/code&gt;,&lt;code class=&quot;highlighter-rouge&quot;&gt;集合值合并&lt;/code&gt;等。请参考阅读Spring IoC容器特性详解&lt;/p&gt;

&lt;p&gt;这里说的配置包括纯XML,基于注解,基于Java的三种配置Spring方式，Spring并不强迫我们使用哪一种，甚至是支持混合使用这几种配置的。由于XML的说明性强于注解，所以官方大部分配置细节都采用XML结构讲解。&lt;/p&gt;

&lt;p&gt;XML配置样例：&lt;/p&gt;

&lt;div class=&quot;language-xml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;beans&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;xmlns=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http://www.springframework.org/schema/beans&quot;&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;xmlns:xsi=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;xsi:schemaLocation=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;

    &lt;span class=&quot;nt&quot;&gt;&amp;lt;bean&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;...&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;...&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- collaborators and configuration for this bean go here --&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/bean&amp;gt;&lt;/span&gt;

    &lt;span class=&quot;nt&quot;&gt;&amp;lt;bean&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;...&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;...&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- collaborators and configuration for this bean go here --&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/bean&amp;gt;&lt;/span&gt;

    &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- more bean definitions go here --&amp;gt;&lt;/span&gt;

&lt;span class=&quot;nt&quot;&gt;&amp;lt;/beans&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;如何编写xml配置&quot;&gt;如何编写XML配置&lt;/h2&gt;
&lt;p&gt;事实上本章不应该讨论这个话题，应为文章关注的是Spring Framework的核心机制，而非具体操作。值得提及的有几点内容：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;结构化你的XML配置文件&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-xml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;beans&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;import&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;resource=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;services.xml&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;import&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;resource=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;resources/messageSource.xml&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;import&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;resource=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;/resources/themeSource.xml&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;

    &lt;span class=&quot;nt&quot;&gt;&amp;lt;bean&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;bean1&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;...&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;bean&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;bean2&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;...&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/beans&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;使用p-namespace&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;常规写法：&lt;/p&gt;

&lt;div class=&quot;language-xml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;bean&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;myDataSource&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;org.apache.commons.dbcp.BasicDataSource&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;destroy-method=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;close&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- results in a setDriverClassName(String) call --&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;property&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;driverClassName&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;value=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;com.mysql.jdbc.Driver&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;property&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;url&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;value=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;jdbc:mysql://localhost:3306/mydb&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;property&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;username&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;value=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;root&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;property&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;password&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;value=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;masterkaoli&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/bean&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;利用p-namespace简化xml结构，增强可读性。需要注意的是增加&lt;code class=&quot;highlighter-rouge&quot;&gt;xmlns:p=&quot;http://www.springframework.org/schema/p&lt;/code&gt; 命名空间&lt;/p&gt;

&lt;div class=&quot;language-xml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;beans&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;xmlns=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http://www.springframework.org/schema/beans&quot;&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;xmlns:xsi=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;xmlns:p=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http://www.springframework.org/schema/p&quot;&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;xsi:schemaLocation=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;

    &lt;span class=&quot;nt&quot;&gt;&amp;lt;bean&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;myDataSource&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;org.apache.commons.dbcp.BasicDataSource&quot;&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;destroy-method=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;close&quot;&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;p:driverClassName=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;com.mysql.jdbc.Driver&quot;&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;p:url=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;jdbc:mysql://localhost:3306/mydb&quot;&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;p:username=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;root&quot;&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;p:password=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;masterkaoli&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/beans&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;使用xml-or-注解&quot;&gt;使用XMl Or 注解&lt;/h2&gt;
&lt;p&gt;随着&lt;code class=&quot;highlighter-rouge&quot;&gt;Spring boot&lt;/code&gt;的出现，构建基于Spring的项目变得更为简单，大量注解被使用，不再看到xml的身影；甚至是配置文件也从properties变成了yml。&lt;/p&gt;

&lt;h2 id=&quot;理解spring容器上下文context&quot;&gt;理解Spring容器上下文(Context)&lt;/h2&gt;
</content>
 </entry>
 
 <entry>
   <title>每天一点小知识 String类</title>
   <link href="https://zaqweb.github.io/java/2017/12/01/tips-string/"/>
   <updated>2017-12-01T16:21:09+00:00</updated>
   <id>https://zaqweb.github.io/java/2017/12/01/tips-string</id>
   <content type="html">&lt;p&gt;String 类是java程序再常用不过的一个JDK级class，那么对于每天都要面对的String我们是否有足够的认识呢？
今天希望通过一些小知识点让大家能够深入掌握String对象的日常处理。&lt;/p&gt;

&lt;h1 id=&quot;string的存储结构&quot;&gt;String的存储结构&lt;/h1&gt;
&lt;p&gt;String类的每一个实例都使用一个数组（Array）最为底层存储数据结构。数组的类型为基本类型char，明白这一点之后我们应该意识到String类的绝大多数
API操作都是针对char数组的。例如indexOf,toUpperCase,toCharArray；这意味着很多操作会涉及到数组遍历。&lt;/p&gt;

&lt;h1 id=&quot;substring源码解读&quot;&gt;substring源码解读&lt;/h1&gt;

&lt;p&gt;代码非常简单，主要看最后一行&lt;code class=&quot;highlighter-rouge&quot;&gt;return (beginIndex == 0) ? this : new String(value, beginIndex, subLen);&lt;/code&gt; 如果截取下标从0开始则返回当前String对象，否则利用&lt;code class=&quot;highlighter-rouge&quot;&gt;public String(char value[], int offset, int count)&lt;/code&gt;构造一个指定区间的新String对象。&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;substring&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;beginIndex&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;beginIndex&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;StringIndexOutOfBoundsException&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;beginIndex&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;subLen&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;length&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;beginIndex&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;subLen&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;StringIndexOutOfBoundsException&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;subLen&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;beginIndex&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;beginIndex&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;subLen&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;indexof源码解读&quot;&gt;indexOf源码解读&lt;/h1&gt;

&lt;p&gt;作为程序员通常只需要调用indexOf(“find”)就能得到结果 ，但实际执行的是下面这段代码；”find”是需要查找的对象作为target被传入，
代码不是特别容易阅读，但是我们可以清晰的看到这种操作一定涉及数组遍历，所以如果能给定范围尽量使用多参调用来争取效率。&lt;/p&gt;

&lt;p&gt;需要特别说明的是：不是一般程序员想象的直接去查找”find”，而是先找到”f”，再继续往下匹配。为什么这样？可以思考一下！&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
&lt;span class=&quot;cm&quot;&gt;/**
     * Code shared by String and StringBuffer to do searches. The
     * source is the character array being searched, and the target
     * is the string being searched for.
     *
     * @param   source       the characters being searched.
     * @param   sourceOffset offset of the source string.
     * @param   sourceCount  count of the source string.
     * @param   target       the characters being searched for.
     * @param   targetOffset offset of the target string.
     * @param   targetCount  count of the target string.
     * @param   fromIndex    the index to begin searching from.
     */&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;indexOf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;source&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sourceOffset&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sourceCount&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;targetOffset&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;targetCount&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fromIndex&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fromIndex&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sourceCount&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;targetCount&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sourceCount&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fromIndex&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;fromIndex&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;targetCount&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fromIndex&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;first&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;targetOffset&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;];&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;max&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sourceOffset&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sourceCount&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;targetCount&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sourceOffset&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fromIndex&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;cm&quot;&gt;/* Look for first character. */&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;source&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(++&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;max&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;source&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

            &lt;span class=&quot;cm&quot;&gt;/* Found first character, now look at the rest of v2 */&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
                &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;end&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;targetCount&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;targetOffset&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;end&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;source&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
                        &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;];&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++);&lt;/span&gt;

                &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
                    &lt;span class=&quot;cm&quot;&gt;/* Found whole string. */&lt;/span&gt;
                    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sourceOffset&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>mvn package javax.crypto does not exist</title>
   <link href="https://zaqweb.github.io/others/2017/09/22/mvn-package/"/>
   <updated>2017-09-22T15:30:09+00:00</updated>
   <id>https://zaqweb.github.io/others/2017/09/22/mvn-package</id>
   <content type="html">&lt;h1 id=&quot;问题现象&quot;&gt;问题现象&lt;/h1&gt;
&lt;p&gt;有一次同事提交了代码Jenkins平台自动打包失败，而同事在本地是Eclipse开发环境使用&lt;code class=&quot;highlighter-rouge&quot;&gt;mvn tomcat7:run&lt;/code&gt; 是可以成功运行项目的。 &lt;br /&gt;
区别是Jenkins平台使用&lt;code class=&quot;highlighter-rouge&quot;&gt;mvn clean package&lt;/code&gt;打包。错误说明是挺明显的&lt;strong&gt;package javax.crypto does not exist&lt;/strong&gt;，但是在开发环境中没有任何问题，build path中包含了jre目录自然能够引用到jce.jar中的类。&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;[INFO] 49 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] services-consumer .......................... SUCCESS [  0.874 s]
[INFO] services-consumer-rest ..................... FAILURE [  2.240 s]
[INFO] job-consumer ............................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 34.749 s
[INFO] Finished at: 2017-09-22T15:39:10+08:00
[INFO] Final Memory: 127M/430M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project services-consumer-rest: Compilation failure: Compilation failure:
[ERROR] /Users/ervices-consumer-rest/src/main/java/com/test/portal/utils/RSAUtils.java:[18,19] error: package javax.crypto does not exist
[ERROR] /Users/services/services-consumer-rest/src/main/java/com/test/portal/utils/DesUtil.java:[11,19] error: package javax.crypto does not exist
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;报错的RSAUtils.java文件内容，包引用部分&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;javax.crypto.BadPaddingException&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;javax.crypto.Cipher&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;javax.crypto.IllegalBlockSizeException&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;javax.crypto.NoSuchPaddingException&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;javax.crypto.SecretKey&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;javax.crypto.SecretKeyFactory&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;javax.crypto.spec.DESKeySpec&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;javax.crypto.spec.IvParameterSpec&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;问题分析&quot;&gt;问题分析&lt;/h1&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;怀疑Jenkins平台问题
为了验证这个怀疑，我同步了最新的代码在本地使用&lt;code class=&quot;highlighter-rouge&quot;&gt;mvn clean package&lt;/code&gt; 得到同样的错误信息，证明这个怀疑不成立。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Maven编译环境JDK问题
既然IDE开发环境中编译时没有问题的，而使用&lt;code class=&quot;highlighter-rouge&quot;&gt;mvn compile&lt;/code&gt; &lt;code class=&quot;highlighter-rouge&quot;&gt;package&lt;/code&gt; &lt;code class=&quot;highlighter-rouge&quot;&gt;install&lt;/code&gt; 都报错很容易联想到mvn的运行时环境中没有引用到jce.jar。&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;font color=&quot;#FF0099&quot;&gt; 那么问题就变成了Maven是如何指定编译环境的？ &lt;/font&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;请参见官方文档 http://maven.apache.org/plugins/maven-compiler-plugin/index.html&lt;/p&gt;

&lt;h1 id=&quot;解决方法&quot;&gt;解决方法&lt;/h1&gt;
&lt;p&gt;maven 是通过插件来管理编译的，所以在pom.xml的&lt;code class=&quot;highlighter-rouge&quot;&gt;maven-compiler-plugin&lt;/code&gt;可以设定编译器的lib包路径，
添加上${java.home}/lib/jce.jar&lt;/p&gt;

&lt;div class=&quot;language-xml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;build&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;plugins&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;plugin&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;nt&quot;&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.apache.maven.plugins&lt;span class=&quot;nt&quot;&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;  
      &lt;span class=&quot;nt&quot;&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;maven-compiler-plugin&lt;span class=&quot;nt&quot;&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;  
      &lt;span class=&quot;nt&quot;&gt;&amp;lt;version&amp;gt;&lt;/span&gt;${maven_compiler_plugin_version}&lt;span class=&quot;nt&quot;&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;  
      &lt;span class=&quot;nt&quot;&gt;&amp;lt;configuration&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;source&amp;gt;&lt;/span&gt;1.7&lt;span class=&quot;nt&quot;&gt;&amp;lt;/source&amp;gt;&lt;/span&gt;  
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;target&amp;gt;&lt;/span&gt;1.7&lt;span class=&quot;nt&quot;&gt;&amp;lt;/target&amp;gt;&lt;/span&gt;  
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;compilerArguments&amp;gt;&lt;/span&gt;
          &lt;span class=&quot;nt&quot;&gt;&amp;lt;bootclasspath&amp;gt;&lt;/span&gt;${java.home}/lib/rt.jar:${java.home}/lib/jce.jar&lt;span class=&quot;nt&quot;&gt;&amp;lt;/bootclasspath&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;/compilerArguments&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;nt&quot;&gt;&amp;lt;/configuration&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/plugin&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;/plugins&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/build&amp;gt;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>为什么需要使用微服务架构</title>
   <link href="https://zaqweb.github.io/others/2017/08/20/micro-service/"/>
   <updated>2017-08-20T22:30:09+00:00</updated>
   <id>https://zaqweb.github.io/others/2017/08/20/micro-service</id>
   <content type="html">&lt;p&gt;有时候我们需要回答这样一个问题，为什么选择使用某一种技术，放弃另一项技术？是因为它更贴合我们的业务，还是因为他已经是一种流行，一种趋势，还是另有原因？&lt;/p&gt;

&lt;h1 id=&quot;什么是微服务&quot;&gt;什么是微服务&lt;/h1&gt;

&lt;h1 id=&quot;为什么出现微服务概念&quot;&gt;为什么出现微服务概念&lt;/h1&gt;

&lt;h1 id=&quot;以前为什么没提微服务&quot;&gt;以前为什么没提微服务&lt;/h1&gt;

&lt;h1 id=&quot;与soa有什么不一样&quot;&gt;与SOA有什么不一样&lt;/h1&gt;

&lt;h1 id=&quot;微服务的支撑技术&quot;&gt;微服务的支撑技术&lt;/h1&gt;

&lt;h1 id=&quot;一个真实的微服务项目概况&quot;&gt;一个真实的微服务项目概况&lt;/h1&gt;
</content>
 </entry>
 
 <entry>
   <title>Oracle数据库删除重复数据</title>
   <link href="https://zaqweb.github.io/database/2017/08/04/duplicate-data-clean/"/>
   <updated>2017-08-04T09:30:09+00:00</updated>
   <id>https://zaqweb.github.io/database/2017/08/04/duplicate-data-clean</id>
   <content type="html">&lt;p&gt;由于越来越多的应用不采用数据库层的数据完整性约束（主要指外键约束和唯一性约束），那么也就会有越来越多的脏数据存在。&lt;/p&gt;

&lt;h1 id=&quot;场景&quot;&gt;场景&lt;/h1&gt;

&lt;p&gt;假设：有如下A表（文章表）id为数据库主键，doc_id为业务上的主键用来确定唯一一篇文章&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;id&lt;/th&gt;
      &lt;th&gt;doc_id&lt;/th&gt;
      &lt;th&gt;doc_name&lt;/th&gt;
      &lt;th&gt;doc_link&lt;/th&gt;
      &lt;th&gt;doc_author&lt;/th&gt;
      &lt;th&gt;update_time&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;1&lt;/td&gt;
      &lt;td&gt;A000001&lt;/td&gt;
      &lt;td&gt;架构技术演进&lt;/td&gt;
      &lt;td&gt;test.com/a000001.html&lt;/td&gt;
      &lt;td&gt;张三&lt;/td&gt;
      &lt;td&gt;2016-03-04&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;2&lt;/td&gt;
      &lt;td&gt;A000001&lt;/td&gt;
      &lt;td&gt;架构技术演进&lt;/td&gt;
      &lt;td&gt;test.com/a000001.html&lt;/td&gt;
      &lt;td&gt;张三&lt;/td&gt;
      &lt;td&gt;2016-03-05&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;3&lt;/td&gt;
      &lt;td&gt;B000002&lt;/td&gt;
      &lt;td&gt;为什么使用微服务&lt;/td&gt;
      &lt;td&gt;test.com/b000002.html&lt;/td&gt;
      &lt;td&gt;李四&lt;/td&gt;
      &lt;td&gt;2017-01-01&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;4&lt;/td&gt;
      &lt;td&gt;B000003&lt;/td&gt;
      &lt;td&gt;分布式架构&lt;/td&gt;
      &lt;td&gt;test.com/b000003.html&lt;/td&gt;
      &lt;td&gt;王五&lt;/td&gt;
      &lt;td&gt;2017-03-01&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;假设：有如下B表（我阅读的文章表）id为数据库主键，read_doc_id业务上确定读了哪一篇文章，read_update_time 为最后一次阅读时间&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;id&lt;/th&gt;
      &lt;th&gt;user_id&lt;/th&gt;
      &lt;th&gt;read_doc_id&lt;/th&gt;
      &lt;th&gt;read_update_time&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;1&lt;/td&gt;
      &lt;td&gt;11101&lt;/td&gt;
      &lt;td&gt;A000001&lt;/td&gt;
      &lt;td&gt;2017-07-01&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;查询语句&lt;/p&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;doc_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;doc_link&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;doc_author&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;read_update_time&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;where&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;doc_id&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;read_doc_id&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user_id&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'11101'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;页面结果 &lt;br /&gt;
&lt;img src=&quot;/assets/img/database/625BEFEC-0161-41FE-AB20-77B6DE8B6688.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;问题来了出现了重复的数据，原因是A表数据重复&lt;/p&gt;

&lt;h2 id=&quot;如何定义重复&quot;&gt;如何定义重复&lt;/h2&gt;

&lt;p&gt;这依赖于我们面对的业务&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;业务主键重复 &lt;br /&gt;
  这种情况是指如A表中doc_id一旦重复，无论其他列是否重复都定义为重复&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;数值一致重复 &lt;br /&gt;
  想象一下A表没有id列并且其他列的值都一样&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;如何确定要删的行&quot;&gt;如何确定要删的行&lt;/h2&gt;
&lt;p&gt;通过&lt;strong&gt;count&lt;/strong&gt;和&lt;strong&gt;having&lt;/strong&gt;来看有哪些行是重复的&lt;/p&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;doc_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;group&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;by&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;doc_id&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;having&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;得到下面的结果&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;doc_id&lt;/th&gt;
      &lt;th&gt;count(1)&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;A000001&lt;/td&gt;
      &lt;td&gt;2&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;B000002&lt;/td&gt;
      &lt;td&gt;1&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;B000003&lt;/td&gt;
      &lt;td&gt;1&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;重点是怎么删&quot;&gt;重点是怎么删&lt;/h2&gt;

&lt;p&gt;1.业务主键重复 &lt;br /&gt;
  需要挑出一条来删，比如保留id主键最大的，或者保留update_time最近的，这完全取决你的实际情况。 &lt;br /&gt;
  删除重复数据的思想是利用业务主键确定要删除的数据集合，保留集合中最后一条数据即可&lt;/p&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;k&quot;&gt;create&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;replace&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;procedure&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;REMOVE_DUPLICATE_DATA&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;is&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;NUMBER&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;-- 循环标记变量&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;--根据业务主键循环所有重复数据&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;temp&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;doc_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;c&lt;/span&gt;
                   &lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;
                  &lt;span class=&quot;k&quot;&gt;group&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;by&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;doc_id&lt;/span&gt;
                 &lt;span class=&quot;k&quot;&gt;having&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;loop&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;c1&quot;&gt;--利用定位到的重复数据查到所有等待被删除的实际主键&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tempx&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;
                      &lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;
                     &lt;span class=&quot;k&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;doc_id&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;temp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;doc_id&lt;/span&gt;
                     &lt;span class=&quot;k&quot;&gt;order&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;by&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;procinst_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;loop&lt;/span&gt;
      &lt;span class=&quot;c1&quot;&gt;--需要保留一个不删除&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;temp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;then&lt;/span&gt;
          &lt;span class=&quot;c1&quot;&gt;--依次删除&lt;/span&gt;
          &lt;span class=&quot;k&quot;&gt;delete&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;id&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tempx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
          &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;commit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;2.数值一致重复 &lt;br /&gt;
  随便删哪一条，需要使用rownum &lt;br /&gt;
  思想和第一种情况一样，但是没有主键的数值类重复找不到删除的唯一性条件所以需要加个rownum即可。&lt;/p&gt;

&lt;h2 id=&quot;最佳实践&quot;&gt;最佳实践&lt;/h2&gt;

&lt;p&gt;第一条. 数据主表该加唯一性约束的要加上 &lt;br /&gt;
第二条. 没把握的insert()改成saveOrUpdate()&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>警惕你身边的架构师</title>
   <link href="https://zaqweb.github.io/others/2017/04/02/architect-warning/"/>
   <updated>2017-04-02T11:30:09+00:00</updated>
   <id>https://zaqweb.github.io/others/2017/04/02/architect-warning</id>
   <content type="html">&lt;p&gt;&lt;strong&gt;注意一点&lt;/strong&gt;：在IT技术的世界里永远没有完美的方案，每一种技术都有他的强项和弱项。架构师很多时候在各种技术之间做出选择，而选择的依据就是哪一项技术更符合我们的业务，哪一项技术能够带来真正的价值。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;如果你无法同意这个观点也就没必要继续往下阅读&lt;/strong&gt;&lt;/p&gt;

&lt;h1 id=&quot;什么是架构师&quot;&gt;什么是架构师&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;Architect&lt;/strong&gt; 一词的本意是指建筑行业的设计师，用行业内的话说他们做的是结构设计，空间设计而不仅仅是我们一般人认为的美观性方面设计。&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;第一个问题是，这一类Architect需不需要在工地码砖？ &lt;br /&gt;
 答案是不需要的&lt;/li&gt;
  &lt;li&gt;第二个问题是，什么是软件行业的架构师？ &lt;br /&gt;
 没有人给这一类架构师做明确的定义，大多还是强调软件设计能力，关键技术突破能力和培养团队的能力。 &lt;br /&gt;
 我想说架构师并不是一种炫酷的Title，也不是管理者。他始终应该是一个工程师，追求卓越。比我们想象的高级更高级，是技术的广度与深度以及职业素养等等多方面的体现。&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;架构师的组织架构&quot;&gt;架构师的组织架构&lt;/h1&gt;
&lt;p&gt;我只能说一说自己经历的一些公司组织情况，欢迎网友通过留言来聊一聊架构师的其他组织形态。
&lt;img src=&quot;/assets/img/others/arch1.jpg&quot; alt=&quot;顶配&quot; /&gt;
上图描述的是超大型集团企业的配置，这种类型的企业IT系统建设非常复杂。通常由于体制的复杂性和业务的复杂性共同导致的，同时架构师组织配置带来的价值也不容易衡量。个人认为这种配置在积极影响和消极影响两者当中消极影响通常会更突出。&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;CIO/CTO &lt;br /&gt;
  我没有直接接触过CIO/CTO，对他们的工作内容和职责也无法轻率的做出评价。但我认为这个职位仍然是一个技术条线管理者，管理的重点是&lt;strong&gt;技术&lt;/strong&gt;绝不是其他诸如人事、成本、利润、行政的东西。他们是一个公司技术发展的灯塔、布道师，他们的决策直接影响这团队的技术能力发展路线，以及最终是否能够实现技术变现。&lt;/li&gt;
  &lt;li&gt;架构委员会 &lt;br /&gt;
  就&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;积极影响&quot;&gt;积极影响&lt;/h2&gt;

&lt;h2 id=&quot;消极影响&quot;&gt;消极影响&lt;/h2&gt;

&lt;h1 id=&quot;架构师类型&quot;&gt;架构师类型&lt;/h1&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;编程型架构师&lt;/strong&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;文档型架构师&lt;/strong&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;总结&quot;&gt;总结&lt;/h1&gt;
</content>
 </entry>
 
 <entry>
   <title>分布式框架Dubbox一</title>
   <link href="https://zaqweb.github.io/distribute/2017/03/02/distribute-dubbo-1/"/>
   <updated>2017-03-02T23:30:09+00:00</updated>
   <id>https://zaqweb.github.io/distribute/2017/03/02/distribute-dubbo-1</id>
   <content type="html">&lt;p&gt;Init&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>深入理解Java多线程二（Java线程的默认值）</title>
   <link href="https://zaqweb.github.io/java/2017/03/02/java-thread-2/"/>
   <updated>2017-03-02T22:30:09+00:00</updated>
   <id>https://zaqweb.github.io/java/2017/03/02/java-thread-2</id>
   <content type="html">&lt;p&gt;我想通过&lt;a href=&quot;../java-thread-1&quot;&gt;上一篇文章&lt;/a&gt;不可能让你彻底全面掌握OS层面的多线程技术，但是我们需要对以下内容有一定认识：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;线程是进程中的一个控制点而已&lt;/li&gt;
  &lt;li&gt;线程是在CPU核的硬件线程上被运行的&lt;/li&gt;
  &lt;li&gt;每个线程有自己的内存堆栈&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;strong&gt;开始进入Java多线程技术的学习吧！！&lt;/strong&gt;&lt;/p&gt;

&lt;h1 id=&quot;java-thread类源码&quot;&gt;Java Thread类源码&lt;/h1&gt;

&lt;h2 id=&quot;阅读源码&quot;&gt;阅读源码&lt;/h2&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Thread&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;implements&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Runnable&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;cm&quot;&gt;/* Make sure registerNatives is the first thing &amp;lt;clinit&amp;gt; does. */&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;native&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;registerNatives&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;registerNatives&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;volatile&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;            &lt;span class=&quot;n&quot;&gt;priority&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;cm&quot;&gt;/* Whether or not the thread is a daemon thread. */&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;boolean&lt;/span&gt;     &lt;span class=&quot;n&quot;&gt;daemon&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;cm&quot;&gt;/* What will be run. */&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Runnable&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;


    &lt;span class=&quot;cm&quot;&gt;/**
     * The minimum priority that a thread can have.
     */&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;MIN_PRIORITY&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

   &lt;span class=&quot;cm&quot;&gt;/**
     * The default priority that is assigned to a thread.
     */&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;NORM_PRIORITY&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;cm&quot;&gt;/**
     * The maximum priority that a thread can have.
     */&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;MAX_PRIORITY&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;几个小问题&quot;&gt;几个小问题&lt;/h2&gt;

&lt;h2 id=&quot;深入学习&quot;&gt;深入学习&lt;/h2&gt;

&lt;h1 id=&quot;创建自己的thread&quot;&gt;创建自己的Thread&lt;/h1&gt;
</content>
 </entry>
 
 <entry>
   <title>深入理解Java多线程一(认识线程)</title>
   <link href="https://zaqweb.github.io/java/2017/03/01/java-thread-1/"/>
   <updated>2017-03-01T23:30:09+00:00</updated>
   <id>https://zaqweb.github.io/java/2017/03/01/java-thread-1</id>
   <content type="html">&lt;p&gt;个人不认为在深入理解OS层面的线程，进程，I/O， 内存等技术之前你能够真的掌握好面向某门特定语言的多线程技术。&lt;/p&gt;

&lt;p&gt;因为特定语言环境下的线程只是一个线程对象，比如在Java中继承Thread类或实现Runnable接口就可以有我们自己的线程对象。但是，大家可以检查一下线程的状态，你会发现并没有Running状态。这是因为线程最终是靠OS调度系统来交给CPU的硬件线程运行的，不是JVM更不是我们写的业务代码。所以，这里希望掌握一个概念[硬件线程]。&lt;/p&gt;

&lt;h1 id=&quot;伪多线程&quot;&gt;伪多线程&lt;/h1&gt;

&lt;div class=&quot;side-by-side&quot;&gt;
  &lt;div class=&quot;toleft&quot;&gt;
    在了解硬件线程这个概念之后，我们还需要明白他是属于CPU核(core)的，一个核就有对应一个硬件线程。所以我们在购买计算机的时候为什么要关注这个CPU是几核的？没错，核数越多说明CPU在同一时钟周期内能执行的线程就越多，简单点就是越快。
    &lt;p&gt;   伪多线程是在核（core）上发生的，既然线程是受OS调度系统控制的，那么OS就有机会在这个过程中做点“手脚”。OS利用时间片（Time slice）技术实现伪多线程，让线程误以为CPU是给他一个人用的，事实上是一个硬件线程被足够小的时间片分割开交替执行多个线程指令，从而实现了伪多线程。 &lt;/p&gt;  
  &lt;/div&gt;
  &lt;div class=&quot;toright&quot;&gt;
    &lt;img src=&quot;/assets/img/java/220px-Multithreaded_process.svg.png&quot; /&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h1 id=&quot;线程-vs-进程&quot;&gt;线程 VS 进程&lt;/h1&gt;

&lt;h2 id=&quot;关系&quot;&gt;关系&lt;/h2&gt;

&lt;h2 id=&quot;上下文切换&quot;&gt;上下文切换&lt;/h2&gt;

&lt;h2 id=&quot;内存堆栈&quot;&gt;内存堆栈&lt;/h2&gt;
</content>
 </entry>
 

</feed>
