Interview Review: Java ThreadPool, Redis, Message Queue, Network, and Algorithms
This article shares a ByteDance interview experience and provides detailed technical explanations on Java thread pools, Redis internals, message queue usage, computer networking processes, HTTP/HTTPS differences, and a sample algorithm problem, offering valuable insights for backend developers.
Source: authorized from JavaGuide. The article shares a ByteDance interview experience and provides detailed technical explanations on Java thread pools, Redis internals, message queues, computer networking, HTTP/HTTPS differences, and a sample algorithm problem.
Java ThreadPool
What is the purpose of a thread pool?
Thread pools provide a way to limit and manage resources for executing tasks, maintaining statistics such as completed task count.
Key benefits
Reduce resource consumption : Reuse existing threads to avoid creation and destruction overhead.
Improve response speed : Tasks can start immediately without waiting for thread creation.
Enhance manageability : Unified allocation, tuning, and monitoring of threads.
Important parameters of ThreadPoolExecutor
Core parameters: corePoolSize , maximumPoolSize , workQueue .
corePoolSize : Maximum number of threads when the queue is not full.
maximumPoolSize : Maximum threads when the queue is full.
workQueue : Queue where new tasks are placed if core threads are busy.
Other common parameters
keepAliveTime : Time that excess threads (beyond corePoolSize) stay alive when idle.
unit : Time unit for keepAliveTime.
threadFactory : Factory to create new threads.
handler : Rejection policy.
keepAliveTime and core threads
By default core threads are not destroyed; keepAliveTime applies only to non‑core threads. Since JDK 1.6 you can enable allowCoreThreadTimeOut to let core threads time out.
public void allowCoreThreadTimeOut(boolean value) {
// core threads' keepAliveTime must be > 0 to enable timeout
if (value && keepAliveTime <= 0) {
throw new IllegalArgumentException("Core threads must have nonzero keep alive times");
}
if (value != allowCoreThreadTimeOut) {
allowCoreThreadTimeOut = value;
// if timeout enabled, interrupt idle workers including core threads
if (value) {
interruptIdleWorkers();
}
}
}Example of creating a pool with core size 5, keepAliveTime 10 seconds, and enabling core thread timeout:
// create a pool with core size 5, keepAliveTime 10 seconds
ThreadPoolExecutor executor = new ThreadPoolExecutor(5, 5, 10L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(15));
// allow core threads to time out
executor.allowCoreThreadTimeOut(true);
// submit 10 tasks
for (int i = 0; i < 10; i++) {
executor.execute(() -> {
System.out.println(Thread.currentThread().getName());
});
}Note: when core thread timeout is enabled, keepAliveTime must be greater than 0, otherwise an exception is thrown.
Redis
Why is Redis fast?
Because it operates in memory, uses a reactor event loop with I/O multiplexing, and implements optimized data structures.
Expiration mechanisms
Commands such as EXPIRE , PEXPIRE , EXPIREAT , PEXPIREAT set TTL; TTL and PTTL query remaining time. Redis stores expiration timestamps in an "expires" dictionary inside redisDb and uses a combination of periodic and lazy deletion.
typedef struct redisDb {
...
dict *dict; // key‑value store
dict *expires; // expiration times
...
} redisDb;Hot keys
Hot keys receive disproportionate access and can become performance bottlenecks; common mitigations include read/write separation, Redis Cluster, and secondary caches (e.g., Caffeine).
Sorted Set (zset) implementation
Sorted sets are implemented with a skip‑list (and a ziplist for small elements) backed by ConcurrentSkipListMap , supporting score‑ordered retrieval.
zset-max-ziplist-value 64
zset-max-ziplist-entries 128Message Queue (MQ)
Why use MQ?
It improves performance via asynchronous processing, enables throttling, and reduces system coupling.
Decoupling example
Producers publish messages to a queue; consumers subscribe without direct dependencies, allowing independent scaling and easier extension.
Delayed messages in RocketMQ
Versions ≤4.x support 18 fixed delay levels (e.g., 1 s, 5 s, …, 2 h). RocketMQ 5.0 introduces timer messages based on a time‑wheel algorithm, overcoming the limitations of fixed levels.
Computer Network
Browser request flow
Enter the URL in the browser.
Resolve the domain name via DNS.
Establish a TCP connection to the server.
Send an HTTP request over the TCP connection.
Server processes the request and returns an HTTP response.
Browser parses HTML, renders the page, and fetches sub‑resources (images, CSS, JS) as needed.
Close or reuse the TCP connection when communication is finished.
HTTP vs HTTPS
Port : HTTP uses 80, HTTPS uses 443.
URL scheme : http:// vs https:// .
Security : HTTPS runs over TLS, encrypting data and using certificates for authentication, at the cost of additional server resources.
SEO : Search engines favor HTTPS sites.
How HTTPS ensures transmission security
HTTPS encrypts data in transit and uses digital certificates with signatures to authenticate the server, preventing eavesdropping and man‑in‑the‑middle attacks.
Algorithm
Reference to LeetCode problem “Longest Substring Without Repeating Characters” (medium difficulty).
IT Services Circle
Delivering cutting-edge internet insights and practical learning resources. We're a passionate and principled IT media platform.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.