← PayPal Interview Insights

PayPal·Software Engineer·Technical Phone Screen·Senior

Senior
Jun 2026

Summary

PayPal technical phone screen for a software engineer role, pretty much a deep dive into Java concurrency. One question, but they really wanted you to go far with it.

Questions Asked (1)

Q1

Is Java's HashMap thread-safe? Walk through how ConcurrentHashMap achieves both thread safety and performance in modern JDKs, including things like lock striping, CAS operations, non-blocking reads, how it handles high collision scenarios, and its resizing behavior. When would you pick one over the other?

Technical Trade-offsSystem DesignAlgorithms & Data Structures
Author's notes

Started fine.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by directly answering that HashMap is not thread-safe, then explain how ConcurrentHashMap achieves thread safety and performance through lock striping, CAS, and non-blocking reads. Walk through its internal mechanisms in a structured way, covering collision handling and resizing, and conclude with practical trade-offs for when to use each.

Pro tip: Mention that in modern JDKs (Java 8+), ConcurrentHashMap uses synchronized on individual bins (nodes) instead of segment locking, and that its resizing is cooperative and non-blocking for reads. This shows you're up-to-date and understand the evolution.

1. Direct Answer and HashMap Limitations

State clearly that HashMap is not thread-safe and explain the consequences of concurrent modification, such as data corruption or infinite loops in older JDKs.

2. ConcurrentHashMap's Thread Safety Mechanisms

Describe how ConcurrentHashMap uses CAS for lock-free updates when bins are empty, and synchronized on the first node of a bin for updates when collisions occur, ensuring fine-grained locking.

3. Performance Optimizations

Explain non-blocking reads via volatile reads, lock striping (bin-level locking), and how resizing is done cooperatively with multiple threads helping to transfer bins.

4. Handling High Collisions and Resizing

Discuss treeification (converting bins to red-black trees when collisions exceed a threshold) and the resizing process, including how reads remain non-blocking during resizing.

5. When to Choose Which

Provide guidance: use HashMap for single-threaded or read-only scenarios; use ConcurrentHashMap for concurrent access, especially when high read/write concurrency is needed, but consider alternatives like synchronizedMap for low contention.

Key Points to Mention

  • HashMap is not thread-safe; concurrent modification can cause data corruption or infinite loops.
  • ConcurrentHashMap uses CAS for lock-free updates on empty bins and synchronized on the first node for collisions.
  • Non-blocking reads are achieved through volatile reads of nodes and the table array.
  • Lock striping in modern JDKs is at the bin level, not segment level, allowing higher concurrency.
  • Treeification converts long collision chains to red-black trees to maintain O(log n) performance.
  • Resizing is cooperative: multiple threads can help transfer bins, and reads can proceed during resizing.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.