Tech Master Tutorials
Email Facebook Google LinkedIn Pinterest Twitter
Home Java Java 8 Java Interview Questions Java Programming

Multithreading

Processes and Threads, both are the basic unit of programming.

Process can be defined as a program in execution. Each process has a set of resources exclusively allocated to itself and sharing of the resources with other processes is costly.

And a thread is a light weight process. Threads are light weight because threads share the same resources – same data (program text, heap memory and files). Each thread has its own memory stack.

If we have multiple tasks at hand then we can create multiple processes for each task. But if these multiple tasks share the same resources then we can create multiple threads as threads are light weight and more performance efficient.


Threads can run in parallel on multiple cores of the processor. As today it is very common to have multiple cores in a computer system, threads can be quite helpful in terms of performance and resource utilization but as threads share the resources available to them it is also required to provide a synchronized access to the resource so that system may not become inconsistent.