Many programmers don't know how to use multithreading correctly, and we often get some advice from people regarding use of multithreading: Don't use multithreading or at least limit use of multithreading. But sometimes it's better to use multithreading when we want to give users better user experience, for example in GUI programming or some long running process. Then we need to understand some details about multithreading. Also, many interview questions are from multithreading.
summarized a list of Java multithreading interview questions. He gave the answers to these questions. Hope this can help those who want to understand multithreading or who are preparing for interviews.
These are the some of question:
- What is synchronization in respect to multi-threading in Java?
- Explain different way of using thread?
- What is the difference between Thread.start() & Thread.run() method?
- Why do we need run() & start() method both. Can we achieve it with only run method?
- What is ThreadLocal class? How can it be used?
- When InvalidMonitorStateException is thrown? Why?
- What is the difference between sleep(), suspend() and wait() ?
- What happens when I make a static method as synchronized?
- Can a thread call a non-synchronized instance method of an Object when a synchronized method is being executed ?
- Can two threads call two different synchronized instance methods of an Object?
For the full list of questions and answers, please go to 20 Multi Threading Interview Questions & Answers for Java Developers