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. The Essence of Programming as a CareerI want to discuss this from two perspectives. First, from the work itself — in my view, a programmer’s work falls int...
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. The ProblemRecently, I noticed that the performance profile of a particular SQL query was abnormally slow — inserting several thousand records in batch was taking on the ord...
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
RocketMQ’s MessageQueue has a unique design: it splits a queue into readQueueNums (read queue count) and writeQueueNums (write queue count). In the vast majority of cases, these two values must be equal — if they diverge, serious problems arise. So why separate them? The answer lies in smooth scaling. What is a MessageQueue?In RocketMQ, a Topic is a logical category for messages, while a MessageQueue is the physical shard of a Topic, similar to Kafka’s Partition. A key constraint: the numbe...
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 among the most fundamental and efficient operations in computer science. Today, let’s explore a classic application: converting between uppercase and lowercase letters with a single line of code. Why Use Bitwise Operations for Case Conversion?Your first reaction might be: doesn’t Java already have Character.toUpperCase() and Character.toLowerCase()? Why reinvent the wheel? Indeed, 99% of the time you should use the standard library. But understanding this trick has se...
ActiveMQ Multi-threaded Consumption - Different Approaches
Problem ScenarioIn 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(...
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...













