0

Is it a fair assumption to say that if a class has a synchronized block, it's always better to have @GuardedBy annotation in that class.

More specifically, will there be a case where we have a synchronized block in a java file but we cannot use @GuardedBy annotation in that class on any field or method ?

Bajji
  • 2,243
  • 2
  • 22
  • 35

1 Answers1

0

If @GuardedBy annotation reference any of the Lock implementations like ReentrantLock, ReentrantReadWriteLock.ReadLock, ReentrantReadWriteLock.WriteLock then it is expected to use the concerned lock for locking instead of locking with a synchronized block.

Abhiroop Sarkar
  • 2,251
  • 1
  • 26
  • 45