<?xml version="1.0" encoding="utf-8" ?><rss version="2.0"><channel><title><![CDATA[hellboy0621的博客]]></title><description><![CDATA[]]></description><link>https://blog.youkuaiyun.com/hellboy0621</link><language>zh-cn</language><generator>https://blog.youkuaiyun.com/</generator><copyright><![CDATA[Copyright &copy; hellboy0621]]></copyright><item><title><![CDATA[【Druid源码阅读】11. 小结]]></title><link>https://blog.youkuaiyun.com/hellboy0621/article/details/124893227</link><guid>https://blog.youkuaiyun.com/hellboy0621/article/details/124893227</guid><author>hellboy0621</author><pubDate>Sat, 21 May 2022 01:43:59 +0800</pubDate><description><![CDATA[今天总结下，前几天分析的 Druid 源码。

由于每天可投入的有效时间有限，只把 Druid 最基本的流程大概看了下，但还是有些疑惑点的。

最重要的就是获取连接方法中的初始化方法 init()，连接对象保存在3个数组中，后续创建和销毁线层都是通过操作这3个数组来完成的。

再有就是可重入锁 lock，以及可重入锁上的2个条件empty 和notEmpty。

用来控制线程池中

如果连接数已经达到最大连接数时，线程阻塞，不再创建新的连接；
	如果连接池中没有可用连接时，阻塞，并且通知创建线程恢复，...]]></description><category></category></item><item><title><![CDATA[【Druid源码阅读】10. 过滤器工作原理]]></title><link>https://blog.youkuaiyun.com/hellboy0621/article/details/124873700</link><guid>https://blog.youkuaiyun.com/hellboy0621/article/details/124873700</guid><author>hellboy0621</author><pubDate>Thu, 19 May 2022 23:59:28 +0800</pubDate><description><![CDATA[昨天以 StatFilter 分析了责任链模式，今天还以 StatFilter 来举例。

StatFilter 就是用来统计数据，用来支撑 Druid 监控的。

其实大概看一下 StatFilter 的结构，可以看到有很多 public 方法，第一个参数是 FilterChain，并且代码实现都是使用调用过滤器的同名方法，



过滤方法有很多，除了昨天介绍的 dataSource_getConnection，再举个例子：


@Override
public void connection_commi]]></description><category></category></item><item><title><![CDATA[【Druid源码阅读】8. 对于连接的管理]]></title><link>https://blog.youkuaiyun.com/hellboy0621/article/details/124832653</link><guid>https://blog.youkuaiyun.com/hellboy0621/article/details/124832653</guid><author>hellboy0621</author><pubDate>Thu, 19 May 2022 22:20:43 +0800</pubDate><description><![CDATA[目录

testOnBorrow

testWhileIdle

testOnReturn

结论





第6篇中，分析了如何获取连接，那获取连接后，Druid 是如何管理这些连接的呢？

可以先给结论，是通过几个关键参数来控制的


testOnBorrow
testOnReturn
testWhileIdle

testOnBorrow

首先看 testOnBorrow，从字面理解，是从连接池中获取连接时，要测试连接是否可用。下面是代码中使用这个属性的几处地方：



1179 和 1193 行，]]></description><category></category></item><item><title><![CDATA[【Druid源码阅读】9. 过滤器]]></title><link>https://blog.youkuaiyun.com/hellboy0621/article/details/124854057</link><guid>https://blog.youkuaiyun.com/hellboy0621/article/details/124854057</guid><author>hellboy0621</author><pubDate>Thu, 19 May 2022 00:45:10 +0800</pubDate><description><![CDATA[在前面几天获取连接的代码中，经常会看到 filters 这个属性，今天一起来看下过滤器是如何工作的。

找一个单侧，把里面连接串和用户名密码改成自己的：


src/test/java/com/alibaba/druid/pool/Case0.java

设置 stat 过滤器

里面有一行代码，就是设置过滤器的：


dataSource.setFilters("stat");


