<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Java on haifeiWu</title><link>https://haifeiWu.github.io/tags/java/</link><description>Recent content in Java on haifeiWu</description><generator>Hugo -- gohugo.io</generator><language>zh-cn</language><managingEditor>whfstudio@163.com (haifeiWu)</managingEditor><webMaster>whfstudio@163.com (haifeiWu)</webMaster><copyright>© 2016～2026 haifeiWu</copyright><lastBuildDate>Wed, 12 May 2021 12:19:58 +0800</lastBuildDate><atom:link href="https://haifeiWu.github.io/tags/java/index.xml" rel="self" type="application/rss+xml"/><item><title>Kafka 的 Replica 机制</title><link>https://haifeiWu.github.io/posts/kafkadereplicajizhi/</link><pubDate>Wed, 12 May 2021 12:19:58 +0800</pubDate><author>whfstudio@163.com (haifeiWu)</author><guid>https://haifeiWu.github.io/posts/kafkadereplicajizhi/</guid><description>Kafka 是一个分布式的发布-订阅消息系统。它最初是在 LinkedIn 开发的，2011年7月成为一个 Apache 项目。</description></item><item><title>ThreadPoolExecutor 的简单梳理</title><link>https://haifeiWu.github.io/posts/threadpoolexecutor--de-jian-dan-shu-li/</link><pubDate>Sun, 19 Jan 2020 00:00:00 +0800</pubDate><author>whfstudio@163.com (haifeiWu)</author><guid>https://haifeiWu.github.io/posts/threadpoolexecutor--de-jian-dan-shu-li/</guid><description>还是楼主惯用的论述三连问，先问是什么，再问为什么，最后祭除终极大杀器 just do it ……what ? 那么什么是线程池呢？总的来说，线程池是一种线程使用模式。线程的频繁创建于调度会带来调度开销，进而影响缓存局部性和整体性能。而线程</description></item><item><title>MapReduce 的简单实现</title><link>https://haifeiWu.github.io/posts/mapreduce-shixiandejiandanshixian/</link><pubDate>Sat, 18 Jan 2020 23:37:50 +0800</pubDate><author>whfstudio@163.com (haifeiWu)</author><guid>https://haifeiWu.github.io/posts/mapreduce-shixiandejiandanshixian/</guid><description>相信用过 Hadoop 的同学在等待结果输出的时候会出现类似于这样的 INFO : 2020-01-17 11:44:14,132 Stage-11 map = 0%, reduce = 0% 的日志，它展示了 MapReduce 的执行过程，下面我们也将就 MapReduce…</description></item><item><title>使用 Map 实现策略模式</title><link>https://haifeiWu.github.io/posts/shi-yong--map--shi-xian-ce-lve-mo-shi/</link><pubDate>Thu, 16 Jan 2020 00:00:00 +0800</pubDate><author>whfstudio@163.com (haifeiWu)</author><guid>https://haifeiWu.github.io/posts/shi-yong--map--shi-xian-ce-lve-mo-shi/</guid><description>上篇文章在谈到优化代码的时候，有一部分涉及到了使用策略模式优化我们的代码，本篇文章将围绕策略模式谈谈自己的思考~ What? 总的来说，设计模式是对软件设计中普遍存在并且反复出现的各种问题，所提出的通用解决方案，是一系列编码经验的集合。那</description></item><item><title>我理解的 TCP 连接</title><link>https://haifeiWu.github.io/posts/wolijiede-tcp-lianjie/</link><pubDate>Wed, 27 Nov 2019 12:01:51 +0800</pubDate><author>whfstudio@163.com (haifeiWu)</author><guid>https://haifeiWu.github.io/posts/wolijiede-tcp-lianjie/</guid><description>TCP 是面向连接的协议。运输连接是用来传输 TCP 报文的。TCP 运输连接的建立和释放是每一次面向连接通信中必不可少的过程。因此，运输连接有三个阶段，即：连接建立，数据传输和连接释放。在 TCP 连接建立过程中要解决一下三个问题。（1）要使一方明确知道对方的存在。（2）要…</description></item><item><title>Kafka Consumer 的 Rebalance 机制</title><link>https://haifeiWu.github.io/posts/kafka-consumer-de-rebalance-jizhi/</link><pubDate>Tue, 19 Nov 2019 16:22:34 +0800</pubDate><author>whfstudio@163.com (haifeiWu)</author><guid>https://haifeiWu.github.io/posts/kafka-consumer-de-rebalance-jizhi/</guid><description>如上图所示，Consumer 使用 Consumer Group 名称标记自己，并且发布到主题的每条记录都会传递到每个订阅消费者组中的一个 Consumer 实例。Consumer 实例可以在单独的进程中或在单独的机器上。如果所有 Consumer 实例都属于同一个 Con…</description></item><item><title>双重检查锁定与单例</title><link>https://haifeiWu.github.io/posts/shuangchongjianchasuodingyudanli/</link><pubDate>Wed, 13 Nov 2019 14:47:53 +0800</pubDate><author>whfstudio@163.com (haifeiWu)</author><guid>https://haifeiWu.github.io/posts/shuangchongjianchasuodingyudanli/</guid><description>对于单例模式，相信大多数人都可以写出好几种实现方法，懒汉，饿汉等等，然而小小单例真要写好，写的完全正确也并非易事。下面是我们经常使用的一种单例的实现，也就是双重检查所的实现方案。让我们来看一下这个代码是如何工作的：首先当一个线程发出请求后，会先检查 instance 是否为 nu…</description></item><item><title>我理解的零拷贝</title><link>https://haifeiWu.github.io/posts/wolijiedelingkaobei/</link><pubDate>Sat, 09 Nov 2019 11:19:31 +0800</pubDate><author>whfstudio@163.com (haifeiWu)</author><guid>https://haifeiWu.github.io/posts/wolijiedelingkaobei/</guid><description>最近做的业务涉及到的 I/O 操作比较多，对于 Linux 上的 I/O 操作的优化 Zero Copy 早有耳闻，今天打算由上而下（从应用层到底层，当然并不会涉及到内核的细节）的研究一下这个问题。为了更好的描述 zero copy，本文将以网络服务器的简单过程所涉及的内容展开…</description></item><item><title>二分查找算法细节详解</title><link>https://haifeiWu.github.io/posts/er-fen-cha-zhao-suan-fa-xi-jie-xiang-jie/</link><pubDate>Sun, 01 Sep 2019 00:00:00 +0800</pubDate><author>whfstudio@163.com (haifeiWu)</author><guid>https://haifeiWu.github.io/posts/er-fen-cha-zhao-suan-fa-xi-jie-xiang-jie/</guid><description>思路 我相信对很多读者朋友来说，编写二分查找的算法代码属于玄学编程，虽然看起来很简单，就是会出错，要么会漏个等号，要么少加个 1。不要气馁，因为二分查找其实并不简单。看看 Knuth 大佬（发明 KMP 算法的那位）怎么说的：Altho</description></item><item><title>lang3 的 split 方法误用</title><link>https://haifeiWu.github.io/posts/lang3-de-split-fangfawuyong/</link><pubDate>Wed, 07 Aug 2019 13:53:17 +0800</pubDate><author>whfstudio@163.com (haifeiWu)</author><guid>https://haifeiWu.github.io/posts/lang3-de-split-fangfawuyong/</guid><description>apache 的 lang3 是我们开发常用到的三方工具包，然而对这个包不甚了解的话，会产生莫名其秒的 bug，在这里做下记录。通过分析字符串的拆分结果，发现该方法并不是将分隔符去截取字符串，而是将分隔符的每一个字符都当成分隔符去截取字符串，当我们的分隔符是一个字符的时候一…</description></item><item><title>实现自己的 RPC 框架（二）</title><link>https://haifeiWu.github.io/posts/shixianzijide-rpc-kuangjia-er/</link><pubDate>Tue, 06 Aug 2019 14:13:41 +0800</pubDate><author>whfstudio@163.com (haifeiWu)</author><guid>https://haifeiWu.github.io/posts/shixianzijide-rpc-kuangjia-er/</guid><description>前段时间自己搞了个 RPC 的轮子，不过相对来说比较简单，最近在原来的基础上加以改造，使用 ZooKeeper 实现了 provider 自动寻址以及消费者的简单负载均衡，对之前的感兴趣的请转 造个轮子&amp;mdash;RPC 动手实现。在原来使用 TCP 直连的基础上实现基于 Zooke…</description></item><item><title>[译] 为什么 String 在 Java 中是不可变的</title><link>https://haifeiWu.github.io/posts/yi---wei-shen-me-string-zai-java-zhong-shi-bu-ke-bian-de/</link><pubDate>Mon, 08 Jul 2019 00:00:00 +0800</pubDate><author>whfstudio@163.com (haifeiWu)</author><guid>https://haifeiWu.github.io/posts/yi---wei-shen-me-string-zai-java-zhong-shi-bu-ke-bian-de/</guid><description>String 在 Java 中是不可变的。不可变类只是一个无法修改其实例的类。创建实例时，将初始化实例中的所有信息，并且无法修改信息。不可变类有许多优点。本文总结了为什么 String 设计为不可变的。这篇文章从内存，同步和数据结</description></item><item><title>ArrayBlockingQueue 阻塞队列</title><link>https://haifeiWu.github.io/posts/arrayblockingqueue--zu-se-dui-lie/</link><pubDate>Sun, 27 Jan 2019 00:00:00 +0800</pubDate><author>whfstudio@163.com (haifeiWu)</author><guid>https://haifeiWu.github.io/posts/arrayblockingqueue--zu-se-dui-lie/</guid><description>一直都在写业务代码，对于 jdk 底层的代码难免有些疏忽，所以决定把一些比较重要的源码过一遍……是什么？ArrayBlockingQueue 是一个用数组实现的有界阻塞队列。此队列按照先进先出（FIFO）的原则对元素进行排序。默认情况</description></item><item><title>散列表</title><link>https://haifeiWu.github.io/posts/sanliebiao/</link><pubDate>Fri, 23 Nov 2018 14:54:25 +0800</pubDate><author>whfstudio@163.com (haifeiWu)</author><guid>https://haifeiWu.github.io/posts/sanliebiao/</guid><description>是根据键 (Key) 而直接访问在内存存储位置的数据结构。也就是说，它通过计算一个关于键值的函数，将所需查询的数据映射到表中一个位置来访问记录，这加快了查找速度。</description></item><item><title>聊聊 volatile 关键字</title><link>https://haifeiWu.github.io/posts/liaoliao-volatile-guanjianzi/</link><pubDate>Mon, 22 Oct 2018 10:07:21 +0800</pubDate><author>whfstudio@163.com (haifeiWu)</author><guid>https://haifeiWu.github.io/posts/liaoliao-volatile-guanjianzi/</guid><description>我们知道 volatile 关键字的作用是保证变量在多线程之间的可见性，它是 java.util.concurrent 包的核心，没有 volatile 就没有这么多的并发类给我们使用。本文将简单介绍一下 volatile 这个东东。CAS(compare-and-swap)…</description></item><item><title>Redis 协议规范（译文）</title><link>https://haifeiWu.github.io/posts/redisxieyiguifan-yiwen/</link><pubDate>Wed, 08 Aug 2018 00:57:50 +0800</pubDate><author>whfstudio@163.com (haifeiWu)</author><guid>https://haifeiWu.github.io/posts/redisxieyiguifan-yiwen/</guid><description>Redis 客户端使用名为 RESP（Redis 序列化协议）的协议与 Redis 服务器进行通信。虽然该协议是专为 Redis 设计的，但它可以用于其他 CS 软件项目的通讯协议。RESP 可以序列化不同的数据类型，如整型，字符串，数组。还有一种特定的错误类型。请求将要执行的命令作为字符…</description></item><item><title>聊聊 JDK 非阻塞队列源码（CAS 实现）</title><link>https://haifeiWu.github.io/posts/liaoliao-jdk-feizuseduilieyuanma-casshixian/</link><pubDate>Thu, 02 Aug 2018 14:23:33 +0800</pubDate><author>whfstudio@163.com (haifeiWu)</author><guid>https://haifeiWu.github.io/posts/liaoliao-jdk-feizuseduilieyuanma-casshixian/</guid><description>正如上篇文章聊聊 JDK 阻塞队列源码（ReentrantLock 实现）所说，队列在我们现实生活中队列随处可见，最经典的就是去银行办理业务，超市买东西排队等。今天楼主要讲的就是 JDK 中安全队列的另一种实现使用 CAS 算法实现的安全队列。</description></item><item><title>聊聊 JDK 阻塞队列源码（ReentrantLock 版）</title><link>https://haifeiWu.github.io/posts/liaoliao-jdk-zuseduilieyuanma-reentrantlockban/</link><pubDate>Wed, 01 Aug 2018 10:14:44 +0800</pubDate><author>whfstudio@163.com (haifeiWu)</author><guid>https://haifeiWu.github.io/posts/liaoliao-jdk-zuseduilieyuanma-reentrantlockban/</guid><description>项目中用到了一个叫做 Disruptor 的队列，今天楼主并不是要介绍 Disruptor 而是想巩固一下基础扒一下 JDK 中的阻塞队列，听到队列相信大家对其并不陌生，在我们现实生活中队列随处可见，最经典的就是去银行办理业务等。</description></item><item><title>JDK 定时任务 Timer 与 ScheduledExecutorService 排坑记录</title><link>https://haifeiWu.github.io/posts/jdk-dingshirenwu-timer-yu-scheduledexecutorservice-paikengji/</link><pubDate>Wed, 18 Jul 2018 19:12:40 +0800</pubDate><author>whfstudio@163.com (haifeiWu)</author><guid>https://haifeiWu.github.io/posts/jdk-dingshirenwu-timer-yu-scheduledexecutorservice-paikengji/</guid><description>正在认真敲代码的楼主，突然收到数据维护系统发过来的报警邮件说楼主凌晨跑的定时任务没有成功，于是便开始了楼主今天的找坑填坑的过程。</description></item><item><title>TCP 粘包问题浅析及其解决方案</title><link>https://haifeiWu.github.io/posts/tcp-zhanbaowentiqianxijiqijiejuefangan/</link><pubDate>Mon, 16 Jul 2018 18:58:07 +0800</pubDate><author>whfstudio@163.com (haifeiWu)</author><guid>https://haifeiWu.github.io/posts/tcp-zhanbaowentiqianxijiqijiejuefangan/</guid><description>最近一直在做中间件相关的东西，所以接触到的各种协议比较多，总的来说有 TCP，UDP，HTTP 等各种网络传输协议，因此楼主想先从协议最基本的 TCP 粘包问题搞起，把计算机网络这部分基础夯实一下。</description></item><item><title>I-team 博客全文检索 Elasticsearch 实战</title><link>https://haifeiWu.github.io/posts/i-team-bokequanwenjiansuo-elasticsearch-shizhan/</link><pubDate>Thu, 12 Jul 2018 16:26:02 +0800</pubDate><author>whfstudio@163.com (haifeiWu)</author><guid>https://haifeiWu.github.io/posts/i-team-bokequanwenjiansuo-elasticsearch-shizhan/</guid><description>一直觉得博客缺点东西，最近还是发现了，当博客慢慢多起来的时候想要找一篇之前写的博客很是麻烦，于是作为后端开发的楼主觉得自己动手丰衣足食，也就有了这次博客全文检索功能 Elasticsearch 实战，这里还要感谢一下‘辉哥’赞助的一台服务器。</description></item><item><title>阿里云离线同步工具 DataX 源码略读</title><link>https://haifeiWu.github.io/posts/aliyunlixiantongbugongjudataxyuanmalvedu/</link><pubDate>Fri, 06 Jul 2018 10:47:57 +0800</pubDate><author>whfstudio@163.com (haifeiWu)</author><guid>https://haifeiWu.github.io/posts/aliyunlixiantongbugongjudataxyuanmalvedu/</guid><description>最近在做一些数据迁移相关工作，并最终采用了 DataX，楼主也本着知其然，也要知其所以然的精神粗略的看一看 Datax 的源码。</description></item><item><title>阿里离线数据同步工具 DataX 踩坑记录</title><link>https://haifeiWu.github.io/posts/alilixianshujutongbugongju-datax-caikengjilu/</link><pubDate>Wed, 04 Jul 2018 22:33:38 +0800</pubDate><author>whfstudio@163.com (haifeiWu)</author><guid>https://haifeiWu.github.io/posts/alilixianshujutongbugongju-datax-caikengjilu/</guid><description>最近在做一些数据迁移相关工作，调研了一些工具，发现 DataX 是个不错的东西，所以安利给大家。那么 DataX 是什么呢？DataX 是阿里巴巴集团内被广泛使用的离线数据同步工具，实现包括 MySQL、SQL Server、Oracle、PostgreSQL 等各种异构数据源的同步</description></item><item><title>Netty 实战之第一个应用</title><link>https://haifeiWu.github.io/posts/nettyshizhanzhidiyigeyingyong/</link><pubDate>Thu, 21 Jun 2018 20:09:37 +0800</pubDate><author>whfstudio@163.com (haifeiWu)</author><guid>https://haifeiWu.github.io/posts/nettyshizhanzhidiyigeyingyong/</guid><description>作为一个正在 Java 路上摸爬滚打的小菜鸡，之前在项目中也用过 Netty，也因为 Netty 报名阿里的中间件大赛，但终究功力太浅，最终不了了之，最近工作中又遇到了 Netty 的小姐妹 Mina。此时楼主觉得 Netty 还是需要潜心深入学习一下。</description></item><item><title>死磕 Java 之聊聊 HashMap 源码(基于 JDK1.8)</title><link>https://haifeiWu.github.io/posts/sikejavazhiliaoliaohashmapyuanma-jiyujdk1-8/</link><pubDate>Mon, 04 Jun 2018 23:07:24 +0800</pubDate><author>whfstudio@163.com (haifeiWu)</author><guid>https://haifeiWu.github.io/posts/sikejavazhiliaoliaohashmapyuanma-jiyujdk1-8/</guid><description>HashMap 是 Java 程序员使用频率最高的数据结构之一。另外，JDK1.8 对 HashMap 底层的实现进行了优化，如引入红黑树的数据结构以及扩容的优化等等来提高性能。本文结合 JDK1.8 的源码，探讨 HashMap 的结构实现和功能原理。</description></item><item><title>聊聊 HashSet 源码</title><link>https://haifeiWu.github.io/posts/liaoliaohashsetyuanma/</link><pubDate>Tue, 29 May 2018 23:18:49 +0800</pubDate><author>whfstudio@163.com (haifeiWu)</author><guid>https://haifeiWu.github.io/posts/liaoliaohashsetyuanma/</guid><description>今天聊一下 HashSet 源码，HashSet 内部基本使用 HashMap 来实现，本博客将通过一下几个方向讲解。</description></item><item><title>classpath* 和 classpath 使用遇到的问题</title><link>https://haifeiWu.github.io/posts/classpath-he-classpathshiyongyudaodewenti/</link><pubDate>Thu, 24 May 2018 22:00:41 +0800</pubDate><author>whfstudio@163.com (haifeiWu)</author><guid>https://haifeiWu.github.io/posts/classpath-he-classpathshiyongyudaodewenti/</guid><description>在 Spring 配置 mybatis 的时候需要加载 mybatis 的多个相关配置文件，其中 mybatis 的 mapper 对应的 XML 通常放在其他的 jar 包中，mybatis-conf 文件通常在当前工程中，so，也就引出了今天遇到的问题，那么 classpath* 和 classpath 到底</description></item><item><title>死磕 Java 之聊聊 ThreadLocal 源码(基于 JDK1.8)</title><link>https://haifeiWu.github.io/posts/sikejavazhiliaoliaothreadlocalyuanma-jiyujdk1-8/</link><pubDate>Wed, 09 May 2018 22:15:42 +0800</pubDate><author>whfstudio@163.com (haifeiWu)</author><guid>https://haifeiWu.github.io/posts/sikejavazhiliaoliaothreadlocalyuanma-jiyujdk1-8/</guid><description>记得在一次面试中被问到 ThreadLocal，答得马马虎虎，所以打算研究一下 ThreadLocal 的源码 面试官：用过 ThreadLocal 吗？楼主答：用过，当时使用 ThreadLocal 的时候，使用 Spring 实现横切整个 Controller 层，使用 ThreadL…</description></item><item><title>死磕 Java 之聊聊 LinkedList 源码(基于 JDK1.8)</title><link>https://haifeiWu.github.io/posts/sikejavazhiliaoliaolinkedlistyuanma-jiyujdk1-8/</link><pubDate>Sun, 06 May 2018 23:09:50 +0800</pubDate><author>whfstudio@163.com (haifeiWu)</author><guid>https://haifeiWu.github.io/posts/sikejavazhiliaoliaolinkedlistyuanma-jiyujdk1-8/</guid><description>工作快一年了，近期打算研究一下 JDK 的源码，也就因此有了死磕 Java 系列</description></item><item><title>Java 命令之 javap 初探</title><link>https://haifeiWu.github.io/posts/javaminglingzhijavapchutan/</link><pubDate>Mon, 26 Feb 2018 13:27:15 +0800</pubDate><author>whfstudio@163.com (haifeiWu)</author><guid>https://haifeiWu.github.io/posts/javaminglingzhijavapchutan/</guid><description>下面列举 javap 命令的常用 options 及其功能描述，更多功能的使用请自行 Google，楼主不做赘述。javap 命令分解一个 class 文件，它根据 options 来决定到底输出什么。如果没有使用 options,那么 javap 将会输出该 class 文件中的包，类里的 protect…</description></item><item><title>Java 实现终止线程池中正在运行的定时任务</title><link>https://haifeiWu.github.io/posts/javashixianzhongzhixianchengchizhongzhengzaiyunxingdedingshi/</link><pubDate>Wed, 17 Jan 2018 20:35:01 +0800</pubDate><author>whfstudio@163.com (haifeiWu)</author><guid>https://haifeiWu.github.io/posts/javashixianzhongzhixianchengchizhongzhengzaiyunxingdedingshi/</guid><description>最近项目中遇到了一个新的需求，就是实现一个可以动态添加定时任务的功能。说到这里，有人可能会说简单啊，使用 quartz 就好了，简单粗暴。然而 quartz 框架太重了，小项目根本不好操作啊。当然，也有人会说，jdk 提供了 timer 的接口啊，完全够用啊。但是我们项目的需求完全是多线程的…</description></item><item><title>child-rpc</title><link>https://haifeiWu.github.io/projects/child-rpc/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><author>whfstudio@163.com (haifeiWu)</author><guid>https://haifeiWu.github.io/projects/child-rpc/</guid><description>&lt;p&gt;Netty 实现的轻量级 RPC 框架，从零手写。&lt;/p&gt;
&lt;p&gt;A lightweight RPC framework implemented from scratch with Netty.&lt;/p&gt;</description></item><item><title>disruptor-learn</title><link>https://haifeiWu.github.io/projects/disruptor-learn/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><author>whfstudio@163.com (haifeiWu)</author><guid>https://haifeiWu.github.io/projects/disruptor-learn/</guid><description>&lt;p&gt;Disruptor 无锁队列学习笔记与实践。&lt;/p&gt;
&lt;p&gt;Disruptor lock-free queue learning notes and practice.&lt;/p&gt;</description></item><item><title>lightconf</title><link>https://haifeiWu.github.io/projects/lightconf/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><author>whfstudio@163.com (haifeiWu)</author><guid>https://haifeiWu.github.io/projects/lightconf/</guid><description>&lt;p&gt;基于 Netty 实现的轻量级分布式应用配置中心。&lt;/p&gt;
&lt;p&gt;A lightweight distributed application configuration center built on Netty.&lt;/p&gt;</description></item></channel></rss>