Search your topic in Java2share
Home > FAQs
eXTReMe Tracker


Multi Threading FAQs


Untitled Document

Q29. Is join() method is overloaded?
Ans.       Yes join() method is overloaded method.
                Public final void join() throws InterruptedException
                                By using this method thread will wait up to another thread completion .
                Public final void join(long ms) throws InterruptedException
By using this method thread will wail upto sometime what we are passing as a argument in millisecond
Public final void join(long ms, int ns)throws InterruptedException
By using this method thread will wait up to sometime what we are passing as a argument in millisecond and nanosecond.


Q30 What is the purpose of sleep() method?
Ans.  If a Thread don’t want to perform any operation for a particular amount of time then we should go for sleep() method.Whenever we are using sleep() method compulsory we should handle InterruptedException either by using try-catch or by using throws keyword otherwise we will get compile time error.

Q31. What is synchronized keyword? Explain its advantages and disadvantages.
Ans.       Synchronized keyword is applicable for method and blocks only. We can’t use for variables and classes.
                If a method declared as a synchronized then at a time only one Thread is allow to execute that method on the given object.
                The main advantages of synchronized keyword are, we can prevent data inconsistency problems and we can provide Threadsafty.
                But the main limitation of synchronized keyword is it increases waiting time of Threads and effect performance of the system. Hence if there is no specific requirement it is not recommended to use synchronized keyword.


Q32.Where we can use synchronized keyword?
Ans. Synchronization concept is applicable whenever multiple Threads are operating on the same object simultaneously. But whenever multiple Threads are operating on different objects then there is no impact of synchronization.