From the course: Java Threads
Unlock the full course today
Join today to access over 24,400 courses taught by industry experts.
Extend a thread or implement a Runnable? - Java Tutorial
From the course: Java Threads
Extend a thread or implement a Runnable?
- [Instructor] The two ways to create a thread in Java each have advantages and disadvantages. The first way that is extending the class that you want to run as a separate thread by the java.lang.Thread class is a convenient way. This is because you just have to override the run method in your class to implement the running behavior of your thread. And then, instantiate your class without having to pass a runnable instance to its constructive when creating a new thread object. The second way is not much different, since you implement the runnable interface and override the run method to implement the running behavior. The difference here is having to instant your runnable class first, and then creating a thread instance passing in that runnable instance to its constructor. If you use the first way, you have to keep in mind that your class will not be able to extend any other classes since Java does not allow…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Thread class and Runnable interface2m 17s
-
(Locked)
Creating a thread: Extending the Thread class4m 4s
-
(Locked)
Creating a thread: Implementing the Runnable interface3m 31s
-
(Locked)
Starting a thread7m
-
(Locked)
Extend a thread or implement a Runnable?2m 27s
-
(Locked)
Challenge: Webinar polling system3m 25s
-
(Locked)
Solution: Webinar polling system3m 33s
-
-
-