Skip to main content

Posts

Showing posts from March, 2025

PayPal Technical Interview Guide (3-4 Years Experience)

Core Java & Data Structures 1. Explain the internal working of ConcurrentHashMap. How does it achieve thread safety, and what are its performance trade-offs? Internal Working: Prior to Java 8, it used segment-based locking , where the map was divided into segments , each with its own lock. In Java 8+, it uses a bucket-level lock-free approach with CAS (Compare-And-Swap) for updates. The table is backed by Node<K, V>[] with each entry being a linked list or a tree (if size > 8). Uses synchronized blocks for initialization and volatile for visibility . Thread Safety Mechanism: Uses CAS for atomic updates and synchronized blocks where necessary. Prevents full-table locks by optimistic concurrency control . Buckets reduce lock contention compared to synchronizedMap . Trade-offs: Better scalability than Hashtable , synchronizedMap . Memory overhead due to linked-list/tree structures. More CPU cycles in highly concurrent scenarios. 2. WeakHashMap v...