Search This Blog

Saturday, February 11, 2006

Java Multi Threading Interview Questions

1) What are the two types of multitasking?

Ans : 1.process-based


2) What are the two ways to create the thread?

Ans : implementing Runnable extending Thread

3) What is the signature of the constructor of a thread class?

Ans : Thread(Runnable threadob,String threadName)

4) What are all the methods available in the Runnable Interface?

Ans : run()

5) What is the data type for the method isAlive() and this method is

available in which class?

Ans : boolean, Thread

6) What are all the methods available in the Thread class?

Ans : 1.isAlive()








7) What are all the methods used for Inter Thread communication and what is the class in which these methods are defined?

Ans :1. wait(),notify() & notifyall()

2. Object class

8) What is the mechanisam defind by java for the Resources to be used by only one Thread at a time?

Ans : Synchronisation

9) What is the procedure to own the moniter by many threads?

Ans : not possible

10) What is the unit for 1000 in the below statement?


Ans : long milliseconds

11) What is the data type for the parameter of the sleep() method?

Ans : long

12) What are all the values for the following level?




Ans : 10,1,5

13) What is the method available for setting the priority?

Ans : setPriority()

14) What is the default thread at the time of starting the program?

Ans : main thread

15) The word synchronized can be used with only a method.

True/ False

Ans : False

16) Which priority Thread can prompt the lower primary Thread?

Ans : Higher Priority

17) How many threads at a time can access a monitor?

Ans : one

18) What are all the four states associated in the thread?

Ans : 1. new 2. runnable 3. blocked 4. dead

19) The suspend()method is used to teriminate a thread?

True /False

Ans : False

20) The run() method should necessary exists in clases created as subclass of thread?

True /False

Ans : True

21) When two threads are waiting on each other and can't proceed the programe is said to be in a deadlock?


Ans : True

22) Which method waits for the thread to die ?

Ans : join() method

23) Which of the following is true?

1) wait(),notify(),notifyall() are defined as final & can be called only from with in a synchronized method

2) Among wait(),notify(),notifyall() the wait() method only throws IOException

3) wait(),notify(),notifyall() & sleep() are methods of object class

1 & 2
1,2 & 3
Ans : D
24) Garbage collector thread belongs to which priority?

Ans : low-priority

25) What is meant by timeslicing or time sharing?

Ans : Timeslicing is the method of allocating CPU time to individual threads in a priority schedule.

26) What is meant by daemon thread? In java runtime, what is it's role?

Ans : Daemon thread is a low priority thread which runs intermittently in the background doing the garbage collection operation for the java runtime system


Anonymous said...

I think that run() method is not necessary for the classes extending the Thread class, because this method comes directly from the Runnable interface. Yes it must be present in classes implmenting the Runnable interface. isn't it?

Anonymous said...

True. But by doing that you may not achieve anything. Your thread will die soon after it is started.

If you pass an instance of your own class which implements Runnable (so has run() method) to the Thread (through constructor), calling Thread.start() will call your run method.

Anonymous said...

run method in Thread class does nothing after start method invoke it. you must implement run method on your class (subclass of Thread) to achieve the purpose why you extending Thread.

Anonymous said...


for question no.23, on the second option, wait() actually throws InterruptedException not IOException.

MONICA said...

True.I think Once we extends the Thread class and override the run method in our own class,then the overided method will only be invoked.Here we assign the actual job for a thread to do and will be invoked after invoking start method.
So its necessary to assign a job to your thread which it has to accomplish.

Stark Solutions said...

Nice post about threads, consider my Q&A as well

Q: What happens when start() method is called on an already running thread?
A: IllegalStateException is thrown

Q: Which is best approach to create a thread implementing Runnable or extending Thread?
A: Implementing Runnable. Because we still have opportunity to extend another class as well as implement more interfaces

Anonymous said...

As per the question, answer should be false. Providing run() definition is not mandatory to extend Thread class.

Avi said...

In question 23,
sleep() method is member of thread class not of object class.

Anonymous said...

That's why the answer was D... ;)
Happy reading....

Anonymous said...

hi,i think tat max,min,normal priority of threads is 10,5, it true..

Priya said...

Thanks for sharing

Anonymous said...

The answer for 23 is not D but A, which means that only the first statement is correct.

Because the second sentence says that wait and other methods throw IOException, which is incorrect. These methods throw InterruptedException.

Anonymous said...

i fel questions are very simple nd any body can answer if they have little knowledge

Shrikant.Kulkarni said...

No its correct

Shrikant.Kulkarni said...

No its like below
MAX = 10
MIN = 1

Tips on Interview said...

thanks for your questions and answers,

Anonymous said...

@Shri right dear...

Anonymous said...

Nice ... blog..

Anonymous said...

good question bu Sleep() is method of Thread class while wait() is from Object class. here is another good link I found while searching Java multi-threading questions asked in Investment Banks

Anonymous said...

I think the answer of 23) is not A unless we have a statement like the following - .......& can be called from with in a synchronized method if the calls are to this or synchronized block on the object on which we call object.wait() etc.

Anonymous said...

The answer for 23 is not D but A, which means that only the first statement is correct.

Because the second sentence says that wait and other methods throw IOException, which is incorrect. These methods throw InterruptedException.

FromDev said...

Thanks for sharing the questions. Some of them are my fav ones I always try to ask them while looking for Java candidates. Just bookmarked your link.