In this video of code decode, you will learn Multithreading Interview Questions and Answers in Java which is important in Java Interview Questions and Answers
Udemy Course of Code Decode on Microservice k8s AWS CICD link:
https://openinapp.co/udemycourse
Course Description Video :
https://yt.openinapp.co/dmjvd
Multi threading Interview questions part 1
• Most Asked Multithreading Interview Q...
Q) Difference between t.start() and t.run()
In the case of t.start() a new Thread will be created which is responsible for the execution of run() method.
But in the case of t.run() no new Thread will be created and run() method will be executed just like a normal method by the main Thread.
In the above program if we are replacing t.start() with t.run() the following is the output. Entire output produced by only main Thread. So Its sequential output always. First child then main / parent
Q) How to make a user thread to a Daemon thread
make a user thread to Daemon by using setDaemon() method of thread class.
This method is used for making a user thread to Daemon thread or vice versa. For example if I have a user thread t then t.setDaemon(true) would make it Daemon thread. On the other hand if I have a Daemon thread td then by calling td.setDaemon(false) would make it normal thread(user thread/non-daemon thread).
public boolean isDaemon(): This method is used for checking the status of a thread. It returns true if the thread is Daemon else it returns false.
setDaemon() method can only be called before starting the thread. This method would throw IllegalThreadStateException if you call this method after Thread.start() method. (refer the example)
The main difference between Daemon thread and user threads is that the JVM does not wait for Daemon thread before exiting while it waits for user threads, it does not exit until unless all the user threads finish their execution.
Q) What are the tasks of start method
Register the Thread with thread scheduler. So you just tell what a child thread should do, when and how it will be scheduled will be handled by scheduler.
Call run method.
Q) What if we don’t override Run method?
Thread class Run method will be called and we won’t get any output.
It’s basically useless as you are saying, please create a thread for me and that thread will do nothing for us. So why did u create it ?
Q) Can we overload run method during multi threading?
How do we overload?
May be by passing parameters?
Yes you can but start () will call no arg run () only.
Q) Can we override start method of thread in multi threaded environment?
If you override start () in your custom class then no initializations will be done by thread class for you.
Q) What is Multi threading & how is it diff from multi tasking asked In java interview question and Answers
Multithreading is a specialized form of multitasking.
Process-based multitasking is executing several tasks simultaneously where each task is a separate independent process is Process-based multitasking .
For example, process based multitasking enables you to run the Java IDE at the same time that you are using a text editor or visiting a web site using chrome.
Thread-based multitasking is executing several tasks simultaneously where each task is a separate independent part of the same program (called Thread).
For instance,JUnit uses threads to run test cases in parallel. As an application, you can have computer games. You see objects in games like cars, motor bikes etc. They are just threads that run in the game application.
Thus, process-based multitasking deals with the “big picture,” and thread-based multitasking handles the details
----------------------------------------------------------------------------------------------------------------------------------------
Most Asked Core Java Interview Questions and Answers : • Core Java frequently asked Interview ...
Advance Java Interview Questions and Answers : • Advance Java Interview Questions
Java 8 Interview Questions and Answers : • Java 8 Interview Questions(New Features)
Hibernate Interview Questions and Answers : • Hibernate Interview Questions Java
Spring Boot Interview Questions and Answers : • Advance Java Interview Questions
Angular Playlist : • Angular Course Introduction || Angular 8
GIT : • GIT
-------------------------------------------------------------------------------------------------------------------------------------
Subscriber and Follow Code Decode
Subscriber Code Decode : https://www.youtube.com/c/CodeDecode?...
Linkedin : / codedecodeyoutube
Instagram : / codedecode25
#javainterviewquestions #multithreadinginterviewquestions #codedecode