This guide will help you understand the deadlock concept in Java. We will also take a look at ways to detect and avoid deadlock in Java using a few examples. What you will learn: – What is a deadlock in Java? – Deadlock example – How to detect a deadlock using an example. – Best … Continue reading “How to detect and avoid deadlock in Java with example”
This guide will help you understand the thread pool concept. In this tutorial, we will create a thread pool using the executor service and the thread pool executor. I will also show you how to create a single thread executor using executors class. What you will learn – What is the Executor Service? – Difference … Continue reading “ExecutorService in Java with Example”
In this article, we will take a look at what is the thread pool in java, and what it does?. We will also discuss how to create the thread pool using a few examples. You will learn – What is Thread Pool? – Which option is better – creating a new thread every time vs … Continue reading “Thread Pool in Java Example”
In this article, we discuss what is the race condition and critical section in Java, and how to prevent race condition using synchronized keyword using a few examples. You will learn: – What are Race Conditions and Critical Section? – How to prevent Race Conditions in Java? – What is synchronization in Java and how … Continue reading “Race Condition – Synchronized Java Example”
This guide will help you to understand Thread and its life cycle. We will create a few examples to create a thread using the Thread class and Runnable interface. You will learn – What is Thread in Java? – Thread Life Cycle. – How to create a thread using Thread class. – How to create … Continue reading “Java Thread Example – How To Create a Thread”
This guide will help you understand about ThreadLocal variable and how to create and access the ThreadLocal variable in Java. You will learn: – What is the ThreadLocal variable? – Why do you need the ThreadLocal variable? – How to create and access a ThreadLocal variable? Few more Concurrent related articles from Codedelay ConcurrentHashMap with … Continue reading “ThreadLocal variable in JAVA with Example”
Java 8 introduced many important features including lambdas, stream, etc. CompletableFuture is also one of the most important features added in Java 8 which is useful in asynchronous programming. If you are not aware of asynchronous programming, it is a form of parallel programming that allows a particular code block to run separately from the … Continue reading “CompletableFuture in Java with Example”
This guide will help you to understand the concept Concurrenthashmap in Java. Additionally, we will also take a look at Concurrenthashmap internal implementation and difference between Concurrenthashmap, HashMap, and HashTable. What you will Learn What is Concurrenthashmap in Java? Why is Concurrenthashmap is thread-safe? When do we need Concurrenthashmap over HashMap or HashTable? How do … Continue reading “Concurrenthashmap in Java with example”
The basic idea behind multithreading is simple.
Multithreading refers to two or more threads being executed apparently at the same time, within the same program.
Let’s take a look at Thread first.
A Thread is nothing a thread of execution.
Sometimes they are also called as light processes or execution contexts.
The benefits of using threads
Creating/terminating a thread is much more efficient than creating a process.
In addition to that, Inter-thread communication is much simpler and more efficient than inter-process communication.
In this series, we will take a look at java multithreading concepts.