Threads and Concurrency in Java

An dive into threads and concurrency in the context of Java

What is a Thread?

In the simplest meaning, a thread is a lightweight and independent path that is followed in the execution of a program.

Each Java program will contain at least one thread.

What is Concurrency?

As the definition allows, concurrency is the ability to run multiple programs or parts at the same time. 

What does this have to do with threads?

Concurrency is supported by threads. In Java, the existence of threads is what facilitates concurrent programming. Simply put, without threads there would be no concurrent programming.

The running of multiple threads at a time can be termed as concurrency.

Concurrency, however, does not mean that multiple processes are taking place at the same time, as that would be Parallel processing. It is not possible to run multiple processes in parallel without the use of multiple CPUs. 

The process of concurrency implies that within a period of time, multiple processes will make progress. Processed are progressed with a method of interleaving, which means that each process is processed for a small amount of time, before the progress is switched to another process and so on (Callicoder, 2017). 

Multithreading and Concurrency are not one and the same. Multithreading is a form of concurrency where multiple concurrent behaviours in the same process (Rogers, 2019).


Comments

Popular Posts