From the course: Java EE: Concurrency and Multithreading

Unlock the full course today

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

Using the Thread class to create and run a thread

Using the Thread class to create and run a thread

From the course: Java EE: Concurrency and Multithreading

Start my 1-month free trial

Using the Thread class to create and run a thread

- [Instructor] Okay. Let's take a look at the basic APIs on the Java Standard Edition, first. So, we'll go with the Thread class. The Thread class is present in the java.lang package, and the Thread class will help you to start a thread and manage a thread in the application's run, so whenever you want to create a thread for your Java application, you will need to create an instance of this class in order to start and run an asynchronous task in your application. Now, the job of the thread is something that you will define for your own logic, so the Thread class has got a run method which will allow you to define that asynchronous job so that when you start the thread then that job is going to execute and then it is going to give you the output. So, the job is always defined under the run method. Now, there is some default implementation in the run method of the Thread class. We do not want that, so we'll have to create our own class which extends Thread and then create an instance of…

Contents