threewood1 Technical Blog
website·Indexed 31 days ago
https://threewood1.topA technical knowledge base covering Java development, including Spring 6, Spring Boot, MybatisPlus, and JVM internals. The site provides guides on Redis, RabbitMQ, Docker, MySQL, and Maven, alongside microservices architecture patterns, LeetCode solutions, and version control with Git and SVN.
What's inside threewood1
- Spring (since version 2.5) supports annotations to simplify configuration and replace verbose XML autowiring. The general workflow for implementing annotation-based dependency injection involves four steps: introducing dependencies, enabling component scanning, defining beans using annotations, and performing dependency injection.
Overview of JDK 8 key features
JDK 8 introduced several major features to modernize Java development:
- Lambda Expressions: Anonymous functions that allow functions to be passed as arguments to methods.
- Stream API: A way to process collections of data using functional-style operations (filter, map, sort) with support for parallel execution.
- Functional Interfaces: Interfaces with exactly one abstract method, often marked with
@FunctionalInterface, enabling the use of lambdas. - Default Methods: Allows interfaces to provide a default implementation of methods, ensuring backward compatibility during interface evolution.
- Optional Class: A container object used to represent the presence or absence of a value, helping to prevent
NullPointerException. - Date and Time API: The
java.timepackage provides a modern replacement for the legacyjava.util.Dateandjava.util.Calendarclasses.
Overview of JDBC Architecture and Concepts
JDBC (Java Database Connectivity) is a Java API specification that allows Java applications to interact with various relational databases (e.g., MySQL, Oracle) using SQL strings. It follows an interface-based programming model where the JDK provides the standard API interfaces (java.sqlandjavax.sql), and database vendors provide the specific driver implementations (JAR files). This decoupling allows developers to switch database vendors by changing the driver JAR without modifying the core application code.Introduction to Java Reflection
Reflection in Java allows a program to load a class and programmatically analyze its components, such as member variables, methods, and constructors. It is primarily used to build generic frameworks by allowing the code to operate on any object regardless of its specific type, though it can break encapsulation.Overview of Distributed Locks in Redis
A distributed lock is used to control access to shared resources across different processes in a distributed system. It ensures mutual exclusion to prevent interference and maintain data consistency when multiple hosts or systems share a critical resource.Understand Seata Distributed Transaction Roles
Seata solves distributed transaction problems (where business logic spans multiple services and databases) by using a transaction coordinator to ensure all branch transactions either commit or roll back together. It defines three primary roles:
- TC (Transaction Coordinator): A standalone server that maintains the status of global and branch transactions and coordinates the final commit or rollback.
- TM (Transaction Manager): A client-side component that defines the global transaction scope and initiates the commit or rollback.
- RM (Resource Manager): A client-side component that manages branch transactions, registers them with the TC, and executes the actual commit/rollback on the local resource.
Compare Log4j and SLF4J for Java logging
Log4j and SLF4J are both widely used Java logging frameworks. Log4j provides comprehensive logging features including configurable log levels, output formats, and log rolling, though it can be complex to configure and may have performance issues. SLF4J acts as a simple API facade that supports integration with other logging frameworks and offers higher performance, though it provides fewer built-in features than a full implementation like Log4j.Compare Redis and MySQL
Redis and MySQL serve different purposes based on their architecture:
- Storage: Redis is a key-value store supporting various data structures; MySQL is a relational database using tables.
- Persistence: Redis stores data in memory and persists to disk via specific mechanisms; MySQL primarily stores data on disk.
- Querying: Redis uses a dedicated command set and does not support SQL or complex queries; MySQL uses SQL for complex data retrieval.
- Use Case: Redis is optimized for high performance and low latency (read-heavy scenarios); MySQL is suited for complex queries, transaction processing, and large-scale durable storage.
Compare synchronous and asynchronous communication in microservices
In microservice architectures, communication typically falls into two categories:
Synchronous Communication (e.g., OpenFeign):
- Behavior: The caller sends a request and blocks (waits) until the provider returns a result.
- Drawbacks:
- Poor Extensibility: Adding new requirements (e.g., adding a notification service after payment) requires modifying existing business logic, violating the Open-Closed Principle.
- Performance Degradation: Total response time is the sum of all remote call durations.
- Cascading Failures: If a downstream service (e.g., notification service) fails, the entire transaction may roll back, even if the primary action (e.g., payment) succeeded.
Asynchronous Communication (via Message Queue):
- Behavior: The sender sends a message to a Message Broker and continues its execution without waiting for a response. Consumers subscribe to the Broker to process messages independently.
- Advantages:
- Low Coupling: Senders and receivers are decoupled.
- Higher Performance: The sender only spends time on local logic and sending the message.
- Strong Extensibility: New services can be added by simply subscribing to existing messages without changing the sender's code.
- Fault Isolation: Failures in consumer services do not impact the primary sender service.
- Trade-offs: Increased architectural complexity, harder debugging, and total reliance on the Broker's reliability and performance.
Implement Java OOP Principles: Encapsulation, Inheritance, and Polymorphism
Java's object-oriented design relies on three core pillars:
- Encapsulation: Hiding internal state (fields/attributes) and exposing it only through public methods (interfaces) to improve security and maintainability.
- Inheritance: Creating new classes (subclasses) from existing ones (superclasses) to reuse and extend behavior.
- Polymorphism: Allowing different objects to respond to the same operation in different ways. This is achieved via:
- Compile-time (Static) Polymorphism: Implemented via Method Overloading (same method name, different parameters).
- Runtime (Dynamic) Polymorphism: Implemented via Method Overriding (subclass provides a specific implementation of a method already defined in its superclass).
Understand Content Delivery Networks (CDN)
A CDN is a distributed network of edge servers that cache content closer to the end-user.
How it works: When a user requests a resource, the CDN serves it from the nearest edge node. If the resource isn't cached, the CDN fetches it from the origin server and caches it for subsequent users.
Benefits:
- Reduced Latency: Faster page load times due to physical proximity.
- Load Balancing: Prevents origin server crashes by distributing traffic across multiple nodes.
- Improved Reliability: Higher availability for live streaming and high-traffic content.
Spring Framework Core Concepts
Spring Framework is a lightweight, layered, aspect-oriented Java application solution. Its two most critical modules are:
- IoC (Inversion of Control): Transfers the responsibility of object creation and lifecycle management to the Spring container.
- AOP (Aspect Oriented Programming): Encapsulates common behaviors (e.g., logging, transactions, permissions) that are unrelated to core business logic to reduce code duplication and decouple modules.