Thread Thread can be called lightweight process. Synchronization was introduced to prevent such problems from happening.
This is how multithreading in Java works.
Also, when you create MyThread class object, Thread class constructor will also be invoked, as it is the super class, hence MyThread class object acts as Thread class object. Here is a simple java thread example showing how to extend Thread class.
Java runtime environment runs as a single process which contains different classes and programs as processes. When the thread throws an Exception or Error that is not being caught in the program. Multithreading refers to two or more threads executing concurrently in a single program.
You must specify the code for your thread inside run method. Java provides two ways to create a thread programmatically. Recommended For You 1 Comment on "Creating a thread: Extending thread vs implementing runnable" Notify of new replies to this comment - on Notify of new replies to this comment - off Notify of new replies to this comment - on Notify of new replies to this comment - off Subscribe.