DEV Community

Er. Bhupendra
Er. Bhupendra

Posted on

ALL QUESTIONS RELATED TO THREAD

Java Thread Interview Questions (83–138) – Easy Answer Table

No Question Best Short Answer
83 What is Process? A process is an independent program in execution having its own memory space.
84 What is Thread in Java? A thread is a lightweight sub-process used for concurrent execution inside a program.
85 Process vs Thread Process has separate memory; threads share same memory inside a process.
86 What is Multitasking? Running multiple tasks simultaneously using CPU scheduling.
87 Types of Multitasking Process-based multitasking and Thread-based multitasking.
88 Benefits of Multithreading Improves performance, CPU utilization, responsiveness, and resource sharing.
89 Explain Thread in Java A thread is the smallest unit of execution that runs independently inside a process.
90 Java API that supports threads java.lang.Thread and java.lang.Runnable.
91 Main Thread The main thread is the first thread created when a Java program starts.
92 Ways to create thread Two ways: Extend Thread class or implement Runnable interface.
93 Creating thread using Runnable Implement Runnable and override run() then pass object to Thread.
94 Creating thread using Thread class Extend Thread class and override run() method.
95 Best approach for creating thread Runnable interface because Java supports single inheritance.
96 Thread Scheduler JVM component that decides which thread executes next.
97 Thread Life Cycle New → Runnable → Running → Waiting/Blocked → Dead.
98 Restart dead thread No, once a thread is dead it cannot be restarted.
99 Can one thread block another? Yes, when threads compete for the same resource or lock.
100 Restart already started thread No, calling start() again throws IllegalThreadStateException.
101 If run() not overridden Thread will execute empty run() from Thread class.
102 Overload run() method Yes possible, but JVM only calls run() with no parameters.
105 What is Lock Lock controls access of multiple threads to shared resources.
106 Ways to do synchronization Synchronized method, synchronized block, static synchronization.
107 Synchronized method A method declared with synchronized allowing one thread at a time.
108 When to use synchronized When multiple threads access shared data.
109 Can other threads execute synchronized methods simultaneously No, only one thread can access synchronized method of same object.
110 Same thread accessing other synchronized methods Yes, same thread can access multiple synchronized methods of same object.
111 Synchronized block Used to synchronize specific code block instead of entire method.
112 Advantages of synchronized block Improves performance by locking only required code.
113 Class level lock Lock applied on class object using static synchronized methods.
114 Synchronize static methods Yes, using static synchronized.
115 Synchronized block for primitives No, lock requires object reference not primitive.
116 Thread priorities Priority decides execution preference of threads.
117 Types of priorities MIN_PRIORITY(1), NORM_PRIORITY(5), MAX_PRIORITY(10).
118 Change thread priority Using setPriority() method.
119 Same priority threads Execution decided by thread scheduler (time slicing).
120 Methods to prevent thread execution sleep(), wait(), join(), yield().
121 yield() method Temporarily pauses current thread giving chance to others.
122 Yield thread execution again Yes, scheduler may schedule it again.
123 join() method Makes one thread wait until another thread completes.
124 sleep() method Pauses thread execution for specified time.
125 sleep() and lock sleep() does NOT release the lock.
126 sleep() affect other threads No, it only pauses current thread.
127 interrupt() method Used to interrupt a sleeping or waiting thread.
128 Interthread communication Communication between threads using wait(), notify(), notifyAll().
129 wait(), notify(), notifyAll() Used for coordination between threads.
130 Why in Object class Because every object can be used as monitor for synchronization.
131 IllegalMonitorStateException Occurs when wait/notify called without owning the object's lock.
132 wait() lock behavior wait() releases the lock.
133 Methods releasing lock Only wait() releases lock.
134 Thread groups Group of threads managed together.
135 ThreadLocal variables Variables local to each thread.
136 Daemon thread Background thread supporting main program (e.g., Garbage Collector).
137 Make thread daemon Using setDaemon(true) before start().
138 Main thread daemon No, main thread cannot be daemon.

⭐ Most Important Interview Differences

Topic Key Point
sleep vs wait sleep() → Thread class, no lock release
wait() → Object class, releases lock
Runnable vs Thread Runnable preferred because supports multiple inheritance
Process vs Thread Process separate memory, thread shared memory
start() vs run() start() creates new thread, run() normal method call

🔥 Memory Trick to Remember Entire Thread Topic

Remember this sequence:

Basic
Creation
Lifecycle
Synchronization
Scheduling
Communication
Advanced
Enter fullscreen mode Exit fullscreen mode

Shortcut:

B C L S S C A
Enter fullscreen mode Exit fullscreen mode

💡 Interview Tip

If interviewer asks anything about threads, answer using this 3-step template:

Definition
Example
Important point
Enter fullscreen mode Exit fullscreen mode

Example:

Synchronization is a mechanism to control multiple threads
accessing shared resources to avoid race conditions.
Enter fullscreen mode Exit fullscreen mode

Top comments (0)