Code snippet like below:
List<String> list = new ArrayList<>();
public void addValue(int i) {
synchronized (list) {
list.add("list" + i);
}
}
My question is that what is locked by keyword synchronized
.
What will be checked of the list
when two threads are asking to execute the code block?
The same question is that I synchronized this
but its fields can still be changed.