Java Concurrency 101: Understanding Multithreading Fundamentals

The Java Trail
13 min readSep 22, 2023

Imagine you’re using your favorite code editor on a computer with a single processor. When you make changes to a code file and click “save,” a series of actions is triggered, ultimately writing data to the computer’s hard drive.

Now, here’s the catch: this writing process, known as I/O (Input/Output), can be quite slow, and during this time, the computer’s CPU (the brain of the computer) is basically waiting and not doing anything productive.

Instead of letting the CPU sit idle while waiting for I/O to finish, we can use threads. In this case, one thread is responsible for handling I/O, and another thread takes care of the user interface (UI)

So, when you click somewhere else on the screen while the I/O thread is busy, the CPU can switch to the UI thread, ensuring that your code editor remains responsive and doesn’t appear frozen or unresponsive to your actions. This way, your computer can multitask efficiently, even with a single processor.

Program, Process & Thread

Program:

  • Programs can be things like applications, software, or scripts.
  • To actually use a program, your computer’s operating system takes these instructions and data and creates something called a

--

--

The Java Trail

Scalable Distributed System, Backend Performance Optimization, Java Enthusiast. (mazumder.dip.auvi@gmail.com Or, +8801741240520)