{"id":2290,"date":"2020-04-01T18:22:25","date_gmt":"2020-04-01T18:22:25","guid":{"rendered":"https:\/\/www.h2kinfosys.com\/blog\/?p=2290"},"modified":"2020-04-07T18:21:33","modified_gmt":"2020-04-07T12:51:33","slug":"java-threads-and-runnables","status":"publish","type":"post","link":"https:\/\/www.h2kinfosys.com\/blog\/java-threads-and-runnables\/","title":{"rendered":"Java Threads and Runnables"},"content":{"rendered":"<p>Since JDK 1.0 Java language provides built-in support for multithreaded programming.<br \/>\nMultithreading is an essential feature in the <a href=\"https:\/\/www.h2kinfosys.com\/courses\/java-online-training-course-details\">Java platform<\/a>. Every application has at least one thread. It is called the main thread. This thread can create more threads.<br \/>\nIn Java language, each thread is associated with an instance of the class Thread.<br \/>\nYou can use class Thread or interface Runnable for thread creation.<\/p>\n<h2>Thread class<\/h2>\n<p>The class Thread is a basic API to create a Java thread. The Java Virtual Machine allows an application to have multiple threads running concurrently. Threads have priorities, a higher priority means that thread has preferences to be executed. There is also a possibility to mark a thread as a daemon. Daemon thread is a background and low priority thread. It is dedicated to run tasks such as garbage collection. They provide services to support running of user thread. When an application starts there is usually a single non-daemon thread that typically calls method main.<br \/>\nLet&#8217;s create thread extending the class Thread:<\/p>\n<p dir=\"ltr\" style=\"line-height: 1.2; background-color: #ffffff; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: #ffffff; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public<\/span><span style=\"font-size: 12pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: #ffffff; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">c<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">lass<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0MyThread\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">extends<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0Thread {<\/span><br \/>\n<span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">void<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0run() {<\/span><br \/>\n<span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0System.<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #0000c0; background-color: transparent; font-weight: bold; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">out<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.println(<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #2a00ff; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">&#8220;My first thread is running!&#8221;<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">);<\/span><br \/>\n<span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0 \u00a0 \u00a0}<\/span><br \/>\n<span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>We don&#8217;t need any imports in our class, because class Thread is located in package java.lang. This <a href=\"https:\/\/www.h2kinfosys.com\/blog\/java-language-packages\/\">Java package<\/a> is importing automatically. This code is not enough to run thread. You have to call it for execution. There are two ways to do this:<br \/>\nsimply use the method start() for your thread;<br \/>\nuse executors.<br \/>\nHere we are using the first method to start our thread:<\/p>\n<p dir=\"ltr\" style=\"line-height: 1.2; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">class<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0ThreadExample {<\/span><br \/>\n<span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">static<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">void<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0main(String[]\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">args<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">) {<\/span><br \/>\n<span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">System.<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #0000c0; background-color: #ffffff; font-weight: bold; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">out<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.println(<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #2a00ff; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">&#8220;The main thread id is &#8220;<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">+ Thread.<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">currentThread<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">().getId());<\/span><br \/>\n<span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">MyThread\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">mythread<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0=\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">new<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0MyThread();<\/span><br \/>\n<span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">mythread<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.start();<\/span><br \/>\n<span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><br \/>\n<span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p>Method start() calls the MyThread method run(). As a result, we will get two threads running concurrently (main thread and thread that we have just created).<br \/>\nWhy do we use the method start ()? Why don&#8217;t we call the method run () directly? The method start, besides running thread, creates a separate call stack for the thread. Let&#8217;s try an example that will help us to understand how it works. We are going to create our thread 3 times and to print its id:<\/p>\n<p dir=\"ltr\" style=\"line-height: 1.2; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">class<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0ThreadExample {<\/span><br \/>\n<span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">static<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">void<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0main(String[]\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">args<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">) {<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><br \/>\n<span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">for<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">(<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">int<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">i<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0= 0;\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">i<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0&lt; 3;\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">i<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">++) {<\/span><br \/>\n<span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">MyThread\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">mythread<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0=\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">new<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0MyThread();<\/span><br \/>\n<span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">mythread<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.start();\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><br \/>\n<span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><br \/>\n<span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><br \/>\n<span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p>&nbsp;<\/p>\n<p dir=\"ltr\" style=\"line-height: 1.2; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">class<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0MyThread\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">extends<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0Thread {<\/span><br \/>\n<span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">void<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0run() {<\/span><br \/>\n<span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0System.<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #0000c0; background-color: transparent; font-weight: bold; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">out<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.println(<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #2a00ff; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">&#8220;My thread with id &#8220;<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">+ Thread.<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">currentThread<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">().getId() +\u00a0<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.2; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0 \u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #2a00ff; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">&#8221; is running!&#8221;<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">);<\/span><br \/>\n<span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0 \u00a0 \u00a0}<\/span><br \/>\n<span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p>The output of the current application will be:<\/p>\n<p>The main thread id is 1<br \/>\nMy thread with id 12 is running!<br \/>\nMy thread with id 13 is running!<br \/>\nMy thread with id 14 is running!<\/p>\n<p>In case we will run the thread by calling the method run() we will get:<\/p>\n<p><span style=\"font-weight: 400;\">The main thread id is 1<\/span><br \/>\nMy thread with id 1 is running!<br \/>\nMy thread with id 1 is running!<br \/>\nMy thread with id 1 is running!<\/p>\n<p>As you can understand, in case of method calling the method run(), no new thread is really created.<\/p>\n<h2>Thread Lifecycle<\/h2>\n<p>There are 6 states of a thread. You can find them in the image:<\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter wp-image-2295 size-full\" src=\"https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/04\/Screenshot_67.png\" alt=\"Java Threads and Runnables\" width=\"770\" height=\"499\" title=\"\" srcset=\"https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/04\/Screenshot_67.png 770w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/04\/Screenshot_67-300x194.png 300w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/04\/Screenshot_67-768x498.png 768w\" sizes=\"(max-width: 770px) 100vw, 770px\" \/><\/p>\n<p>A thread is in the New state when it is just created. It has not started yet. After calling the method run(), the thread is moving to the state Runnable. The Waiting or Blocked states mean that the thread is temporarily inactive and it doesn&#8217;t consume any CPU. It&#8217;s waiting for notification from another thread or waiting for accessing a protected section of code that is currently locked by some another thread. The Timed waiting state is about sleep or a conditional wait of the thread.<br \/>\nThe Terminated state can be reached in two cases: the thread finished his work and exited normally or an unhandled error occurred.<\/p>\n<p>There is the method Thread.getState() that returns the stated of its thread as one of the Enum values(NEW, RUNNABLE, BLOCKED, WAITING, TIMED_WAITING, TERMINATED).<\/p>\n<p>Here is an example of shaking the state of thread in different places:<\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">class<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0ThreadExample {<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">static<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">void<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0main(String[]\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">args<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">)\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">throws<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0InterruptedException {<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">MyThread\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">mythread<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0=\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">new<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0MyThread();<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">System.<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #0000c0; background-color: transparent; font-weight: bold; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">out<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.println(<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #2a00ff; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">&#8220;After new thread instance creation: &#8220;<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0+\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">mythread<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.getState());<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">mythread<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.start();<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">System.<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #0000c0; background-color: transparent; font-weight: bold; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">out<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.println(<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #2a00ff; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">&#8220;After calling the method start(): &#8220;<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0+\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">mythread<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.getState());<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">Thread.<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">sleep<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">(1000);<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">System.<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #0000c0; background-color: transparent; font-weight: bold; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">out<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.println(<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #2a00ff; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">&#8220;We sent our thread to sleep:\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #2a00ff; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #2a00ff; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #2a00ff; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #2a00ff; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #2a00ff; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #2a00ff; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #2a00ff; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #2a00ff; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">&#8220;<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">+<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">mythread<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.getState());<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">Thread.<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">sleep<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">(1000);<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">System.<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #0000c0; background-color: transparent; font-weight: bold; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">out<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.println(<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #2a00ff; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">&#8220;My Thread is finished: &#8220;<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">+<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">mythread<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.getState());<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">class<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0MyThread\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">extends<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0Thread {<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">void<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0run() {<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0System.<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #0000c0; background-color: transparent; font-weight: bold; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">out<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.println(<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #2a00ff; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">&#8220;In the thread the state is &#8220;<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">+\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">Thread.<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">currentThread<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">().getState());<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">try<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0{<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">Thread.<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">sleep<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">(1500);<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">catch<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0(InterruptedException\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">e<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">) {<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">e<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.printStackTrace();<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0 \u00a0 \u00a0}<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong>The output will be:<\/strong><br \/>\n<em>After new thread instance creation: NEW<\/em><br \/>\n<em> After calling the method start(): RUNNABLE<\/em><br \/>\n<em> In the thread the state is RUNNABLE<\/em><br \/>\n<em> We sent our thread to sleep: TIMED_WAITING<\/em><br \/>\n<em> My Thread is finished: TERMINATED<\/em><\/p>\n<p>In this example, we sent our thread to sleep. Also, we used method sleep in the main thread, because to reach all states of our thread we need to wait.<\/p>\n<p>The class Thread contains a method to interrupt a thread. If a thread is in the Waiting or the Blocked state, Interrupted Exception will be thrown. After, a thread interrupt status will be set back to the false state. You can check the interrupt status with the method isInterrupted().<\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">class<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0ThreadExample {<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: #ffffff; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: #ffffff; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">static<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: #ffffff; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">void<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0main(String[]\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">args<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">)\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: #ffffff; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">throws<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0InterruptedException {<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">MyThread\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">mythread<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0=\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: #ffffff; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">new<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0MyThread();<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">mythread<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.start();<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">mythread<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.interrupt();<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">System.<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #0000c0; background-color: #ffffff; font-weight: bold; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">out<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.println(<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #2a00ff; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">&#8220;Interrupted state after calling interrupt(): &#8220;<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">+\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">mythread<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.isInterrupted());<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">Thread.<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">sleep<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">(1000);<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">System.<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #0000c0; background-color: transparent; font-weight: bold; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">out<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.println(<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #2a00ff; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">&#8220;Interrupted state in 1 second: &#8220;<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0+\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">mythread<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.isInterrupted());<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">class<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0MyThread\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">extends<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0Thread {<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">void<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0run() {<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">try<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0{<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">Thread.<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">sleep<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">(3000);<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">catch<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0(InterruptedException\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">e<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">) {<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">System.<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #0000c0; background-color: transparent; font-weight: bold; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">out<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.println(<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #2a00ff; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">&#8220;Thread was interrupted&#8221;<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">);<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p><strong>The output will be:<\/strong><\/p>\n<p>Interrupted state after calling interrupt(): true<br \/>\nThread was interrupted<br \/>\nInterrupted state in 1 second: false<\/p>\n<p>If a thread is in the runnable state, the method interrupt() will just set interrupted status to true.<\/p>\n<h2>Runnable interface<\/h2>\n<p>One more way to create a thread is to implement the interface Runnable. The Thread class also implements this interface. Let&#8217;s look at the thread created by the implementation of the Runnable:<\/p>\n<p dir=\"ltr\" style=\"line-height: 1.2; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">class<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0RunnableExample {<\/span><br \/>\n<span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">static<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">void<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0main(String[]\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">args<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">)\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">throws<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0InterruptedException {<\/span><br \/>\n<span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">MyThread\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">mythread<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0=\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">new<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0MyThread();<\/span><br \/>\n<span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">Thread\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">thread<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0=\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">new<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0Thread(<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">mythread<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">);<\/span><br \/>\n<span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">thread<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.start();<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.2; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.2; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.2; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">class<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0MyThread\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">implements<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0Runnable {<\/span><br \/>\n<span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">void<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0run() {<\/span><br \/>\n<span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">System.<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #0000c0; background-color: transparent; font-weight: bold; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">out<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.println(<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #2a00ff; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">&#8220;The thread created by implementaion of the Runnable\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #2a00ff; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #2a00ff; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #2a00ff; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">interface&#8221;<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">);<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.2; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.2; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p>As you see, you need to use class Thread. We pass our class that implements the Runnable interface into its constructor. After we can call the method start() on it.<\/p>\n<p>The Thread class has the method getName(). Let&#8217;s try to apply it in our example:<\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; line-height: 1; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: #ffffff; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: #ffffff; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">class<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0ThreadExample {<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; line-height: 1; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: #ffffff; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: #ffffff; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">static<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: #ffffff; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">void<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0main(String[]\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">args<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">)\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: #ffffff; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">throws<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0InterruptedException {<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; line-height: 1; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">System.<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #0000c0; background-color: #ffffff; font-weight: bold; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">out<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.println(<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #2a00ff; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">&#8220;The Main thread name is &#8220;<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0+\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0 \u00a0 \u00a0 \u00a0Thread.<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">currentThread<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">().getName());<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; line-height: 1; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">MyThread\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">mythread<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0=\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: #ffffff; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">new<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0MyThread();<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; line-height: 1; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">Thread\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">thread<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0=\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: #ffffff; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">new<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0Thread(<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">mythread<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">);<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; line-height: 1; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">thread<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.start();<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; line-height: 1; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; line-height: 1; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; line-height: 1; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: #ffffff; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">class<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0MyThread\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: #ffffff; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">implements<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0Runnable {<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; line-height: 1; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: #ffffff; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: #ffffff; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">void<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0run() {<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; line-height: 1; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">System.<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #0000c0; background-color: #ffffff; font-weight: bold; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">out<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.println(<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #2a00ff; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">&#8220;We created the thread with name &#8220;<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0+ \u00a0 \u00a0 \u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">Thread.<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">currentThread<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">().getName());<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; line-height: 1; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; line-height: 1; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: #ffffff; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p><strong>The output will be:<\/strong><br \/>\n<em>The Main thread name is main<\/em><br \/>\n<em> We created the thread with name Thread-0<\/em><\/p>\n<p>This means that we have created our thread successfully.<br \/>\nThere is also a possibility to set a name to your thread. For this, you can use the method setName().<br \/>\nThe threads have priorities. You can get the priority of your thread by calling method getPriority(). Here is a simple example:<\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">class<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0ThreadExample {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">static<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">void<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0main(String[]\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">args<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">)\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">throws<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0InterruptedException {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">System.<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #0000c0; background-color: transparent; font-weight: bold; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">out<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.println(<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #2a00ff; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">&#8220;The current thread priority is &#8220;<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0+\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0 \u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">Thread.<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">currentThread<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">().getPriority());<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p><strong>The output will be:<\/strong><\/p>\n<p><em>The current thread priority is 5<\/em><\/p>\n<p>This is because, by default, all threads have priority 5. You can change this value by using the method setPriority().<br \/>\nThe class Thread has the method join(). It allows one thread to wait until another thread completes its execution.<br \/>\nLet&#8217;s declare thread that prints its name every half second.<\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">class<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0MyThread\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">implements<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0Runnable {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">void<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0run() {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">for<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0(<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">int<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">i<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0= 0;\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">i<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0&lt; 2;\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">i<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">++) {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">try<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0{<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">Thread.<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">sleep<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">(500);<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">catch<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0(InterruptedException\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">e<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">) {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">e<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.printStackTrace();<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">System.<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #0000c0; background-color: transparent; font-weight: bold; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">out<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.println(<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #2a00ff; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">&#8220;The thread &#8220;<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0+ Thread.<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">currentThread<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">().getName()+\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #2a00ff; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">&#8221; is running&#8221;<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">);<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p>Now we will create two instances of this thread and run them. Here is the example without the join() method:<\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">class<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0ThreadsExample {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">static<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">void<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0main(String[]\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">args<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">)\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">throws<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0InterruptedException {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">Thread\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">thread1<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0=\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">new<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0Thread(<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">new<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0MyThread());<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">Thread\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">thread2<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0=\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">new<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0Thread(<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">new<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0MyThread());<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">thread1<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.start();<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">thread2<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.start();<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p><strong>The output:<\/strong><\/p>\n<p><em>The thread Thread-1 is running<\/em><br \/>\n<em> The thread Thread-0 is running<\/em><br \/>\n<em> The thread Thread-1 is running<\/em><br \/>\n<em> The thread Thread-0 is running<\/em><\/p>\n<p>As you see, two threads run concurrently. Let&#8217;s ask one of the threads to wait while another one will finish his work:<\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">class<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0ThreadsExample {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">static<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">void<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0main(String[]\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">args<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">)\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">throws<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0InterruptedException {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">Thread\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">thread1<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0=\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">new<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0Thread(<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">new<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0MyThread());<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">Thread\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">thread2<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0=\u00a0<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">new<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0Thread(<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #7f0055; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">new<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0MyThread());<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">thread1<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.start();<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">thread1<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.join();<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #6a3e3e; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">thread2<\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">.start();<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 10pt; font-family: Consolas,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p><strong>The output:<\/strong><br \/>\n<em>The thread Thread-0 is running<\/em><br \/>\n<em> The thread Thread-0 is running<\/em><br \/>\n<em> The thread Thread-1 is running<\/em><br \/>\n<em> The thread Thread-1 is running<\/em><\/p>\n<p>Now, the Thread-1 started to run just after Thread-0 was completed. The method join() has overridden versions. They allow waiting for the completion of another thread just a limited period of time.<br \/>\nThe class Thread has also method is Alive() that returns true if a thread is just created or already running.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Since JDK 1.0 Java language provides built-in support for multithreaded programming. Multithreading is an essential feature in the Java platform. Every application has at least one thread. It is called the main thread. This thread can create more threads. In Java language, each thread is associated with an instance of the class Thread. You can [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2407,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[42],"tags":[58,457,456],"class_list":["post-2290","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java-tutorials","tag-java","tag-runnables","tag-threads"],"_links":{"self":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/2290","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/comments?post=2290"}],"version-history":[{"count":0,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/2290\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media\/2407"}],"wp:attachment":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media?parent=2290"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/categories?post=2290"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/tags?post=2290"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}