<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Java Interview Revision Question Bank - Medium]]></title>
        <description><![CDATA[Java Interview Revision Question Bank - Medium]]></description>
        <link>https://medium.com/java-interview-revision-question-bank?source=rss----550defa3f5c---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Java Interview Revision Question Bank - Medium</title>
            <link>https://medium.com/java-interview-revision-question-bank?source=rss----550defa3f5c---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 21:20:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/java-interview-revision-question-bank" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Everything about Java Multithreading]]></title>
            <link>https://medium.com/java-interview-revision-question-bank/everything-about-java-multithreading-be234f5ac119?source=rss----550defa3f5c---4</link>
            <guid isPermaLink="false">https://medium.com/p/be234f5ac119</guid>
            <category><![CDATA[java-interview]]></category>
            <category><![CDATA[multithreading-in-java]]></category>
            <dc:creator><![CDATA[Vivek Kumar Gupta]]></dc:creator>
            <pubDate>Tue, 04 Jul 2023 11:25:49 GMT</pubDate>
            <atom:updated>2023-06-04T13:53:11.345Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello Folks, as an IT professional we always think we should have some written notes which I can revise over the weekend or want to jump up and need some ready-made material to revise all the concepts in just 2–3 days. So, I am creating a series for that, and this is the multithreading part of that series.</p><p>Multithreading is one of the core concepts which always get asked in any of the interview or even in your day-to-day programmer life you will use it.</p><p>This page make you learn each and everything related to multithreading and can be referred by junior to senior to expert java professionals.</p><p>It’s a child page of</p><p><a href="https://medium.com/@cs.vivekgupta/java-full-stack-study-guide-1a459b68f48c">Java Full Stack Study Guide — Vivek Kumar Gupta — Medium</a></p><h3>Program, Process and Threads</h3><ul><li>When we execute a <strong>program</strong>, it is loaded into the Main Memory(RAM), by the Operating System(with the concept known <a href="https://en.wikipedia.org/wiki/Memory_paging">Paging</a>). The Operating System’s core called Kernel then creates the <strong>process</strong> which is the running instance of a program. <strong>In simple words, the process is just the runtime instance of our program.</strong></li><li>A <strong>thread</strong> is a small independent unit of execution inside a process. Multiple threads may exist within a process, running concurrently, having some local state associated with them. There may also be a global state in a process that all the threads share. Special care needs to be taken when multiple threads are writing and reading to and from this global state.</li><li>The word thread can mean two things:</li></ul><ol><li><strong>Kernel Space Threads:</strong> Threads that run in Kernel on behalf of User Space Threads: Ex: Device Driver Threads</li><li><strong>User Space Threads: </strong>Threads that run in a User Level Process. Ex: Java Threads</li></ol><ul><li><strong>How threading is related to Java?</strong> Well, Java is just alike another user-level process getting managed by the operating system and has the support of multithreading. In fact, every Java process (Java application) has a default thread named <strong><em>main. </em></strong>Other threads can be created from the main thread.</li></ul><pre>package learning.multithreading;<br><br>public class CurrentThread {<br><br>    public static void main(String[] args) {<br>        Thread currentThread = Thread.currentThread();<br>        System.out.println(&quot;Current Thread Name - &quot; + currentThread.getName());<br>        System.out.println(&quot;Current Thread Priority - &quot; + currentThread.getPriority());<br>        System.out.println(&quot;Current Thread Group - &quot; + currentThread.getThreadGroup());<br>        System.out.println(&quot;Current Thread Id - &quot; + currentThread.getId());<br>        System.out.println(&quot;Current Thread State - &quot; + currentThread.getState());<br>    }<br>}<br><br>/**<br> * Output<br> * Current Thread Name - main<br> * Current Thread Priority - 5<br> * Current Thread Group - java.lang.ThreadGroup[name=main,maxpri=10]<br> * Current Thread Id - 1<br> * Current Thread State - RUNNABLE<br> */</pre><ul><li>Native Thread Modelling: Java supports (From Java 1.3 version), Native Thread Modelling with the support of underlying OS especially Linux. Linux had provided support for the large concurrent execution of threads using the POSIX thread library. This library is the basis for JVM implementing the Native Thread Model and provides a one-to-one mapping between Java and Kernel threads.</li></ul><h3><strong>Ways to Create Threads</strong></h3><p>There are 2 ways to create threads in java —</p><ul><li><strong>Instantiating Thread class with Runnable class</strong></li></ul><pre>package learning.multithreading;<br><br>public class ThreadRunnable {<br><br>    public static void main(String[] args) {<br>        Runnable runnableTest = new RunnableTest();<br>        Thread runnableTestThread = new Thread(runnableTest);<br>        runnableTestThread.start();<br>    }<br>}<br><br>class RunnableTest implements Runnable {<br><br>    /**<br>     * When an object implementing interface {@code Runnable} is used<br>     * to create a thread, starting the thread causes the object&#39;s<br>     * {@code run} method to be called in that separately executing<br>     * thread.<br>     * &lt;p&gt;<br>     * The general contract of the method {@code run} is that it may<br>     * take any action whatsoever.<br>     *<br>     * @see Thread#run()<br>     */<br>    @Override<br>    public void run() {<br>        ThreadInformation.print(Thread.currentThread());<br>    }<br><br>    class ThreadInformation {<br>        public static void print(Thread thread) {<br>            System.out.println(&quot;Current Thread Name - &quot; + thread.getName());<br>            System.out.println(&quot;Current Thread Priority - &quot; + thread.getPriority());<br>            System.out.println(&quot;Current Thread Group - &quot; + thread.getThreadGroup());<br>            System.out.println(&quot;Current Thread Id - &quot; + thread.getId());<br>            System.out.println(&quot;Current Thread State - &quot; + thread.getState());<br>        }<br>    }<br>}<br><br>/**<br> * Output:<br> * Current Thread Name - Thread-0<br> * Current Thread Priority - 5<br> * Current Thread Group - java.lang.ThreadGroup[name=main,maxpri=10]<br> * Current Thread Id - 16<br> * Current Thread State - RUNNABLE<br> */<br><br>// Thread group is showing from where the child thread is created. <br>// In the above case its main.</pre><ul><li><strong>Subclassing Thread class</strong></li></ul><pre>package learning.multithreading;<br><br>public class ThreadSubclass {<br><br>    public static void main(String[] args) {<br>        Thread thread = new ThreadSubclassTest();<br>        <br>        // Shows initial state of thread<br>        ThreadSubclassTest.ThreadInformation.print(thread);<br><br>        thread.start();<br>    }<br>}<br><br>class ThreadSubclassTest extends Thread {<br><br>    public void run() {<br>        ThreadInformation.print(Thread.currentThread());<br>    }<br><br>    class ThreadInformation {<br>        public static void print(Thread thread) {<br>            System.out.println(&quot;Current Thread Name - &quot; + thread.getName());<br>            System.out.println(&quot;Current Thread Priority - &quot; + thread.getPriority());<br>            System.out.println(&quot;Current Thread Group - &quot; + thread.getThreadGroup());<br>            System.out.println(&quot;Current Thread Id - &quot; + thread.getId());<br>            System.out.println(&quot;Current Thread State - &quot; + thread.getState());<br>        }<br>    }<br>}<br><br>/**<br> * Output:<br> * Current Thread Name - Thread-0<br> * Current Thread Priority - 5<br> * Current Thread Group - java.lang.ThreadGroup[name=main,maxpri=10]<br> * Current Thread Id - 16<br> * Current Thread State - NEW<br> * -----------------------------------------<br> * Current Thread Name - Thread-0<br> * Current Thread Priority - 5<br> * Current Thread Group - java.lang.ThreadGroup[name=main,maxpri=10]<br> * Current Thread Id - 16<br> * Current Thread State - RUNNABLE<br> */</pre><h3>Lifecycle of a Thread</h3><p>Below diagram shows the state of Threadin its lifecycle —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/0*jqpxMLpukjjr4g-9.jpg" /></figure><ol><li><strong>New Thread:</strong> When a new thread is created, it is in the new state. The thread has not yet started to run when the thread is in this state. When a thread lies in the new state, its code is yet to be run and hasn’t started to execute.</li><li><strong>Runnable State:</strong> A thread that is ready to run is moved to a runnable state. In this state, a thread might actually be running or it might be ready to run at any instant of time. It is the responsibility of the thread scheduler to give the thread, time to run. <br> A multi-threaded program allocates a fixed amount of time to each individual thread. Each and every thread runs for a short while and then pauses and relinquishes the CPU to another thread so that other threads can get a chance to run. When this happens, all such threads that are ready to run, waiting for the CPU and the currently running thread lie in a runnable state.</li><li><strong>Blocked/Waiting state:</strong> When a thread is temporarily inactive, then it’s in one of the following states — Blocked or Waiting</li><li><strong>Timed Waiting:</strong> A thread lies in a timed waiting state when it calls a method with a time-out parameter. A thread lies in this state until the timeout is completed or until a notification is received. For example, when a thread calls sleep or a conditional wait, it is moved to a timed waiting state.</li><li><strong>Terminated State:</strong> A thread terminates because of either of the following reasons:</li></ol><ul><li>Because it exits normally. This happens when the code of the thread has been entirely executed by the program.</li><li>Because there occurred some unusual erroneous event, like segmentation fault or an unhandled exception.</li></ul><h3>Stack and Frame in Threads</h3><p>Java Virtual Machine’s stack is private to a JVM thread. Every method call that happens in that thread will have an entry in its private stack. Now, what all can a JVM stack store.</p><p>Well, Java Virtual Machine specification says, a JVM stack stores frames. A frame can be thought of as a wrapper that is used to store local variables, operand stacks, a reference to the run-time constant pool, dispatch exceptions etc.</p><p>Now, the key point to be understood here is, JVM stacks only store the data that is local to that thread and no other thread has access to the other thread’s stack.</p><h3>priority, sleep(), join(), join(long millis), yield()</h3><ul><li>Each thread in Java has priority. Thread priorities are just the numbers from 1 to 10 (1: being the lowest and 10: The highest). The default is 5 if none is specified.</li></ul><pre>Thread thread1 = new Thread1();<br>thread1.setName(&quot;Thread-1&quot;);<br>thread1.setPriority(10);</pre><ul><li>A thread can only be started once. Starting a thread that is already started and completed results in IllegalThreadStateException</li><li>We cannot guarantee the order of how threads are interleaved. It all depends on the Thread Scheduler.</li><li>Once a thread is started, there is NO guarantee that it will keep executing till it’s completed. Within each thread, the execution happens in a predictable order. But the events of different threads can mix in unpredictable ways.</li><li>When a thread completes its run() method, the thread dies and the stack for that thread is removed from JVM’s memory.</li><li>Using the join() method, we can tell the current thread not to run until some other thread has finished. or We can also tell to wait for a specific amount of time using the other flavor of method — join(long milliseconds)</li><li>When we use plain join() the current thread’s state changes to WAITING. And using the join(long milliseconds), changes the current thread’s state to TIMED_WAITING.</li></ul><pre>package learning.multithreading;<br><br>public class ThreadLifecycle {<br><br>    public static void main(String[] args) {<br><br>        Runnable task = () -&gt; {<br>            try {<br>                Thread.sleep(1000);<br>            } catch (InterruptedException e) {<br>                throw new RuntimeException(e);<br>            }<br>            ThreadInformation.printThreadState(Thread.currentThread());<br>        };<br><br>        Thread t1 = new Thread(task, &quot;task-1&quot;);<br>        Thread t2 = new Thread(task, &quot;task-2&quot;);<br>        Thread t3 = new Thread(task, &quot;task-3&quot;);<br><br>        t1.start();<br>        t2.start();<br>        try {<br>            t1.join();<br>            t2.join();<br>        } catch (InterruptedException e) {<br>            throw new RuntimeException(e);<br>        }<br>        t3.start();<br>    }<br><br>    class ThreadInformation {<br>        public static void printThreadState(Thread thread) {<br>            System.out.printf(&quot;%s is on [%s] state %n&quot;, thread.getName(), thread.getState());<br>        }<br>    }<br>}<br><br>/**<br> * Output:<br> * task-2 is on [RUNNABLE] state<br> * task-1 is on [RUNNABLE] state<br> * task-3 is on [RUNNABLE] state<br> */<br><br>/**<br> * Syntax for Yield: Thread.yield();<br>/*</pre><ul><li>The call to yield() on the current thread is expected to put the currently running thread to runnable queue and pick up any other thread with the same priority and start executing it. However, this behavior is JVM-specific.</li><li>Unlike sleep(), join(), wait(), the method yield() won’t ever cause the current thread to go into BLOCKED, WAITING, TIMED_WAITING state. The thread will always go to RUNNABLE after yeild(). In fact, there is no change in the state of the Thread.</li></ul><h3>Synchronizing the Threads</h3><p>Let’s consider a program and what is the issue with it —</p><pre>package learning.multithreading;<br><br>public class SynchronizationIssue {<br><br>    public static void main(String[] args) throws InterruptedException {<br><br>        Counter counter = new Counter();<br><br>        Runnable task = () -&gt; {<br>            for (int i = 0; i &lt; 1000; i++) {<br>                counter.increment();<br>            }<br>        };<br><br>        Thread t1 = new Thread(task, &quot;task-1&quot;);<br>        Thread t2 = new Thread(task, &quot;task-2&quot;);<br>        Thread t3 = new Thread(task, &quot;task-3&quot;);<br><br>        t1.start();<br>        t2.start();<br>        t3.start();<br><br>        // wait for threads to complete<br>        t1.join();<br>        t2.join();<br>        t3.join();<br><br>        System.out.println(&quot;Value of Counter - &quot; + counter.get());<br>    }<br>}<br><br>class Counter {<br>    int counter = 1;<br><br>    public void increment() {<br>        ++counter;<br>    }<br><br>    public int get() {<br>        return counter;<br>    }<br>}<br><br>/**<br> * Outputs:<br> * -------------<br> * Value of Counter - 1771<br> * -------------<br> * Value of Counter - 1390<br> * -------------<br> * Value of Counter - 1478<br> * -------------<br> */</pre><p>Yuo might have noticed the output — it should be exactly 3000 but it is always less than 3000. Why it is so —</p><ol><li>In JVM, the order of the threads is not guaranteed. It all depends on JVM’s Thread Scheduler and that is the reason you are getting different output each time you run ablove program.</li><li>When there are two or more threads accessing the shared data(in this case is Counter), it may lead to inconsistent results because of the fact that these threads race on each other to execute a particular block of code. This leads to a race condition.</li></ol><p>Let’s see how — Our expectation from program vs Actual behavior -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/0*PDtcXIC-icME6-3A.png" /></figure><p>So, now you have fully understood the problem here. To overcome this problem we can approach to it in 2 ways —</p><ol><li>Somehow ask JVM to follow the sequence of execution or execution of a particular block without any interference. This can be achived via synchronized and ReentrantLock . synchronized can be used with methods and code blocks. It provides more flexibility with the block of code as we can deal with it at a finer granular level.</li></ol><pre>// At the method level<br>public synchronized void increment() {<br>    ++counter;<br>}<br><br>// or at the block level<br>public void increment() {<br>   synchronized(this){<br>     ++counter;<br>   }<br>}</pre><p>2. We maintain counter in such a way that even if someone tries to use it(read/update) it will give us consistent results. It can be achived via Atomic Classes which uses <strong><em>Compare-and-Swap</em> </strong>Constructs. We will discuss it later in this article.</p><p><strong>Now, let’s see how synchronization works internally —</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/0*83rLLVszZHigneEd.png" /></figure><p>The first thing to understand is that when the synchronized method or block gets executed, a lock is acquired. We generally say the lock is acquired on a resource. But what is that resource? In Java, that resource is always an Object — A Java Object.</p><blockquote><em>In many books and articles, this lock is called an </em><em>Intrinsic Lock, because the lock is acquired intrinsically without specifying (that the lock needs to be acquired). In the JVM vocabulary, it is called as the </em><em>Monitor. Every object in Java has a </em><em>monitor associated with it. In other words every </em><em>Object in Java has a lock associated with it.</em></blockquote><p>So now the question again is on which object the lock is acquired? There are two answers to this question.</p><p>First, if we are using synchronized <strong><em>method</em></strong>, the lock is always acquired on the object that is calling the synchronized method — this</p><p>Second, if we are using synchronized <strong><em>block</em></strong>, we have to specify the object on which the lock needs to be acquired.</p><p>When we say the lock is acquired, what it exactly means is that the thread takes ownership of the monitor associated with it.</p><blockquote>NOTE: In JVM Language, the lock is called as the Monitor. The most important thing is that Every object in Java has a Monitor associated with it. This monitor is also called as Mutual Exclusion Lock.</blockquote><blockquote>Apart from the monitor, every object also has a waitset associated with it. We will look at waitsets in little more detail when we look at wait, notify &amp; notifyall.</blockquote><blockquote>NOTE: Acquiring the lock is nothing but gaining the ownership of the monitor associated with the object. From bytecode, we can see its via monitorenter and monitorexit.</blockquote><p>Here in our example, we specified synchronized(this) { ++value; } , so the lock will be acquired on the object calling the method. But we can also specify our own object on which the lock is to be acquired as below.</p><pre>private final Object MY_OBJ = new Object();<br>public void increment() {<br>    synchronized (MY_OBJ) {<br>        ++value;<br>    }<br>}</pre><p>With the above case, the lock is acquired on the object referred byMY_OBJ.</p><p>There are three cases we need to understand on gaining ownership of the monitor.</p><ol><li><strong>Another thread already gained ownership of the monitor:</strong> If another thread already owns the monitor associated with shared object, the current thread waits until the object is unlocked, then tries again to gain the ownership. The thread is blocked and waiting for a monitor lock to enter a synchronized block or method. The thread is said to be in BLOCKED state until it gets the ownership of the monitor.</li><li><strong>Current thread already gained ownership of the monitor:</strong> If the current thread already owns the monitor associated with aherad obejct, it increments a counter in the monitor indicating the number of times this thread has entered the monitor. This feature is called the <strong><em>Reentrancy — The same thread reentering the monitor. </em></strong>So, the Intrinsic Lock is a reentrant Lock. We also have a class called ReentrantLock in java.util.concurrent.locks package that works the same way.</li><li><strong>No thread owns the monitor:</strong> If the monitor associated with sgared object is not owned by any thread, the current thread becomes the owner of the monitor, setting the entry count of this monitor to 1.</li></ol><p>The thread that executes monitorexit must be the owner of the monitor associated with the instance referenced by object. When the thread executes monitorexit it decrements the entry count of the monitor associated with object.</p><ol><li>If as a result, the value of the entry count is zero, the thread exits the monitor and is no longer its owner. Other threads that are blocking can now enter the monitor. Which thread can enter the monitor is in the hands of JVM now.</li><li>If <em>objectref</em> is null, <em>monitorexit</em> throws a NullPointerException.</li><li>If the thread that executes <em>monitorexit</em> is not the owner of the monitor associated with the instance referenced by <em>objectref</em>, <em>monitorexit</em> throws an IllegalMonitorStateException.</li><li>One or more monitorexit instructions may be used with a monitorenter instruction to implement a synchronized block.</li></ol><p>The monitorenter and monitorexit instructions are not used in the implementation of synchronized methods, although they can be used to provide equivalent locking semantics.</p><p>To summarize it —</p><ol><li>Every object in Java is a lock associated with it. This lock is also called an Intrinsic Lock or Monitor.</li><li>Acquiring the lock means gaining ownership of the monitor.</li><li>The thread entering into the synchronized block or synchronized method will try to gain ownership of the monitor of the object referred by objectref. For non-static synchronized methods this will always be the this object.</li><li>The Monitor or Lock or Intrinsic Lock is reentrant in nature, which means, a thread can acquire the lock that it has already acquired and it maintains the count of how many times the lock has been acquired by a specific thread.</li><li>The bytecode instructions betweenmonitorenter and monitorexit act as a guarded region (The critical section).</li><li>The monitorenter and monitorexit instructions are NOT used in the implementation of synchronized methods.</li></ol><p><strong>We have seen in the context of instance methods. Now we will see what happens with </strong><strong>static methods.</strong></p><blockquote><em>NOTE: The words </em><em>lock and </em><em>monitor are used interchangeably here. Both are the same in our context.</em></blockquote><p>With the static methods, the synchronization happens the same way except for the object on which the monitor is acquired. The lock/monitor is acquired on the class object.</p><p>When we use synchronized with the <em>instance</em> methods, the monitor is acquired on thethis object and when used with <em>static</em> methods the lock is acquired on the .class object.</p><p><em>With the synchronized block, it doesn’t really matter whether it is a static method or a non-static method. It all depends on which object we are using in </em><em>synchronized block statement. In our case we are using </em><em>Counter.class object just to demonstrate it is equal to using static synchronized method.</em></p><p>Let’s look at few scenarios via program —</p><pre>package learning.multithreading;<br><br>public class ThreadTest {<br><br>    // Static Synchronized method-1<br>    public static synchronized void staticSyncMethod1() {<br>        // Some Code<br>    }<br><br>    // Static Synchronized method-2<br>    public static synchronized void staticSyncMethod2() {<br>        // Some Code<br>    }<br><br>    // Non-Static Synchronized method-1<br>    public synchronized void nonStaticSyncMethod1() {<br>        // Some Code<br>    }<br><br>    // Non-Static Synchronized method-2<br>    public synchronized void nonStaticSyncMethod2() {<br>        // Some Code<br>    }<br><br>    // Instance Methods with No Synchronization<br>    public void instanceMethod1() {<br><br>    }<br><br>    public void instanceMethod2() {<br><br>    }<br><br>    // Non-Static Synchronized method-1<br>    public void syncBlockWithThisObject() {<br>        synchronized (this) {<br>            // do something<br>        }<br>    }<br><br>    // Non-Static Synchronized method-2<br>    public void syncBlockWithClassObject() {<br>        synchronized (ThreadTest.class) {<br>            // do something<br>        }<br>    }<br>}</pre><p>Now, assume that there are two threads: T1 and T2 executing simultaneously.</p><p><strong><em>Scenario #1 — Both the threads execute two non-synchronized methods:</em></strong></p><ul><li><strong>Context:</strong> T1 is executing instanceMethod1() and T2 is executing instanceMethod2()</li><li><strong>Question</strong>: Will these two threads be blocked on each other?</li><li><strong>Answer</strong>: No</li><li><strong>Reason</strong>: There is no use of synchronization on these two methods. So the threads won’t block on each other. If these methods mutate any <em>shared data</em> or in simple words <em>a common variable</em> we will have inconsistent results.</li></ul><p><strong><em>Scenario #2 — T1 &amp; T2 executing synchronized non-static methods:</em></strong></p><ul><li><strong>Context</strong>: While T1 is executing nonStaticSyncMethod1, T2 tries to execute nonStaticSyncMethod2</li><li><strong>Question</strong>: Will these two threads be blocked on each other?</li><li><strong>Answer</strong>: Yes</li><li><strong>Reason</strong>: T1 is executing the synchronized method, which means, it has already acquired the lock/monitor on the object this . So when T2 tries to execute the method nonStaticSyncMethod2 it also tries to acquire the lock on the this object. But it is already acquired by T1. So T2 will be in BLOCKED state until T1 releases the lock (In other words till T1 executes monitorexit statement).</li></ul><p><strong><em>Scenario #3 — T1 &amp; T2 executing static synchronized methods:</em></strong></p><ul><li><strong>Context</strong>: While T1 is executing staticSyncMethod1, T2 tries to execute staticSyncMethod2</li><li><strong>Question</strong>: Will these two threads be blocked on each other?</li><li><strong>Answer</strong>: Yes</li><li><strong>Reason</strong>: T1 is executing the synchronized static method, which means, it has already acquired the lock/monitor on the class object in our case ThreadBlockingDemo.class. So when T2 tries to execute the method staticSyncMethod2 it also tries to acquire the lock on the class object — ThreadBlockingDemo.class. But it is already acquired by T1. So T2 will be in BLOCKED state until T1 releases the lock (In other words till T1 executes monitorexit statement).</li></ul><p><strong><em>Scenario #4 — T1 static synchronized method &amp; T2 executing non-static synchronized method:</em></strong></p><ul><li><strong>Context</strong>: While T1 is executing staticSyncMethod1, T2 tries to execute nonStaticSyncMethod1</li><li><strong>Question</strong>: Will these two threads be blocked on each other?</li><li><strong>Answer</strong>: No</li><li><strong>Reason</strong>: T1 is executing the synchronized static method, which means, it has acquired the lock/monitor on the class object in our case ThreadBlockingDemo.class. Now T2 tries to execute the method nonStaticSyncMethod2 . So it tries to acquire the lock on the this object. Since there is no thread holding the lock on thethis object, T2 successfully acquires the lock and proceed with its job. But assume there is another thread, T3, executing either of the synchronized methods, it will be blocked because both the objects’ locks: the this and the ThreadBlockingDemo.class already acquired by T2 &amp; T1 respectively.</li></ul><p><strong><em>Scenario #5 — T1 is executing non-static synchronized method and T2 — the method with synchronized block with “this” object.</em></strong></p><ul><li><strong>Context</strong>: While T1 is executing nonStaticSyncMethod1, T2 tries to execute syncBlockWithThisObject</li><li><strong>Question</strong>: Will these two threads be blocked on each other?</li><li><strong>Answer</strong>: Yes</li><li><strong>Reason</strong>: T1 is executing the synchronized method, which means, it has already acquired the lock/monitor on the this object. So when T2 tries to execute the method syncBlockWithThisObject as soon as it enters the synchronized block, it tries to acquire the lock on the this object because that is what is specified in the synchronized block statement. But the lock on this object has already been acquired by T1. So T2 will be in BLOCKED state until T1 releases the lock. But if T2 had tried to execute the method syncBlockWithClassObject it would not have been blocked because the lock on class object had not been acquired by any other thread.</li></ul><p><strong><em>Scenario #5 — T1 is executing static synchronized method and T2 — the method with synchronized block with “ThreadBlockingDemo.class” object.</em></strong></p><ul><li><strong>Context</strong>: While T1 is executing staticSyncMethod1, T2 tries to execute syncBlockWithClassObject</li><li><strong>Question</strong>: Will these two threads be blocked on each other?</li><li><strong>Answer</strong>: Yes</li><li><strong>Reason</strong>: T1 is executing the static synchronized method, which means, it has already acquired the lock/monitor on the ThreadBlockingDemo.class object. So when T2 tries to execute the method syncBlockWithClassObject, as soon as it enters the synchronized block, it tries to acquire the lock on the ThreadBlockingDemo.class object because that is what is specified in the synchronized block statement. But the lock on ThreadBlockingDemo.class object has already been acquired by T1. So T2 will be in BLOCKED state until T1 releases the lock. But if T2 had tried to execute the method syncBlockWithThisObject it would not have been blocked because the lock on this object had not been acquired by any other thread.</li></ul><p>Note: A thread cannot block on itself. What does this mean is, if we have two synchronized methods say M1 and M2, and M1 is calling M2; then if a thread, T1, calls M1 will acquire a lock on the object that is calling this method, and when it calls M2 from M1, the monitor count is increased to 2 saying that the same thread acquired the lock twice. When the thread returns to M1 after completing M2, it will reduce the monitor count to 1.</p><h3>Interthread Communication — wait, notify, notifyall</h3><p>we will see how can threads voluntarily leave the monitor and go into the WAITING state and resume — wait(), notify() &amp; notifyall().</p><p><strong>Purpose of </strong><strong>wait and </strong><strong>notify</strong>: A common pattern in multi-threaded programming is to have some kind of communication between the threads. So the wait and notify are more of a communication mechanism. This mechanism allows one thread to communicate to another that a particular condition or event has occurred. And the wait &amp; notify mechanism won’t tell us what is that particular condition/event. That is where the Shared Object comes into the picture.</p><p>The most important thing to remember is that, the wait &amp; notify mechanism doesn’t replace the behavior ofsynchronized keyword as it cannot alone solve the race condition problem that the synchronized solves. In fact, the wait &amp; notify mechanism must be used in conjunction with the synchronized to prevent a race condition.</p><blockquote><em>The wait &amp; notify mechanism must be used in conjunction with synchronized.</em></blockquote><p>To understand the wait &amp; notify let&#39;s look at a single producer and a single consumer problem — which is simply known as the <strong><em>producer-consumer</em></strong> problem.</p><p>The producer-consumer problem is very simple. It can be better understood with a real-world example.</p><h3>Producer-Consumer Real World Scenario:</h3><ol><li>Imagine you went to a restaurant and order multiple food items: item-1, item-2, item-3, and etc.</li><li>Now while the food items are being cooked you will be given a plate that is empty and you wait until the food items come onto your plate.</li><li>When the first set of food items are served onto the plate you start eating them. While you are at eating the serving staff will wait for the plate to be empty (partially or fully). And when you complete(means the plate is again empty), you will again wait for the next set of food items.</li><li>The above scenario is the typical producer and consumer pattern.</li><li>The serving staff that serves the food is the producer, you are the consumer and the plate is the shared resource that is getting used by serving staff for producing the food items and by you for consuming the food items.</li></ol><p>The following figure depicts this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/0*8OR2fTwtg3G-wcOI.png" /></figure><p>Producer and Consumer</p><p>In the programming world, the shared object can be any data structure: usually, it is a circular queue(Ring Buffer) implemented either with an array or a linked list. In our case, we implemented the shared object as an array. In our simple application, we have three entities: Producer, Consumer, and Shared Object.</p><p><strong>Producer: </strong>The thread that puts elements into the array. If the array is full (the plate is full) it waits for the consumer thread to consume until some space is left for the producer to produce the elements.</p><p><strong>Consumer: </strong>The thread that takes the elements from the array. If the array is empty, the consumer thread waits for the producer to produce some elements.</p><p><strong>Shared Object:</strong> The data structure that holds the data and is used by both producer and consumer. The shared object in our case is of fixed size. These kinds of data structures that are limited by size are called <strong><em>Bounded Data Structures</em></strong> or <strong><em>Bound Queues</em></strong>. We look at some of the bounded queues in later parts.</p><p>The following java programs demonstrate the behavior of these entities.</p><pre>package learning.multithreading;<br><br>import java.util.ArrayList;<br>import java.util.List;<br><br>public class ProducerConsumerProblem {<br><br>    /**<br>     * change the size to 1, if you want to produce only when your plate is fully empty.<br>     */<br>    private static final SharedQueue&lt;Integer&gt; sharedQueue = new SharedQueue&lt;&gt;(10);<br><br>    public static void main(String[] args) throws InterruptedException {<br><br>        Runnable producerTask = () -&gt; {<br>            int i = 0;<br>            while (true) {<br>                try {<br>                    sharedQueue.produce(++i);<br>                    // Adjust it, if you want producer and consumer on different pace<br>                    Thread.sleep(1000);<br>                } catch (InterruptedException e) {<br>                    throw new RuntimeException(e);<br>                }<br>            }<br>        };<br><br>        Runnable consumerTask = () -&gt; {<br>            while (true) {<br>                try {<br>                    sharedQueue.consume();<br>                    // Adjust it, if you want producer and consumer on different pace<br>                    Thread.sleep(1000);<br>                } catch (InterruptedException e) {<br>                    throw new RuntimeException(e);<br>                }<br>            }<br>        };<br><br>        Thread pThread = new Thread(producerTask, &quot;Producer&quot;);<br>        Thread cThread = new Thread(consumerTask, &quot;Consumer&quot;);<br><br>        pThread.start();<br>        cThread.start();<br><br>        pThread.join();<br>        cThread.join();<br>    }<br>}<br><br>class SharedQueue&lt;T&gt; {<br><br>    private final int MAX_BUFFER_SIZE;<br>    private final List&lt;T&gt; buffer;<br><br>    SharedQueue() {<br>        this(10);<br>    }<br><br>    SharedQueue(int size) {<br>        MAX_BUFFER_SIZE = size;<br>        buffer = new ArrayList&lt;&gt;(MAX_BUFFER_SIZE);<br>    }<br><br>    /**<br>     * blocks if the list size is MAX_BUFFER_SIZE meaning there is NO extra slot to put the element.<br>     *<br>     * @param t<br>     * @throws InterruptedException<br>     */<br>    public synchronized void produce(T t) throws InterruptedException {<br>        if (buffer.size() == MAX_BUFFER_SIZE) {<br>            System.out.println(Thread.currentThread().getName() + &quot; BUFFER IS FULL. Going into Wait State!&quot;);<br>            wait();<br>        }<br>        buffer.add(t);<br>        System.out.println(Thread.currentThread().getName() + &quot; Produced Element: &quot; + t);<br><br>        notify();<br>    }<br><br>    /**<br>     * blocks if the list size is 0 meaning there is no element to consume.<br>     *<br>     * @return T<br>     * @throws InterruptedException<br>     */<br>    public synchronized T consume() throws InterruptedException {<br>        if (buffer.size() == 0) {<br>            System.out.println(Thread.currentThread().getName() + &quot; BUFFER IS EMPTY. Going into Wait State!&quot;);<br>            wait();<br>        }<br><br>        T t = buffer.remove(0);<br><br>        System.out.println(Thread.currentThread().getName() + &quot; Consumed Element: &quot; + t);<br>        notify();<br>        return t;<br>    }<br>}</pre><p>Let’s now understand what exactly happens when we call wait &amp; notify.</p><p>You might have observed that wait and notify are called without using any object reference in SharedQueue class. That means it is equivalent to this.wait() and this.notify() . Here the objectthis is nothing but our SharedQueue object because that is what participated in the method invocation.</p><p>Now we know wait() and notify() are from SharedQueue object, this may raise another question that we haven’t defined any such methods in SharedQueue class, but where are they coming from then? Well, these are coming from Object class — The super class of every class that we define in Java. Of course, everyone knows this. If you are not sure, look at the java/lang/Object.java file in JDK source code and you can find wait, notify, and notifyAll being the Native methods. But why am I mentioning all this is to avoid the confusion about wait and notify. There are a couple of important points that I want to mention. Please read them thoroughly as these are very very important and no other book mentions them:</p><ol><li>Apart from monitor(Otherwise known as Intrinsic Lock) every object in Java has a waitset associated with it. This is another object apart from the monitor. So now, things: amonitor and a waitset are what every object in Java has. You can think of monitor as a special object and waitset as a special data structure (maybe a set as the name suggests). These two(monitor and waitset) are solely maintained by JVM for every object in Java.</li><li><strong>When a thread calls </strong><strong>wait() on an object there are two things that happen: First, the thread that is calling the </strong><strong>wait method leaves the monitor that it acquired on that object. Second, the thread that calls the wait is added to the </strong><strong>waitset (of the object on which </strong><strong>wait is called).</strong></li><li>At this stage, the thread goes into the WAITING state, which means it now sits in the waitset. This is one scenario where a thread goes into WAITING state. The other scenario when a thread goes into WAITING state is when the other thread calls join() on this thread (If threadA calls anotherThread.join() then threadA goes into WAITING state).</li><li><strong>When a thread calls </strong><strong>notify(), the JVM looks at the </strong><strong>waitset associated with the object on which </strong><strong>notify is called and picks one of threads from that </strong><strong>waitset and adds it to the runnable queue. We cannot guarantee which thread will get picked up. It all depends upon JVM Thread Scheduler.</strong></li><li>Here, if there are multiple threads waiting in the waitset and we want to push all the threads into the runnable state then we call notifyAll() on that object. So notify() picks up a random thread and pushes it to runnable whereas nofityall() pushes all the threads to runnable. One thing to be noted here is that the job of notify() or notifyAll() is just to push the thread to the runnable queue only. Which thread first gets executed by the JVM(RUNNING state) is again unpredictable. It solely depends on the JVM Thread Scheduler. When the thread goes into RUNNING (or getting executed by JVM) it acquires the monitor again and continues from where it left off.</li></ol><p>So here in our case, we have only two threads Producer and Consumer that can be pushed into the waitset of SharedQueue object. The below diagram better illustrates all the flow of wait &amp; notify.</p><figure><img alt="monitors and waitsets — wait &amp; notify flow" src="https://cdn-images-1.medium.com/max/531/0*HBKkorL-8hAL9xW2.png" /><figcaption>monitors and waitsets — wait &amp; notify flow</figcaption></figure><h3>Interrupts</h3><p>An <em>interrupt</em> is an indication to a thread that it should stop what it is doing and do something else. It’s up to the programmer to decide exactly how a thread responds to an interrupt, but it is very common practice to make the thread stop.</p><p>But who interrupts the threads in the first place? Well, one thread interrupts the other. Because whether or not we use the threads in Java JVM creates one thread, the main thread, with which our program execution begins. So it is one thread that interrupts another thread by invoking the method interrupt() on the target thread object which is to be interrupted.</p><p>For the interrupt mechanism to work properly, the thread that is being interrupted must support the interruption. What do we mean by this? Suppose, we have two threads T1 and T2. T1 interrupts T2 by calling T2.interrupt() , then T2 must have some logic to support or handle this interrupt (since the T2 is the target thread). We call this logic the I<strong><em>nterrupt Handler</em></strong>. Then, how do threads implement these interrupt handlers? Well, this depends on what we want and what the thread is doing at the time of interrupt. But the common practice is to stop the thread that is being interrupted. There are two typical ways to handle the interrupts.</p><p>First, all the methods that throw InterruptedException such as: Thread.sleep(), Thread.join(), Object.wait() have the built-in interrupt handlers. All we need to do is to catch this InterruptedException and handle it in the catch block. So the exception handler (the try-catch block of InterruptedException) becomes the Interrupt Handler. As a general practice, the logic in the interrupt handler (the catch block) is written in such a way that it stops the thread itself. It is a common practice to stop the thread in InterruptHandler though it all depends on our use case. But the InterruptHandlers are the nicer way to stop the threads (gracefully without using Thread.stop() ). You all know that<em>Thread.stop() is not a recommended way of stopping the thread</em> (More on this later). The following better explains this behavior.</p><pre>package learning.multithreading;<br><br>public class StoppingThreadWithInterrupt extends Thread {<br>    public static void main(String[] args) throws InterruptedException {<br>        Thread t1 = new StoppingThreadWithInterrupt();<br>        t1.start();<br>        Thread.sleep(5000);<br>        t1.interrupt();<br>        Thread.sleep(1000);<br>        System.out.println(&quot;End of the thread: &quot; + Thread.currentThread().getName() + &quot;!&quot;);<br>    }<br><br>    public void run() {<br>        System.out.print(Thread.currentThread().getName() + &quot;: I am doing work &quot;);<br>        while (true) {<br>            System.out.print(&quot;. &quot;);<br>            try {<br>                Thread.sleep(1000);<br>            } catch (InterruptedException e) {<br>                System.out.println(&quot;\n&quot; + Thread.currentThread().getName() + &quot;: I have been Interrupted!!&quot;);<br>                break;<br>            }<br>        }<br>        System.out.println(&quot;End of the thread: &quot; + Thread.currentThread().getName() + &quot;!&quot;);<br>    }<br>}<br><br>/**<br> * Output:<br> * Thread-0: I am doing work . . . . .<br> * Thread-0: I have been Interrupted!!<br> * End of the thread: Thread-0!<br> * End of the thread: main!<br> */</pre><p>Let us dive deep into the above program. It represents the first way of handling the interrupts — <em>With the methods that throw </em>InterruptedException<em>. </em>We have already specified that these methods (sleep, join, wait and etc) have built-in interrupt handlers. So what is happening in the above program is, the main thread creates another thread t1 and starts it. And the main thread sleeps for 5 seconds. The thread t1 calls Thread.sleep() in a loop (t1 goes into TIMED_WAITING state for every second). Then the main thread interrupts the t1. When a thread calls Thread.sleep() or Thread.join() or Object.wait() it goes into eitherWAITING orTIMED_WAITING state. When a thread is in one of these states and Thread.interrupt() is invoked on that thread object, the built-in interrupt handler kicks in, does some stuff, and throws the InterruptedException which we have to catch. So in our program, when the main thread calls t1.interrupt() and t1 is in TIMED_WAITINGstate(since it is intermittently calling Thread.sleep()), the built-in interrupt handlers kicks in and raises the InterruptedException. The catch block, then breaks from the loop and completes the thread. This is what we mean by stopping the thread gracefully without calling Thread.stop(). In fact, we are not exactly stopping the thread but we are taking the thread to its completion. We missed a few important points here about the interrupts — The Interrupt Status Flag</p><h3>The Interrupt Status Flag</h3><p>The interrupt mechanism is implemented using an internal flag known as the <em>interrupt status</em>. When we invoke t1.interrupt(), it sets the interrupt status flag. This can be checked using t1.isInterrupted(). There is another static method Thread.interrupted() which also returns the boolean value stating whether the thread is interrupted or not. But the sole purpose of this static method is to clear the interrupt status flag.</p><p>People generally get confused between these two methods. So the <strong><em>instance</em></strong> method isInterrupted() is to check whether the interrupt status flag is set or not (In other words, to check whether a thread is interrupted or not) and the static method interrupted() is to clear the flag.</p><blockquote><em>Thread.isInterrupted() is an instance method to check whether the thread is interrupted or not.</em></blockquote><blockquote><em>Thread.interrupted() is a static method which when invoked clears the interrupt status flag of the current running thread.</em></blockquote><p>Now let’s have a look at the second way of handling the interrupts. What if we don’t call the methods that throw InterruptedException in our programs. Let us look at the below code.</p><pre>package learning.multithreading;<br><br>public class StoppingThreadWithInterrupt2 extends Thread {<br>    public static void main(String[] args) throws InterruptedException {<br>        Thread t1 = new StoppingThreadWithInterrupt2();<br>        t1.start();<br>        Thread.sleep(10);<br>        t1.interrupt();<br>        Thread.sleep(1000);<br>        System.out.println(&quot;End of the thread: &quot; + Thread.currentThread().getName() + &quot;!&quot;);<br>    }<br><br>    public void run() {<br>        System.out.print(Thread.currentThread().getName() + &quot;: I am doing work &quot;);<br>        while (!Thread.currentThread().isInterrupted()) {<br>            System.out.print(&quot;. &quot;);<br>        }<br>        System.out.println(Thread.currentThread().getName() + &quot;: I have been interrupted!!&quot;);<br>        System.out.println(&quot;End of the thread: &quot; + Thread.currentThread().getName() + &quot;!&quot;);<br>    }<br>}<br><br>/**<br> * Output:<br> * Thread-0: I am doing work . . . . Thread-0: I have been interrupted!!<br> * End of the thread: Thread-0!<br> * End of the thread: main!<br> */</pre><p>The main change that you can observe between the above program and the previous one is, we just removed Thread.sleep(), the try-catch around it and the condition of the while loop checking whether the thread is interrupted or not.</p><p>Why can’t we use the same condition !Thread.currentThread.isInterrupted() and remove the break statement in the catch block. We can definitely use it. But there is a catch. Let’s try and modify the program and run it to understand it better.</p><pre>package learning.multithreading;<br><br>public class StoppingThreadWithInterrupt3 extends Thread {<br>    public static void main(String[] args) throws InterruptedException {<br>        Thread t1 = new StoppingThreadWithInterrupt3();<br>        t1.start();<br>        Thread.sleep(5000);<br>        t1.interrupt();<br>        Thread.sleep(1000);<br>        System.out.println(&quot;End of the thread: &quot; + Thread.currentThread().getName() + &quot;!&quot;);<br>    }<br><br>    public void run() {<br>        System.out.print(Thread.currentThread().getName() + &quot;: I am doing work &quot;);<br>        while (!Thread.currentThread().isInterrupted()) {<br>            System.out.print(&quot;. &quot;);<br>            try {<br>                Thread.sleep(1000);<br>            } catch (InterruptedException e) {<br>                System.out.println(&quot;\n&quot; + Thread.currentThread().getName() + &quot;: I have been Interrupted!!&quot;);<br>            }<br>        }<br>        System.out.println(Thread.currentThread().getName() + &quot;: I have been interrupted!!&quot;);<br>        System.out.println(&quot;End of the thread: &quot; + Thread.currentThread().getName() + &quot;!&quot;);<br>    }<br>}<br><br>/**<br> * Output:<br> * Thread-0: I am doing work . . . . .<br> * Thread-0: I have been Interrupted!!<br> * . . End of the thread: main!<br> * . . . . . . . . . . . . . . .<br> * . . . . . . . . . . . . . . .<br> */</pre><p>Run it in your system and check whether the thread program stops or not. The thing is, it(thread t1) won’t be complete. It runs infinitely. Why?</p><p>Well, the trick lies in built-in interrupt handlers — for all the methods that throw theInterruptedException. They clear the interrupt status flag.</p><blockquote><em>Very Important Note: The built-in interrupt handlers for the methods that throws </em><em>InterruptedException will clear the interrupt status flag. So by the time the control comes into the catch block of </em><em>InterruptedException the interrupt status flag will already have been cleared.</em></blockquote><p>So by the time the execution comes into the catch block, the interrupt status flag will already have been cleared. And the condition in the while loop will always be true. Because the isInterrupted() instance method just checks whether the flag is set or not.</p><p>So, what can be done here? Again, it depends on what we need and what our required behavior is. But in our case, we have two simple ways of fixing this.</p><ol><li>First, We can simply set the interrupt status flag by invoking interrupt() instance method like this; Thread.currentThread().interrupt() in the catch block(ideally as a first statement in the catch block), so that, when the control comes to while loop condition it checks that the thread is interrupted and comes out of the loop.</li><li>Second, we can just simply use thebreak statement as a final statement in the catch block so that it breaks the while loop and comes out.</li></ol><p>Either of the above two is fine. But I would upvote for the first approach. Because using break may not work if we nested loops as it only comes out of the inner loop. So the below program is the complete program and a very safer way to stop the thread using interrupts.</p><pre>package learning.multithreading;<br><br>public class StoppingThreadWithInterrupt4 extends Thread {<br>    public static void main(String[] args) throws InterruptedException {<br>        Thread t1 = new StoppingThreadWithInterrupt4();<br>        t1.start();<br>        Thread.sleep(5000);<br>        t1.interrupt();<br>        Thread.sleep(1000);<br>        System.out.println(&quot;End of the thread: &quot; + Thread.currentThread().getName() + &quot;!&quot;);<br>    }<br><br>    public void run() {<br>        System.out.print(Thread.currentThread().getName() + &quot;: I am doing work &quot;);<br>        while (!Thread.currentThread().isInterrupted()) {<br>            System.out.print(&quot;. &quot;);<br>            try {<br>                Thread.sleep(1000);<br>            } catch (InterruptedException e) {<br>                System.out.println(&quot;\n&quot; + Thread.currentThread().getName() + &quot; is Interrupted? &quot; + Thread.currentThread().isInterrupted());<br>                Thread.currentThread().interrupt(); // Sets the interrupt flag<br>                System.out.println(Thread.currentThread().getName() + &quot;: I have been Interrupted!!&quot;);<br>            }<br>        }<br>        System.out.println(Thread.currentThread().getName() + &quot;: I have been interrupted!!&quot;);<br>        System.out.println(&quot;End of the thread: &quot; + Thread.currentThread().getName() + &quot;!&quot;);<br>    }<br>}<br><br>/**<br> * Output:<br> * Thread-0: I am doing work . . . . .<br> * Thread-0 is Interrupted? false<br> * Thread-0: I have been Interrupted!!<br> * Thread-0: I have been interrupted!!<br> * End of the thread: Thread-0!<br> * End of the thread: main!<br> */</pre><p>So far we have seen two ways of handling interrupts: The one with the InterruptedException and other without it. But what if we don’t provide any interrupt handler? Well, in Java, there are NO default interrupt handlers. When a thread, say T1, interrupts another thread, say T2, and if T2 doesn’t provide the interrupt handler, then nothing happens. The interrupts will simply be ignored.</p><p>You can find the links to similar topics/material on it’s <a href="https://medium.com/@cs.vivekgupta/java-full-stack-study-guide-1a459b68f48c">parent </a>page.</p><p>Thanks for reading! Enjoy!</p><p>Please write in comments how you liked it and please feel free to provide the feedback.</p><p>Please provide in comments or response if you think I have missed few topics which is very important to cover.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be234f5ac119" width="1" height="1" alt=""><hr><p><a href="https://medium.com/java-interview-revision-question-bank/everything-about-java-multithreading-be234f5ac119">Everything about Java Multithreading</a> was originally published in <a href="https://medium.com/java-interview-revision-question-bank">Java Interview Revision Question Bank</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>