Xiaomi Java Interview Insights: Reflection, Dynamic Proxies, Redis & JWT

The article starts by highlighting Xiaomi's competitive software developer salaries, then provides a detailed Java interview guide covering reflection fundamentals, static vs dynamic proxies, SPI vs API, synchronization behavior, Redis caching strategies, and JWT authentication, complete with code examples and practical comparisons.

JavaGuide
JavaGuide
JavaGuide
Xiaomi Java Interview Insights: Reflection, Dynamic Proxies, Redis & JWT

Xiaomi recently announced its software development salaries, noting that entry‑level positions in Beijing start at 18k × 15, with higher offers up to 20‑24k × 15, while senior roles in autonomous driving can reach 100w‑160w, requiring top‑university PhDs and strong personal ability.

Understanding Reflection

Reflection allows runtime inspection and invocation of any class's fields and methods, which is essential for frameworks like Spring, Spring Boot, and MyBatis. Annotations such as @Component and @Value work because the framework uses reflection to read class metadata.

How to Implement Dynamic Proxies

Dynamic proxies enable method enhancement without modifying source code. Java provides two main approaches:

JDK Dynamic Proxy : Requires the target class to implement one or more interfaces. The proxy instance is created at runtime via Proxy.newProxyInstance(). Calls are forwarded to an InvocationHandler 's invoke method, where pre‑ and post‑logic can be added.

CGLIB Dynamic Proxy : Uses the third‑party CGLIB library to generate a subclass of the target class at runtime (via ASM bytecode manipulation). It can proxy classes without interfaces but cannot proxy final, private, or static methods.

In most cases, JDK dynamic proxy is more efficient, especially after recent JDK optimizations.

Static Proxy vs Dynamic Proxy

The core differences are:

Proxy relationship timing : Static proxies are determined at compile time (a fixed .class file), while dynamic proxies are created at runtime.

Implementation : Static proxies require manually written proxy classes that implement the same interface as the target, leading to higher code volume and maintenance cost. Dynamic proxies use a handler or interceptor to encapsulate enhancement logic, offering reuse and lower code size.

Interface dependency : Static proxies need the target to implement an interface; dynamic proxies can proxy either interfaces or concrete classes.

Advantages : Static proxies are simple and have no extra framework dependencies. Dynamic proxies are more flexible, reusable, and better suited for complex scenarios such as Spring AOP.

SPI vs API

SPI (Service Provider Interface) is designed for framework extensions: the service interface resides on the provider side, and implementations are supplied by third parties. API (Application Programming Interface) is used by callers to invoke functionality provided by a service. Typical usage examples include Spring, database drivers, logging frameworks, and Dubbo extensions.

Java Synchronization Locks

The synchronized keyword is built on the JVM's monitor lock. Whether the block exits normally or via an exception, the monitor is automatically released, preventing deadlocks. The article demonstrates this with a multithreaded example where one thread throws an exception while holding the lock, yet another thread can still acquire the lock afterward, confirming correct lock release.

Why Use Redis?

Redis offers faster access (memory‑based), higher QPS (5w+ to 10w+ compared to ~4k for MySQL), and rich features such as distributed locks, rate limiting, message queues, and data structures. Compared with local caches, Redis provides consistent data across servers, larger memory capacity, persistence, centralized management, and richer functionality.

Typical multi‑level cache architecture uses a local in‑memory cache (e.g., Caffeine) as L1 and Redis as L2. Reads first check L1, then fall back to L2, and finally to the database if needed.

Redis Use Cases Beyond Caching

Distributed locks (commonly via Redisson)

Rate limiting (Redis + Lua scripts or Redisson's RRateLimiter)

Message queues (List and Stream data structures)

Delayed queues (Redisson's sorted‑set based implementation)

Distributed sessions (storing session data in String or Hash)

Complex business scenarios (bitmap for active users, sorted set for leaderboards, HyperLogLog for UV/PV)

Redisson Distributed Lock Implementation

Redisson provides an easy‑to‑use distributed lock with an automatic watchdog that renews the lock lease (default 30 s, configurable via setLockWatchdogTimeout). The renewal logic runs asynchronously using a Lua script to ensure atomicity.

private long lockWatchdogTimeout = 30 * 1000;
public Config setLockWatchdogTimeout(long lockWatchdogTimeout) {
    this.lockWatchdogTimeout = lockWatchdogTimeout;
    return this;
}
public long getLockWatchdogTimeout() {
    return lockWatchdogTimeout;
}

When acquiring a lock without specifying a lease time, Redisson activates the watchdog; specifying a lease time disables it.

Why Choose JWT for Authentication?

JWT is stateless, eliminating server‑side session storage and improving scalability. It avoids CSRF attacks because it does not rely on cookies, works well for mobile clients, and simplifies single sign‑on across services. However, JWT has drawbacks: tokens remain valid until expiration (making logout difficult), refresh token management is required, and the token size adds network overhead.

Interview Questions Highlighted

Leetcode 217 – Contains Duplicate: return true if any element appears at least twice.

Leetcode 61 – Rotate List: rotate a linked list right by k positions.

The article concludes with references to further reading on Java proxy patterns, distributed locks, and other backend topics.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaRedisReflectionSynchronizationJWTSPIDynamic Proxy
JavaGuide
Written by

JavaGuide

Backend tech guide and AI engineering practice covering fundamentals, databases, distributed systems, high concurrency, system design, plus AI agents and large-model engineering.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.