I don't entirely understand check and set behaviour.. here is an example:    public static void main(String[] args) {    List<String> list = Collections.synchronizedList(new ArrayList<>());    String abc = 123;    if (!list.contains(abc)) {        list.add(abc);        // ... some several lines of code        list.remove(abc);    }}What I don't quite understand...So I understand that contains and add should be in a synchronized(list) block...but what about remove? if not, then what if it was: if (list.contains(abc)) {   list.add(abc);   list.remove(abc);}  ? I understand that code doesn't make much sense but I just am using it as an example... Does remove have to be in the synchronized block here?
Don't quite understand check and set in concurrency
java;multithreading;concurrency