public void setFilters(String filters) throws SQLException {
 ]]></description><category></category></item><item><title><![CDATA[【Druid源码阅读】7. 驱动加载]]></title><link>https://blog.youkuaiyun.com/hellboy0621/article/details/124811853</link><guid>https://blog.youkuaiyun.com/hellboy0621/article/details/124811853</guid><author>hellboy0621</author><pubDate>Tue, 17 May 2022 01:47:17 +0800</pubDate><description><![CDATA[在初始化 init() 方法中，可以看到2处关于 java.sql.Driver 驱动的方法：


// bug fixed for dead lock, for issue #2980
DruidDriver.getInstance();

resolveDriver();

先来看第1处，看注释是为了解决一个bug而增加的，主要解决了多线程死锁的问题，issue 链接：https://github.com/alibaba/druid/issues/2980

DruidDriver 类的 static ]]></description><category></category></item><item><title><![CDATA[【Druid源码阅读】5. 创建并运行销毁连接线程：createAndStartDestroyThread()]]></title><link>https://blog.youkuaiyun.com/hellboy0621/article/details/124776811</link><guid>https://blog.youkuaiyun.com/hellboy0621/article/details/124776811</guid><author>hellboy0621</author><pubDate>Sun, 15 May 2022 01:00:55 +0800</pubDate><description><![CDATA[上一篇分析了创建连接线程，今天来看下销毁连接线程。

1. 2种方式执行destroyTask 中封装的逻辑

分2种情况，取决于使用者有没有在初始化连接池前设置destroyScheduler：


