Govt Exams
Thread pooling reuses a fixed set of threads instead of creating new ones for each task. ExecutorService provides convenient methods for thread pool management.
A deadlock occurs when two or more threads are blocked forever, waiting for each other to release resources they need.
A daemon thread runs in the background and doesn't prevent the JVM from exiting. When all non-daemon threads finish, the JVM exits even if daemon threads are running.
The AtomicInteger class (and other Atomic classes) provides thread-safe operations without explicit synchronization using low-level atomic operations.
notify() wakes up a single thread that is waiting on the object's monitor, while notifyAll() wakes up all threads waiting on that object.
A synchronized method locks the object, allowing only one thread to execute it at a time for that object instance.
A race condition occurs when multiple threads access shared data and the final result depends on the order of execution, which is unpredictable.
Calling start() on an already started thread throws IllegalThreadStateException because a thread can only be started once.
The thread states are NEW, RUNNABLE, RUNNING, BLOCKED, WAITING, TIMED_WAITING, and TERMINATED. SLEEPING is not an official state.
The synchronized keyword provides mutual exclusion to ensure that only one thread can access a resource at a time, preventing race conditions.