1. What is the start() and run() method of Thread class?
When the start() method is called, a new thread is created and this newly created thread executes the task that is kept in the run() method. One can call the start() method only once.
When the run() method is called, no new thread is created as in the case of the start() method. This method is executed by the current thread. One can call the run() method multiple times.
2. What is Thread in java?
3. What are the 2 ways of implementing Thread in java?
4. What is the difference between class lock and Object lock?
Class lock: each and every class has a unique lock usually referred to as a class level lock. These locks are achieved using the keyword ‘static synchronized’ and can be used to make static data thread-safe. It is generally used when one wants to prevent multiple threads from entering a synchronized block.
Object lock: each and every object has a unique lock usually referred to as an object-level lock. These locks are achieved using the keyword ‘synchronized’ and can be used to protect non-static data. It is generally used when one wants to synchronize a non-static method or block so that only the thread will be able to execute the code block on a given instance of the class.
5. What is Daemon Thread?
daemon threads are basically referred to as a service provider that provides services and support to user threads. There are basically two methods available in thread class for daemon thread: setDaemon() and isDaemon().
These threads are referred to as low priority threads, therefore are especially required for supporting background tasks like garbage collection, releasing memory of unused objects, etc.
6. What are wait() and Sleep() methods?
it is a non-static method that causes the current thread to wait and go to sleep until some other threads call the notify () or notifyAll() method for the object’s monitor (lock). It simply releases the lock and is mostly used for inter-thread communication. It is defined in the object class, and should only be called from a synchronized context.
7. What is difference between notify() and notifyall()?
8. What is Runnable and Callable interface?
9. What are benefits of using Multithreading?
10. What is Thread pool?
11. What is the purpose of Join Method?
12. Explain deadlock?
13. How do Threads Communicate with each other?
14. How to stop thread in java?
15. Explain the different priorities of Threads?
16. What is the primary drawback of Syncronized Methods?
17. What are the different states of a Thread?
18. Is 2 threads can have same name? if yes, How can you identify the same threads?
19. What is the priority of main thread?
20. What is the default priority of a thread?
21. What is Synchronization?
22. Is it possible to make constructors synchronized? No,
23. Can we use Synchronized Keyword with variables? no
24. Explain Volatile Variables in java? main memory
25. What is Inter-Thread Communication?
26. What is Context switching?
27. When should we use interrupt a Thread?
28. What is Race-Condition?