protected void createAndStartDestroyThread() {
    // 这里创建真正销毁连接的任务
    destroyTask = new DestroyTask();

    // 如果在初始化连接池之前设置了销毁连接的定时执行器 destroySchedule..]]></description><category></category></item><item><title><![CDATA[【Druid源码阅读】6. 初始化后获取连接]]></title><link>https://blog.youkuaiyun.com/hellboy0621/article/details/124761815</link><guid>https://blog.youkuaiyun.com/hellboy0621/article/details/124761815</guid><author>hellboy0621</author><pubDate>Sat, 14 May 2022 00:09:59 +0800</pubDate><description><![CDATA[前几天把 init 初始化方法大概分析了下，今天继续，把获取连接的部分分析完。


public DruidPooledConnection getConnection(long maxWaitMillis) throws SQLException {
    init();

    if (filters.size() &gt; 0) {
        FilterChainImpl filterChain = new FilterChainImpl(this);
        return fil]]></description><category></category></item><item><title><![CDATA[【Druid源码阅读】4. 创建并运行创建连接线程：createAndStartCreatorThread()]]></title><link>https://blog.youkuaiyun.com/hellboy0621/article/details/124742544</link><guid>https://blog.youkuaiyun.com/hellboy0621/article/details/124742544</guid><author>hellboy0621</author><pubDate>Fri, 13 May 2022 00:36:24 +0800</pubDate><description><![CDATA[现在我们来一起看下 创建并运行创建连接线程：createAndStartCreatorThread()；


protected void createAndStartCreatorThread() {
    // 只有在创建执行器没有设置时，才会创建创建连接线程
    if (createScheduler == null) {
        String threadName = "Druid-ConnectionPool-Create-" + System.identityHashCode(..]]></description><category></category></item><item><title><![CDATA[【Druid源码阅读】3. 初始化连接之同步创建连接]]></title><link>https://blog.youkuaiyun.com/hellboy0621/article/details/124741165</link><guid>https://blog.youkuaiyun.com/hellboy0621/article/details/124741165</guid><author>hellboy0621</author><pubDate>Thu, 12 May 2022 23:22:10 +0800</pubDate><description><![CDATA[书接上文，异步创建连接需要设置参数，如果不设置参数，使用默认配置，会进到同步创建连接的分支。


if (createScheduler != null &amp;&amp; asyncInit) {
    // 异步
    for (int i = 0; i &lt; initialSize; ++i) {
        submitCreateTask(true);
    }
} else if (!asyncInit) {
    // 同步
    // init connections..]]></description><category></category></item><item><title><![CDATA[【Druid源码阅读】2. 初始化连接之异步创建连接]]></title><link>https://blog.youkuaiyun.com/hellboy0621/article/details/124720985</link><guid>https://blog.youkuaiyun.com/hellboy0621/article/details/124720985</guid><author>hellboy0621</author><pubDate>Thu, 12 May 2022 01:04:07 +0800</pubDate><description><![CDATA[今天就连着昨天的思路，来看下连接到底是如何初始化的。

第14步： 初始化连接，数量为设置的初始连接数，并存放到数组中；（真正创建连接在这一步中）


if (createScheduler != null &amp;&amp; asyncInit) {
    // 异步
    for (int i = 0; i &lt; initialSize; ++i) {
        submitCreateTask(true);
    }
} else if (!asyncInit) {
    //..]]></description><category></category></item><item><title><![CDATA[【Druid源码阅读】1. 初识Druid]]></title><link>https://blog.youkuaiyun.com/hellboy0621/article/details/124699895</link><guid>https://blog.youkuaiyun.com/hellboy0621/article/details/124699895</guid><author>hellboy0621</author><pubDate>Wed, 11 May 2022 01:38:55 +0800</pubDate><description><![CDATA[Druid源码阅读]]></description><category></category></item><item><title><![CDATA[Java8 日期和时间API]]></title><link>https://blog.youkuaiyun.com/hellboy0621/article/details/124578598</link><guid>https://blog.youkuaiyun.com/hellboy0621/article/details/124578598</guid><author>hellboy0621</author><pubDate>Wed, 04 May 2022 21:59:29 +0800</pubDate><description><![CDATA[Java8 日期和时间APIA new tool that blends your everyday work apps into one. It's the all-in-one workspace for you and your teamhttps://foggy-airbus-610.notion.site/Java8-API-71e484547208463395b5b269d51b81cc
]]></description><category></category></item><item><title><![CDATA[AOP之 AspectJ]]></title><link>https://blog.youkuaiyun.com/hellboy0621/article/details/124210665</link><guid>https://blog.youkuaiyun.com/hellboy0621/article/details/124210665</guid><author>hellboy0621</author><pubDate>Sat, 16 Apr 2022 21:46:06 +0800</pubDate><description><![CDATA[AOP之jac编译器]]></description><category></category></item><item><title><![CDATA[TCP握手的理解]]></title><link>https://blog.youkuaiyun.com/hellboy0621/article/details/123589053</link><guid>https://blog.youkuaiyun.com/hellboy0621/article/details/123589053</guid><author>hellboy0621</author><pubDate>Sat, 19 Mar 2022 09:26:13 +0800</pubDate><description><![CDATA[TCP握手]]></description><category></category></item><item><title><![CDATA[使用 HSDB 探究多态原理]]></title><link>https://blog.youkuaiyun.com/hellboy0621/article/details/117625631</link><guid>https://blog.youkuaiyun.com/hellboy0621/article/details/117625631</guid><author>hellboy0621</author><pubDate>Sun, 06 Jun 2021 14:13:28 +0800</pubDate><description><![CDATA[HSDB（Hotspot Debugger），是一个内置的 JVM 工具，可以用来深入分析 JVM运行时内部状态。位于 JDK 安装目录下的 lib/sa-jdi.jar 中，启动命令：(一定要使用 sudo，否则后面输入 pid 后连接不上)
sudo java -cp sa-jdi.jar sun.jvm.hotspot.HSDB

打开界面后，依次点击 File -&gt; Attach to HotSpot Process…
输入程序启动后的进程ID。
测试程序代码如下：
public abstra]]></description><category></category></item><item><title><![CDATA[Java 不同 String 相同 hashCode]]></title><link>https://blog.youkuaiyun.com/hellboy0621/article/details/117606675</link><guid>https://blog.youkuaiyun.com/hellboy0621/article/details/117606675</guid><author>hellboy0621</author><pubDate>Sat, 05 Jun 2021 22:15:33 +0800</pubDate><description><![CDATA[快速找到 hashCode 相同的两个字符串：
查看 String 的 hashCode() 方法，源码如下：
public int hashCode() {
        int h = hash;
        if (h == 0 &amp;&amp; value.length &gt; 0) {
            char val[] = value;

            for (int i = 0; i &lt; value.length; i++) {
            ]]></description><category></category></item><item><title><![CDATA[软件公司的两种管理方式 - 转自 CoolShell]]></title><link>https://blog.youkuaiyun.com/hellboy0621/article/details/114276149</link><guid>https://blog.youkuaiyun.com/hellboy0621/article/details/114276149</guid><author>hellboy0621</author><pubDate>Tue, 02 Mar 2021 08:59:37 +0800</pubDate><description><![CDATA[本文转自酷壳：https://coolshell.cn/articles/4951.html

软件公司的两种管理方式

2011年07月06日陈皓评论110 条评论74,539 人阅读

这篇文章是我的一个外国的同事Gareth推荐给我的，我和他一起工作过一段时间。他之所以觉得非常不错，是因为这篇文章让他身有体会，他觉得我也一定会有体会，并让我考虑一下翻译到我的blog上来。我看完后觉得很有代表性，而且觉得说得太对了，所以翻译过来，希望大家都读一读，最好转给你的公司老板。

这篇文章来源于 ...]]></description><category></category></item><item><title><![CDATA[【Soul源码阅读】21.插件之大体流程]]></title><link>https://blog.youkuaiyun.com/hellboy0621/article/details/113678278</link><guid>https://blog.youkuaiyun.com/hellboy0621/article/details/113678278</guid><author>hellboy0621</author><pubDate>Sat, 06 Feb 2021 03:05:00 +0800</pubDate><description><![CDATA[插件的接口 SoulPlugin 有很多实现，我们先关注以下这些，从名字上能看出来，这些就是 soul-admin 管理页面上插件列表里的代码实现。



