Java: Beginner Guide to Multithreading
a thread...
Multithreading is a concept of applying multitasking in Java.
Java supports thread-based multitasking.
Java program can be divided into several threads and those threads can be executed in parallel to support multi-tasking.
Two ways to create a thread in Java:
1. By Implementing Runnable Interface
2. By extending the Thread class
Let's create a thread by implementing the "Runnable" interface:
Steps:
1. Implement Runnable Interface
2. Override the run() method, and put your code inside it.
3. Pass the instance of your class to the Thread class constructor.
4. Call the start() method to run your thread.
Let's create a thread by extending the "Thread" class:
Steps:
1. Extend your class with Thread class
2. Override the run() method, and put your code inside it.
3. Instantiate your class.
4. Call the start() method to run your thread.