In this tutorial, we are going to see differences between process and thread in java.
If you are working on multithreading in java, it is good to know differences between process and thread. How multithreading can improve performance by executing code in parallel.
Process vs Thread:
The process can be referred as program in execution whereas thread is part of process.
Process has its own address space whereas multiple threads share same address space of process. Each thread has its own stack.
Process can have multiple threads but thread is the smallest unit which can execute concurrently with other threads.
Process are quite heavyweight and have more overhead whereas thread is light weight and have less overhead.
Process do not depend on each other whereas threads are not independent as they share address space.
You do not require synchronization in case of process. Threads require synchronization to avoid unexpected scenarios.
Processes can communicate to each other using inter-process communication only where as thread can communicate directly as thread share same address space.
You can easily create new threads by calling thread’s start method but you need to copy resources of parent process to create a new child process.
Was this post helpful?
Let us know if you liked the post. That’s the only way we can improve.
Table of ContentsGet Thread Id in JavaGet Thread Id of Current Running ThreadGet Thread id of Multiple Threads In this article, we will learn to get thread id of a running thread in Java. An Id is a unique positive number generated at the time of thread creation. This id remains unchanged during the lifetime […]
Table of ContentsWhat is BlockingQueueArrayBlockingQueueFeaturesConstructorsMethodsUsage ScenariosImplementation CodeSummary In this article, we will understand the Java concurrent queue, BlockingQueue. We will then go deep into it’s one of the implementation, ArrayBlockingQueue. What is BlockingQueue BlockingQueue interface was introduced in Java 5 under concurrent APIs and it represents a thread-safe queue in which elements can be added […]
Table of ContentsUsing Thread.sleepUsing TimeUnit.XXX.sleep methodUsing ScheduledExecutorServiceFrequently asked questions on Java wait secondsHow to wait for 5 seconds in java?How to wait for 1 seconds in java?How to pause for 5 seconds in java? In this post, we will see how to delay java program for few secs or wait for seconds for java program […]
Table of ContentsProblemSolution 1Print even and odd numbers using threads in java Solution 2: Using remainder In this post, we will see how to print even and odd numbers using threads in java. see also: How to print sequence using 3 threads in java Problem You are given two threads. You need to print odd […]
In this post, we will see why wait(), notify() And notifyAll() methods are in Object Class And Not in Thread Class. This is one of the most asked java multithreading interview questions. You might know that wait(), notify() And notifyAll() Methods are in Object class and do you know the reason for the same? Let’s […]
In this post, we will see how to create your own custom BlockingQueue. This is one of the most asked java interview questions. You need to implement your own BlockingQueue. This question helps interviewer to get your understanding of multithreading concepts. Here is simple implementation of BlockingQueue. We will use array to store elements in […]