下面，以DividePlugin 为例，详细看看这优雅的设计。












...]]></description><category></category></item><item><title><![CDATA[【Soul源码阅读】20.插件灵魂之选择器和规则]]></title><link>https://blog.youkuaiyun.com/hellboy0621/article/details/113665604</link><guid>https://blog.youkuaiyun.com/hellboy0621/article/details/113665604</guid><author>hellboy0621</author><pubDate>Fri, 05 Feb 2021 01:09:49 +0800</pubDate><description><![CDATA[目录

1.灵魂

2.数据结构

3.选择器

4.规则

1.灵魂

这几天一直在看插件相关的功能，一直把核心概念忽略了，那就是所有的插件都有的：selector 和 rule。

在看看官网文档https://dromara.org/zh/projects/soul/selector-and-rule/，里面第一句就是：


选择器和规则是 soul 网关中最灵魂的东西。掌握好它，你可以对任何流量进行管理。


都这么多天过去了，眼睛里净盯着具体对接的协议和同步功能，还有插件的具体使用，就没有关心过.]]></description><category></category></item><item><title><![CDATA[【Soul源码阅读】19.插件之 divide]]></title><link>https://blog.youkuaiyun.com/hellboy0621/article/details/113620998</link><guid>https://blog.youkuaiyun.com/hellboy0621/article/details/113620998</guid><author>hellboy0621</author><pubDate>Thu, 04 Feb 2021 00:27:58 +0800</pubDate><description><![CDATA[目录

1.启动

2.开启 divide 插件

3.添加选择器和规则

4.验证

4.1 负载均衡

4.2 IP 端口探活

官网文档https://dromara.org/zh/projects/soul/divide-plugin/

divide插件是网关处理 http协议请求的核心处理插件。

1.启动

在网关的 pom.xml 文件中添加 starter 依赖，当然，divide 插件是默认支持的。（application-local.yml）


        &lt;!--if .]]></description><category></category></item></channel></rss>