Collections.synchronizedMap()
guarantees that each atomic operation you want to run on the map will be synchronized.
Running two (or more) operations on the map however, must be synchronized in a block.
So yes – you are synchronizing correctly.
More Related Contents:
- How can I get my threaded program to print specific output
- Loop doesn’t see value changed by other thread without a print statement
- Is multi-thread output from System.out.println interleaved
- Synchronizing on String objects in Java
- Synchronization vs Lock
- What is the difference between atomic / volatile / synchronized?
- How to synchronize a static variable among threads running different instances of a class in Java?
- Are Java static initializers thread safe?
- Java double checked locking
- Synchronizing on an Integer value [duplicate]
- Java Synchronized Block for .class
- Static versus non-static lock object in synchronized block
- Java Singleton and Synchronization
- Printing Even and Odd using two Threads in Java
- How do determine if an object is locked (synchronized) so not to block in Java?
- Waiting on multiple threads to complete in Java
- Concurrent threads adding to ArrayList at same time – what happens?
- What is the difference between a synchronized method and synchronized block in Java? [duplicate]
- Collections.synchronizedList and synchronized
- How to add programmatically a custom account in android?
- Correct way to synchronize ArrayList in java
- Ensure that Spring Quartz job execution doesn’t overlap
- Sharing a variable between multiple different threads
- Should you synchronize the run method? Why or why not?
- How to acquire a lock by a key
- synchronized block for an Integer object
- Question about Java synchronized
- difference between synchronizing a static method and a non static method
- Is synchronization within an HttpSession feasible?
- Race between System.out and System.err in java [duplicate]