From the course: Parallel and Concurrent Programming with Java 1

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Thread lifecycle: Java demo

Thread lifecycle: Java demo - Java Tutorial

From the course: Parallel and Concurrent Programming with Java 1

Start my 1-month free trial

Thread lifecycle: Java demo

- [Instructor] In Java, threads can be in one of six possible states. There's the usual new state for threads that have not yet been started, the runnable state for threads that are executing in the Java virtual machine, blocked which in Java means a thread is blocked waiting for a monitor lock which we'll cover later, and the terminated state for after a thread has exited. The two additional states that Java adds are basically more specific variations of being blocked while waiting on other threads. In the waiting state, a thread is waiting indefinitely for another thread to perform a particular action. And in the timed waiting state, the thread will wait for another thread to perform an action for up to a specific waiting time. To demonstrate the lifecycle of a Java thread from creation to termination, I've created this example program which recreates the interactions between Olivia and me in the previous video where I spawned her as a second thread to help slice sausages to make…

Contents