Flash cards
Review the key moves
What is the main idea behind Java synchronized Keyword?
Lesson checks
Practice each idea before moving on
Short Mimo-style checks built from this lesson's code, terms, and sequence.
Which statement best captures the main point of this lesson?
Complete the missing token from the example code.
___Put the learning moves in the order that makes the concept easiest to apply.
❮ 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