DEV Community

ChelseaLiu0822
ChelseaLiu0822

Posted on

[Java]Process and Thread

Process: is used to load instructions, manage memory, and manage IO, process can be seen as an instance of the program (program is static, process is dynamic), when a program is running, it will open a process.
Thread: a process can be divided into one to multiple threads, a thread is the instruction flow, and the instruction flow in a certain order to the CPU for execution.

  • In Java, the Thread is the smallest scheduling unit (execution instructions), and the process is the smallest unit of resource allocation (managed resources). In Windows, processes are not active, but only as a container of threads.

  • Processes are independent of each other, while threads exist within the process.

  • Processes have shared resources, such as memory space etc, for their internal threads.

  • Communication between the processes is more complex.

  • Process communication for the same computer is called IPC (inter-process communication).

  • Process communication between different computers, required through the network, and adherence to common protocols such as HTTP.

  • Thread communication is relatively simple because they share memory within processes, and an example is a common variable that multiple threads can access.

  • Threads are lighter, and the cost of thread context switching is generally lower than processes.

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay