Java_Multithreading_Notes
Java_Multithreading_Notes
- Multithreading is a form of multitasking; it's more efficient because threads share the same process.
- Java handles multithreading directly, which helps reduce idle CPU time (e.g., waiting for input or network
data).
- Java's runtime system relies on threads and is designed for asynchronous execution.
- Single-threaded systems use event loops that block the program during wait states, wasting CPU time.
- In Java, if one thread is blocked, others can continue to execute, improving efficiency.
- Works on both single-core (threads time-slice CPU) and multi-core systems (threads can run in parallel).
- Java's Fork/Join Framework enables parallel programming by splitting tasks and executing subtasks
concurrently.
- Each Java thread has a priority value which determines how threads are scheduled.
- Java uses monitors to allow only one thread to access a synchronized block at a time.
Page 1
Java Multithreading Notes
- Every object in Java has an implicit monitor; synchronized methods lock the object until execution
completes.
- A thread can wait inside a synchronized method until another thread notifies it.
- Java threads are implemented using the Thread class and Runnable interface.
- Runnable is implemented by any class whose instances are intended to be executed by a thread.
- start(): starts the thread and invokes run() in a new call stack.
Page 2