1 00:00:00,420 --> 00:00:02,820 A thread can have many states during its lifetime. 2 00:00:05,670 --> 00:00:09,250 In this lesson, you will monitor the state of a threat during its lifetime. 3 00:00:12,650 --> 00:00:16,490 The state of a threat can be new, which means the threat hasn't started executing it. 4 00:00:20,900 --> 00:00:28,880 So if we print the thread state before we start it, system data, print line threat to get state. 5 00:00:29,910 --> 00:00:31,770 It should return a state of new. 6 00:00:39,760 --> 00:00:44,050 Now, the state of a thread can also be runnable, which means the thread is currently running. 7 00:00:47,190 --> 00:00:51,480 If we print the thread states right after starting it. 8 00:00:54,180 --> 00:00:55,080 It's still running. 9 00:00:57,060 --> 00:00:58,140 And now it finishes. 10 00:01:02,350 --> 00:01:05,830 Now, the state of a threat can also be terminated, which means the threat is finished. 11 00:01:06,370 --> 00:01:11,500 The problem is we're printing the state of the background thread from inside the main thread. 12 00:01:11,980 --> 00:01:13,660 So if we run our current code? 13 00:01:15,440 --> 00:01:19,460 The main thread finishes executing while our background thread is still running. 14 00:01:21,340 --> 00:01:23,080 But what if we put this here? 15 00:01:25,240 --> 00:01:30,610 We should get the same thing because the time it takes to go from here to here is zero milliseconds. 16 00:01:30,820 --> 00:01:33,580 But this task takes three seconds to execute. 17 00:01:35,330 --> 00:01:39,380 From a visual perspective, we're making progress on both threads at the same time. 18 00:01:39,650 --> 00:01:44,720 But the main thread finishes way before the second thread, so given our current knowledge about threads, 19 00:01:44,720 --> 00:01:47,990 it would be really hard to print a terminated state for threat to. 20 00:01:48,000 --> 00:01:50,150 But don't worry, we're going to revisit this. 21 00:01:59,580 --> 00:02:02,550 Let's recap, a threat can have many states during its lifetime. 22 00:02:02,700 --> 00:02:06,270 We looked at the new state, which means a threat hasn't started yet. 23 00:02:06,660 --> 00:02:12,180 A runnable state, which means the threat is still running and terminated, which means the threat is 24 00:02:12,180 --> 00:02:12,690 finished. 25 00:02:12,810 --> 00:02:16,410 A thread can have other states, but for now we're just going to focus on these.