Course contentsShow
← Java
Lesson 2554 of 2,87048. Concurrency FundamentalsFree lesson

Thread: A Lightweight Execution Unit

A thread is a path of execution within a process that shares the process's memory and resources.

Thread: A Lightweight Execution Unit

What you'll learn: You'll understand what a thread is and how it differs from a process in concurrent Java programming.


What Is a Thread?

A thread is a lightweight path of execution within a process. While a process is an independent program with its own memory space (as you learned previously), a thread exists inside a process and shares that process's memory and resources.

Think of it this way: if a process is a restaurant kitchen, threads are the individual chefs working in that kitchen. All chefs (threads) share the same kitchen space, ingredients, and equipment (memory and resources), but each can perform different cooking tasks simultaneously.

Key Characteristics of Threads

Shared Memory: Multiple threads within the same process can access the same variables, objects, and heap memory. This sharing makes communication between threads fast and efficient—no need to copy data between separate memory spaces.

Independent Execution: Despite sharing memory, each thread has its own execution path, program counter, and call stack. One thread might be reading a file while another processes user input, all within the same program.

Lightweight: Creating a thread is much faster and uses fewer resources than creating a new process. Threads don't require duplicating the entire process memory space.

Why Threads Matter

Threads enable your Java applications to perform multiple operations concurrently. A web server can handle many client requests simultaneously by assigning each request to a different thread. A desktop application can keep its user interface responsive while performing background calculations.

Key Takeaway: A thread is a lightweight execution unit within a process that shares the process's memory and resources while maintaining its own independent execution path and stack.