Java Multithreading Interview Questions and Answers

Java Multithreading Interview Questions


1) Explain about Multitasking?

A) The concept of executing multiple functionalities simultaneously one with the other is known as Multitasking.

2) Explain the advantage of Multitasking?

A) The advantage of multitasking is shown below:
1) BY applying the concept of multitasking we can totally avoid the idle state of the CPU.
2) BY applying the concept of multitasking we can make the functionalities independent on each other.
3) Actually, the concept of multitasking was invented in order to overcome the idle state of CPU. But we apply the concept of multitasking to make the functionalities independent on each other.

3) What happens in Multitasking?

A) In Multitasking multiple functionalities would be executed part by part with a very small & negligible time gap. Because of which it looks multiple functionalities are getting executed simultaneously one with the other.

4) What are the two types of Multitasking?

A) The two types of Multitasking are:
1) Process-based Multitasking.
2) Thread-based Multitasking.

5) Explain about Process based Multitasking?

A) Executing multiple programs belonging to the different languages & technologies simultaneously one with the other is known as process-based Multitasking.

6) Explain about Thread based Multitasking?

A) Executing multiple functionalities (or) methods belonging to the same process (or) belonging to the same application simultaneously is known as Thread based Multitasking.

7) Why Java support Thread based Multitasking?

A) In thread-based multitasking, the control would be switching between the two different functionalities (or) methods belonging to the same application and process which would not increase any overhead on the system. Thus Java supports only thread based multitasking.

 8) What is Thread?

A) A thread is nothing but a functionality (or) method which could be executed simultaneously with the other part of the program.

 9) What is the difference between Thread and Method?

A) Every Thread is a method. But every method cannot be a thread.

10) What is the Process?

A) Any program which is under execution is called a process.

11) Explain the relation between thread and process?

A) A thread is a part of the process.

12) Explain the steps using which we implement the concept of thread-based multitasking?

A)  The two steps using which we implement the concept of thread-based multitasking in Java:
1) Defining functionality has a thread.
2) Executing the run method of Runnable Interface has a thread.

13)  Explain Start() method of thread class?

A) The functionality of the start method of thread class is only to handover the run method of Runnable Interface to the JVM for scheduling and request JVM to execute the run method of the runnable interface has a thread.

14) What is Multithreading?

A) The concept of defining multiple functionalities has threads and executing multiple functionalities has threads simultaneously one with the other is known as Multithreading.

15) What is scheduling?

A) The concept of deciding, when the execution of a thread has to start (or) begin and deciding what part of a thread has to get executed and deciding which thread has to continue next is known as scheduling.

16) what is Rescheduling?

A) JVM bringing thread which is under wait state into Action is known as Rescheduling.

17) Explain about Priorities?

A) Priority means preference. Using priorities we can control the Rescheduling of threads.

18) Explain about Notify method?

A) Whenever the notify method is called, it would be bringing a thread which is in the wait state back into action. Based on the priorities mention.

19) What is Deadlock?

A) It is the state of a thread application, where multiple threads belonging to the same application would enter into wait state simultaneously & multiple threads belonging to the same application would continue in the wait state forever, which is known as Deadlock.

20) How to avoid Deadlock?

A) We can avoid Deadlock using wait method of the object class.

21) How many types of Threads are there in Java?

A) There are two types of Threads in Java:
1) User Thread.
2) Daemon Thread.

22) What is User Thread?

A) The normal and usual child thread which is joined to the end of its parent is known as User Thread.

23) What is Daemon Thread?

A) Any child thread which is not joined to the end of its parent is known as Daemon Thread.

24) What is the Minimum priority of Thread?

A) “1” is the Minimum priority of Thread.

25) What is the Normal priority of Thread?

A) “5” is the Normal priority of Thread.

26) What is the Maximum priority of Thread?

A) “10” is the Maximum priority of Thread.

27) What are the methods used for preventing Thread execution?

A) We can prevent the Thread Execution by using the following methods of threads class.
1) yield.
2) join.
3) sleep.

28) Explain about the Yield() method?

A) This is used to pause the currently executing thread, for giving chance to remaining waiting threads of some priority. If there is no thread waiting or all the threads waiting have low priority, then the same thread is once again given a chance for the execution.

29) Explain about the Join() method?

A) If a thread wants to wait until completion of other thread, then we should go for join() method.

30) Explain about the Sleep() method?

A) If a thread doesn’t want to perform any operation for the particular amount of time when pausing is required, then we should go far sleep() method.

31) How to Interrupt a Thread?

A) A Thread can interrupt a sleeping or waiting thread by using interrupt() method of Thread class.

32) How to stop a Thread?

A) To stop a thread execution in the middle by using stop() method.

33) How to Suspend() and Resume() a Thread?

A) A Thread can Suspend another thread by using suspend() method.
And Resume a suspend thread by using resume() method.

34) Explain about the Synchronized?

A) Synchronized is the keyword applicable only for methods but not for variables and class.

35) What is the use of Synchronized Keyword?

A) If a method is declared as Synchronized, then at a time only one method is allowed to execute.


36) How locks are used in Synchronization?

A) Internally Synchronization concept is implemented by using the lock concept. Whenever we use the synchronized keyword, then the lock concept comes into existence.

37) Explain about the wish() method as Synchronized?

A) If we declare wish() method as synchronized then the threads will be executed one by one and hence we will get regular output.

38) Explain about Inter-Thread Communication?

A) The process of executing threads in the sequence of a loop with communication is called Inter-Thread Communication.

39) What are the different states of a Thread?

A) The different states of Thread are:
1) New state.
2) Runnable state.
3) Running state.
4) Dead state.
5) Blocked state.

40) Explain about Time-sliced or Round-Robin Scheduling?

Share:

Search This Blog

  • ()

Our Services

Powered by Blogger.

Top 20 Websites like Bookzz | Bookzz Alternatives Websites

The domain  Bookzz.org  isn’t into work anymore, and the world’s largest ebook library  Bookzz  has got a new domain name or its Alternati...