Entrance Exams
Govt. Exams
A race condition occurs when multiple threads access shared data and the final result depends on the order of execution, which is unpredictable.
The join() method causes the current thread to wait until the thread on which it is called completes its execution.
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.
The interrupt() method is the proper way to stop a thread in Java. The stop() method is deprecated and dangerous.
Thread.sleep() pauses execution for a specified milliseconds, while yield() is a hint to the scheduler that the current thread is willing to yield its turn.
The Runnable interface is the correct interface to implement for creating threads in Java. It has a single abstract method run().
WeakHashMap uses weak references for keys. When a key is no longer referenced elsewhere, it becomes eligible for garbage collection and is automatically removed from the map.
LinkedList implements Queue with FIFO behavior. poll() removes and returns 10. peek() returns 20 without removing it. Queue now contains [20, 30].