Exception Handling & Concurrency Flashcards
7 cards from real 1Z0-819 practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 Exception Handling & Concurrency flashcards as text
What is a deadlock in concurrent programming?
Answer: Two or more threads each waiting for a lock held by the other
Deadlock is a circular wait condition where thread A holds lock X and wants Y, while thread B holds Y and wants X, causing both to block forever.
Which method allows a thread to pause execution and give other threads a chance to run?
Answer: Thread.yield()
Thread.yield() hints to the scheduler that the current thread is willing to relinquish CPU time, though the scheduler may ignore this hint.
What does the try-with-resources statement require of its resources?
Answer: They must implement AutoCloseable
Resources in try-with-resources must implement AutoCloseable (or its subinterface Closeable), ensuring close() is called automatically.
What is the difference between ConcurrentHashMap and Collections.synchronizedMap()?
Answer: ConcurrentHashMap uses segment-level locking for higher throughput; synchronizedMap locks the entire map per operation
ConcurrentHashMap uses internal striped locking for much better concurrent throughput, while synchronizedMap serializes all access with a single lock.
Which checked exception does Thread.sleep() declare?
Answer: InterruptedException
Thread.sleep(millis) declares throws InterruptedException so callers must handle the case where another thread interrupts the sleeping thread.
What does the synchronized keyword guarantee when applied to an instance method?
Answer: Only one thread holds the intrinsic lock of 'this' while executing the method
synchronized on an instance method acquires the intrinsic monitor lock on 'this', preventing other synchronized methods on the same object from running concurrently.
Which Future method retrieves the result of a Callable, blocking if necessary, and can throw ExecutionException?
Answer: Future.get()
Future.get() blocks until the computation completes and wraps any exception thrown by the task in an ExecutionException.