Posts

Spring Boot's Eight Built-in Methods for Controlling Database Connections

Image
  1. Introduction The core objective of the Spring Framework in managing database connections is to ensure efficient, secure, and transaction-aware usage of this critical resource. It abstracts the complexity of obtaining and releasing connections at the underlying level. The key lies in lifecycle management: Spring advocates acquiring a connection only when needed and releasing it back to the pool (or closing it) as soon as it’s no longer in use, preventing resource leaks.  More importantly, it binds the connection to the current execution thread—especially within a transactional context. This ensures that multiple database operations within the same transaction share the same physical connection, maintaining atomicity and consistency (ACID properties). Spring’s transaction management infrastructure automatically coordinates connection acquisition, binding, commit/rollback, and release. Developers typically do not need to handle connection details manually.  By simply fo...

Why is it not recommended to use `DELETE` to remove a large amount of data in MySQL?

Image
In this post, we will analyze why it's not recommended to use DELETE to remove large volumes of data, from three perspectives: InnoDB storage space allocation, the performance impact of DELETE , and best practice recommendations. Overview of InnoDB Storage Architecture Logical Structure Tablespace Segment Extent: Each extent consists of 32 pages. Page: The smallest I/O unit in InnoDB, with a default size of 16KB. Physical Structure Data Files ( .ibd / ibdata1 ): Store tables, indexes, and dictionary metadata. Log Files ( ib_logfile* ): Record page modifications and are used for crash recovery. Extent Auto-Expansion Strategy Initially, 1 extent is allocated. If the total tablespace is less than 32MB, 1 extent is added at a time. If it exceeds 32MB, 4 extents are added at a time. Types of InnoDB Tablespaces System Tablespace ( ibdata1 ): Stores internal dictionary and other metadata. File-Per-Table Tablespace ( innodb_file_per_table=ON ): Each table...

How to Quickly Delete a Large Amount of Data from a Massive Database Table with Tens of Millions of Records

Image
How to Quickly Delete a Large Amount of Data from a Massive Table with Tens of Millions of Records?So, how can we tackle this problem more effectively?  Let’s break it down from the following perspectives: What problems might occur if we delete a large amount of data all at once? Pre-deletion rehearsal: Evaluate the data volume, confirm the deletion plan, and check whether deletion conditions are indexed. Common strategies for bulk data deletion Post-deletion cleanup and follow-up actions 1. What Problems Might Arise from Deleting a Large Amount of Data All at Once? When dealing with a large table containing tens of millions of records, deleting all data in one go can lead to serious issues such as table locking, transaction log bloating, CPU spikes, and replication lag between master and slave databases. 1.1 Table Locking That Freezes the Business Problem: The delete operation can lock the table for a long time (especially if wrapped in a large transaction), blocking...

A Brief Guide to Several Ways of Implementing Asynchronous Programming in Java

Image
In our daily development work, we often talk about asynchronous programming.  For example, in a user registration API, after a user successfully registers, we might send them a notification email asynchronously. But here’s a question for you:  Do you know how many different ways there are to implement asynchronous programming in Java? Let me walk you through the following commonly used approaches: • Using Thread and Runnable • Using thread pools provided by Executors • Using a custom thread pool • Using Future and Callable • Using CompletableFuture • Using ForkJoinPool • Using Spring's @Async for asynchronous methods • Using Message Queues (MQ) for async processing 1. Using Thread and Runnable Thread and Runnable are the most basic ways to implement asynchronous programming in Java.  You can directly use them to create and manage threads. public class Test { public static void main ( String [] args ) { System . out . println ( "Main ...