Working on multiple tasks at the same time is Multitasking. In the same way, multiple threads running at the same time in a machine is called Multi-Threading. Technically, a thread is a unit of a process. Multiple such threads combine to form a process. This means when a process is broken, the equivalent number of threads are available.
For example, Autocorrect is the process where the software looks for the mistakes in the current word being typed. Endlessly checking for the mistake and providing suggestions at the same time is an example of a Multi-Threaded process.
Sample Android App:
Let’s try to visualize Multi-Threading with the help of an Android App. In the below example, 3 Threads start at the same time on a button click and work concurrently.
Step 2: Add the below code in MainActivity. Here, three threads are made, each thread keeps updating the respective TextView every second (declared in the code) when the button is clicked. These Threads keep running until the button is clicked again (i.e.”Stop”).
Multi-Threading concept applies to a large number of day to day applications on various machines. However, there are drawbacks to the same. At the beginner level, one can only think of the load on the machine or increased complexity. But at a greater level, multiple scenarios such as complex testing, unpredictable results, deadlock, starvation, etc are expected.
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Deadlock in Java Multithreading
- What does start() function do in multithreading in Java?
- Java Thread Priority in Multithreading
- Multithreading in Java
- Difference between Multiprogramming, multitasking, multithreading and multiprocessing
- Benefits of Multithreading in Operating System
- Multithreading in Operating System
- Difference between Multiprocessing and Multithreading
- Android | AdMob Banner Ads for Android Studio
- Android | Android Application File Structure
- Android | AdMob Interstitial Ads for Android Studio
- Android | How to Create/Start a New Project in Android Studio?
- Android | Running your first Android app
- Android | How to add Radio Buttons in an Android Application?
- Android | How to Request permissions in Android Application?
- Difference between Android 1.1 and Android 4.0.1
- Difference between Android 1.1 and Android 2.3.4
- Difference between Android 1.0 and Android 1.1
- Difference between Android 1.0 and Android 7.1
- Difference between Android 1.0 and Android 2.3
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.