Design Patterns Cheatsheet
As everyone knows, design patterns are an extremely important discipline for programmers. However, because design patterns cover such a broad scope and involve many abstract concepts, they can be quite difficult to master. The best way to learn design patterns is to combine them with practical experience. Every time you work on a requirement — especially complex ones, or when you detect signs of smelly code — you can flip through the design patterns to see which ones might apply. Therefore, I...
Reflections on a Programmer's Career — My Understanding of the Programming Profession
Over the years of working, I’ve been constantly thinking about what a programmer actually does. As I’ve gained more experience, my understanding has continuously evolved. Writing this article now serves two purposes: sharing my thoughts, and leaving a record to revisit in a couple of years to see how my understanding has further changed. I want to discuss this from two perspectives. First, from the work itself — in my view, a programmer’s work falls into three categories: discovering proble...
Troubleshooting MySQL Batch Operations in Java: Why Batches Sometimes Don't Work
As is well known, using batch operations with MySQL can significantly improve performance when dealing with large datasets. However, when using MySQL in Java, certain details must be carefully handled; otherwise, batch operations may not actually take effect, and you won’t benefit from the performance gains of batching. Recently, I noticed that the performance profile of a particular SQL query was abnormally slow — inserting several thousand records in batch was taking on the order of secon...
Unit Testing Best Practices: Practical Experience and Guidelines
A while ago, when I was trying to improve the unit tests for a project, I realized that I never had a particularly clear understanding of how to write unit tests. So I looked up some materials, and in the process discovered that everyone’s perspectives are quite different. Every article I read updated my own understanding. This article combines others’ viewpoints with my own practical experience to summarize what I currently believe to be correct. It probably won’t be the most definitive answ...
About RocketMQ's readQueue and writeQueue
Explaining why MessageQueue in RocketMQ is split into writeQueue and readQueue. First, let me briefly introduce what a queue in RocketMQ is. Here is an architecture diagram of RocketMQ found online.As we know, when using RocketMQ, we produce or consume against a specific topic. MessageQueue is a part of a topic, similar to the concept of partitions in Kafka. A queue is the minimum unit for consumer consumption, meaning the number of consumers cannot exceed the number of queues. A very speci...
A Powerful Tool for Data Analytics: Introduction to ClickHouse
ClickHouse is an open-source database for real-time data analytics developed by Yandex, initially used in multiple data analytics projects internally at Yandex. To introduce ClickHouse, we first need to introduce Yandex. ClickHouse’s emergence is closely related to Yandex’s business needs. Yandex is Russia’s largest search engine, with many data analytics projects. The largest of these by data volume is Yandex.Metrica, a website analytics service similar to Baidu Analytics, with data volume s...
Converting Between Uppercase and Lowercase Using Bitwise Operations
Bitwise operations are a widely used computation method in computer science. When used appropriately, they can greatly improve computational efficiency. Today, I’d like to introduce a clever application of bitwise operations: converting between uppercase and lowercase letters. To tackle this problem, we can first examine the ASCII code characteristics of uppercase and lowercase letters. As we can see, the ASCII code values of each pair of uppercase and lowercase letters differ by 32. In bi...
ActiveMQ Multi-threaded Consumption - Different Approaches
In a previous article, I introduced the basic syntax for using ActiveMQ on the client side. It is worth noting the consumer side: 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 public void consume() throws JMSException { ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(); cf.setBrokerURL("tcp://localhost:61616"); Connection connection = cf.createConnection(); connection.start(); Sessio...
Some Experience with Balance Deduction Under High Concurrency
Recently, I participated in optimizing an older billing system and learned some common techniques for balance deduction under high concurrency. I also tried some approaches, so I’m summarizing my findings here. Problem DescriptionFor a billing system, concurrency issues are actually divided into two categories. The first is high application concurrency—essentially a large number of users and high access volume. This type of problem is no different from general high concurrency problems and ...
Java Details: Ternary Operator and Autoboxing
Problem IntroductionI encountered an interesting problem today while scanning code with FindBugs — it’s about the ternary operator. Let me record it here. It’s about code like this: 12boolean b = true; Long a = b ? 0l : Long.valueOf(2); FindBugs gave the warning: “Boxed value is unboxed and then immediately reboxed” — meaning a boxed object is unboxed and then immediately reboxed. This problem is actually quite common. I didn’t pay much attention to it at first, and just habitually change...














