bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/Java/Java Reference
Java•Java Reference

Java synchronized Keyword

Flash cards

Review the key moves

1/4
Core idea

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.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

___
3Order

Put the learning moves in the order that makes the concept easiest to apply.

The synchronized keyword is a modifier that locks a method so that only one thread can use it at a time.
Definition and Usage
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