❮ Java Keywords
synchronizedDefinition and Usage
The synchronized keyword is a modifier that locks a method so that only one thread can use it at a time. This prevents problems that arise from race conditions between threads.
In the example above, removing the synchronized keyword from the transfer() method may cause the values of a and b to be modified by another thread in between operations. This would result in the total amount between the two variables to change.
Related Pages
Read more about modifiers in our Java Modifiers Tutorial .
Read more about threads in our Java Threads Tutorial .
❮ Java Keywords