Sign in

| Software Developer | Programming enthusiast | Loves DS and Algo | Passionate about Future | Writes Mostly tech stuff |

Get prepared for multi-threading interview questions.

Deadlock on a single lock

Understanding multithreading in any language is a bit tough as it involves many other concepts like thread-stack, heap, locking, synchronization, etc. Earlier I have tried and attempted to simplify the multithreading concepts with multiple articles.

If you haven't gone through those articles, here is one article to start with.

Multi-Threaded Application:

Now let’s start with one simple multi-threaded application. Let’s say there are two threads and and both are sharing a common object .

  1. reads the message when it is not empty otherwise it will wait for the to write the .
  2. On the other hand, writes the message…


Know your next interview question.

HashMap with Singly Linked List

I have seen a lot of interviewers asking for the internal working mechanism of the hashmap. If you know the complete internal working of one of the map implementations, it becomes easier for you to understand the other classes of the map interface.

So thru this article, we’ll see how the hashing is done and its complete working mechanism, how the , and operations work with the hashmap and their time complexities, and at the end, we’ll see why it should not be used in a multi-threading environment.

What is HashMap?

Basically, HashMap is one of the most popular Collection classes in…


Java synchronization guide for your next interview…

Photo by Max Duzij on Unsplash

Through this article we are going to discuss atomic variables in java, why and where are they used, and how synchronized, volatile and atomic are different. Okay, okay don’t get confused, I’ve already covered synchronization and volatile in detail.

But before going ahead, you should know Race Condition, Critical Section, and Context Switching between threads. I have already covered these concepts and their examples in detail in the below articles. You should go thru them to get a complete and clear understanding of these concepts. Anyway, after reading these articles you will realize multi-threading is not that difficult.

What Does Atomic mean?


Don’t misuse synchronized and volatile in your application.

Cache Coherence

I have seen many developers a bit confused when it comes to multi-threading. This is primarily because a lot of things happen in the background and many concepts are related to it. You should know Race Condition, Critical section, and Context Switching between threads. I have already covered these concepts and their examples in detail.

Process and Thread Context Switching, Do You Know the Difference?

Synchronization in Java: All You Need to Know

In this article, I’ll be covering two important keywords synchronized and volatile, and their proper usage. …


Know your next java interview question.

Most Frequently asked java multithreading interview questions.

Photo by Nico Nazaire on Unsplash

Multithreading is one of the core concepts in any programming language. Understanding concurrency and threading take some time and prepare yourself in a way to clear your multithreading interviews. If you follow this list, which contains the most frequently asked multithreading questions, you may take less time to prepare for the interviews.

Runnable is the core interface provided for representing multi-threaded tasks and implementing threads and Callable is an improvised version of Runnable. Callable was added in Java 1.5.

Just Two Statements:

1. The Callable interface is similar to Runnable, both are designed for classes whose instances are potentially executed by another thread.


One year of writing and lots of learning

Photo by Sharon McCutcheon on Unsplash

My Journey As A Technical Writer:

I have been writing on the medium since August last year. I have written almost 65+ articles covering a lot of technical areas that include Java Programming, DSA, SQL, GIT, Linux, Coding best practices, and my personal experiences as a Software Developer.

Most of my articles cover interview questions and how to answer them with different use cases. I have received a lot of feedback that these articles really helped many developers with their interviews. Sometimes I helped few developers with their mock interviews in my free time.

Some of my weekends I utilized for writing and answering interview questions…


A behavioral design pattern for Flexible Notification-Registration Interaction.

Observer design pattern architecture

In this article, we will see what is the intent of the Observer design pattern, what problems it solves, and its applicability.

Before we move to the technicality of this topic, let me give one of the most basic use cases of this design pattern. We mostly tend to subscribe to the Youtube channels that we love watching. So in this example, the channel is an example of a and the users subscribing to it are . Whenever there is an update on the channel all the subscribed users get notified.

The Intent of Observer Design Pattern Is To:

“Define a one-to-many dependency between objects so that…


A better way to handle synchronization than keyword.

Producer and Consumer image/author

We have already learned how to synchronize a shared resource using a keyword. Now in this article, we’ll see a better way to synchronize shared resource using .

For synchronization using the keyword, you may refer to this article: Synchronization in Java: All You Need to Know

Problems With Synchronized Keyword:

  • A thread can only acquire a lock on an object only once for the shared resources.
  • Once the thread completes the execution of the synchronized block, there is no mechanism by which the other threads will get the lock.
  • Let’s take a scenario and understand the issue with multiple threads…


Clear deadlock concept with an example.

This article is all about Deadlock, we’ll see a deadlock program and will find an approach to overcome the deadlock condition.

What Is a Deadlock?

Deadlock occurs when multiple threads need the same locks but obtain these locks in a different order. A Java multithreaded program may suffer from the deadlock condition because the keyword causes the executing thread to block while waiting for the lock associated with the specified object.

Deadlock is a condition where the threads are waiting infinitely for the resources(locks).

Now Let’s Write a Program and See What’s the Issue With This Program.

There are two threads in the program and two locks are created. Each thread needs both locks to execute…


Expect this question in your multi-threading interviews.

Producer-Consumer

I really love reading and exploring multi-threaded problems and share them with my friends and colleagues. I’m always in the favor of learning something until you understand it completely. Keeping that in mind, I’m writing this article for all those who are trying to understand and learn multi-threading. I have already written few articles on this topic that I will list at the bottom for your reference. In this article, we’ll understand one classical multi-threading problem.

A Small Background of Producer-Consumer Problem:

The Producer-Consumer Problem (sometimes called the Bounded-Buffer Problem) is a classic example of a multi-threaded synchronization problem.

The problem describes two threads, the Producer…

Vikram Gupta

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store