Java Multithreading Question and Answers

21. What are concurrent collection classes?
 
  • Java Collection Classes are fail fast which means that if the Collection will be changed while some thread is traversing over it using iterator, the iterator.next() will throw Concurrent Modification Exception.
  • Concurrent collection classes supports full concurrency of retrievals and adjustable expected concurrency for updates.
 
Your Name Your Email-ID
Your Answer
22. What is the difference between synchronized and synchronized block?
 
  • In case of synchronized method a thread may need to have the lock for a longer time as compared to the synchronized block.
  • Another difference between the synchronized method and block is that we don't specify the particular object whose monitor is required to be obtained by thread for entering a synchronized method, whereas we can specify the particular object in case of synchronized block.
 
Your Name Your Email-ID
Your Answer
23. Can a method be static and synchronized?
  No a static method can't be synchronized.
 
Your Name Your Email-ID
Your Answer
24. Which method must be implemented by all threads?
  All tasks must implement the run() method.
 
Your Name Your Email-ID
Your Answer
12345678910 Page 6 of 10