<dependency>
<groupId>net.jcip</groupId>
<artifactId>jcip-annotations</artifactId>
<version>1.0</version>
</dependency>
import net.jcip.annotations.ThreadSafe;
@ThreadSafe
public class ThreadSafeClass {
private int counter;
public synchronized void increment() {
counter++;
}
public synchronized int getCounter() {
return counter;
}
}