0

What is multi treading in java ? What are the types and why it is used for? Please Explain briefly.

Java

7th Feb 2020, 5:41 PM
Sakshi Shripanavar
5 Answers
+ 3
When you think about large computer networks, it is possible to break down a difficult mathematical problem into smaller computations that can be run paralel on many computers. This is how distibuted computings works, by sharing the workload across machines, and threading helps controlling this process. https://code.sololearn.com/cjyUokHC6ADh/?ref=app
7th Feb 2020, 9:07 PM
Tibor Santa
Tibor Santa - avatar
+ 2
(part 1) A process can be considered as a procedure that is written to complete a particular task. A thread is known as a light weight process which can also be considered as subdivisions of a process. For eg- if there is an organisation that is working towards developing an app for their client then it is a process. All the employees can be considered as threads who are working together to help the organisation reach the goal. Hope you got what threads are.
7th Feb 2020, 6:19 PM
Avinesh
Avinesh - avatar
+ 2
(part 2) Multi threading means running multiple threads concurrently. That being said, understand that if you take a snap of the inside of a system you would realize that at any given time, there is only one process that is running but the switching is so fast that we feel like there are so many processes running together. You can relate that to multi processing. So similarly there is only one thread running at a given time.
7th Feb 2020, 6:26 PM
Avinesh
Avinesh - avatar
+ 1
(part 3) In Java you can achieve multithreading by either extending the Thread class or implementing the Runnable interface and then you have to override the run() method. Then you need to create an object of the class and call the start() method to make separate thread run with the current thread which is nothing but your main thread.
7th Feb 2020, 6:33 PM
Avinesh
Avinesh - avatar
0
rxjava2
7th Feb 2020, 8:35 PM
Atamyrat Babayev
Atamyrat Babayev - avatar