Java Threads Question:

Download Job Interview Questions and Answers PDF

When you will synchronize a piece of your code?

Java Threads Interview Question
Java Threads Interview Question

Answer:

When you expect that your shared code will be accessed by different threads and these threads may change a particular data causing data corruption, then they are placed in a synchronized construct or a synchronized method.

Download Java Threads Interview Questions And Answers PDF

Previous QuestionNext Question
What do you understand by Synchronization?
Or
What is synchronization and why is it important?
Or
Describe synchronization in respect to multithreading?
Or
What is synchronization?
Why would you use a synchronized block vs. synchronized method?