bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths

Loading lesson path

Learn/Java/Java Reference
Java•Java Reference

Java synchronized Keyword

❮ Java Keywords

synchronized

Definition 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

Previous

Java switch Keyword

Next

Java this Keyword