Lesson content
Read, practise, then check your understanding
A Thread represents an execution; Runnable represents a no-result task. Call start, not run, to create concurrent execution.
Lifecycle and cancellation
Thread worker = new Thread(() -> {
while (!Thread.currentThread().isInterrupted()) {
// bounded unit of work
}
});
worker.start();
worker.interrupt();
worker.join();
Interruption is cooperative. Blocking methods may throw InterruptedException; either propagate it or restore status with Thread.currentThread().interrupt(). Avoid sharing mutable state and never use deprecated forceful controls such as stop. For application work prefer executors, structured concurrency where supported, or virtual threads for numerous blocking tasks rather than manually creating unbounded platform threads.
Knowledge check
Answer every question correctly to complete this chapter.
0 of 10 checks passed
Your progress is saved on this device.