Tuesday 15 January 2013

Core Java Interview Questions


36. What is synchronized means in thread?
A method or a block of code can be synchronized. Only one thread is allowed to access the method.

37. What is the difference in synchronizing the static or non static method?
When a sync static method is called the lock is made on the class but if the sync non static method is called then lock is made on the object.

38. Difference between sleep and yield?
The Sleep() method makes a thread to go to sleep mode for a pre defined time and the lock is not released.
The yield() releases the lock on the object and the other thread allowed the lock the object.

39. Difference between notify and notifyall?
notify( ) calls the first thread that called wait( ) on the object whereas
notifyAll( ) calls all the threads that called wait( ) on the object. Object is called based on priority.

40. Can we synchronize a class or variable?
No

                                                          Previous

No comments:

Post a Comment