Threads Flashcards
What is a thread?
A lightweight process that shares code, data, and OS resources but has its own execution stack and program counter.
Difference between process and thread?
Processes have separate memory spaces; threads share memory within a process.
What are the advantages of multithreading?
Responsiveness, resource sharing, economy, scalability.
What is concurrency?
When two or more tasks start and progress over the same time period (may not be simultaneous).
What is parallelism?
True simultaneous execution of tasks on multiple cores.
What is the Java method to start a thread?
start() method.
In Java, where is the thread’s execution logic defined?
In the run() method.
What are the main thread states in Java?
NEW, RUNNABLE, RUNNING, BLOCKED, WAITING, TIMED_WAITING, TERMINATED.
What does join() do in Java threads?
It allows one thread to wait for another to finish.
What does yield() do in Java threads?
Hints the scheduler that the current thread is willing to yield CPU to other threads.