Lets say I have critical section code written in method A
public void A(){
//Critical Section
}
I can make it synchronized so as to allow exclusive access to it
synchronized public void A(){ }
Or alternatively I can also use a Semaphore
class in java
How these two approaches differ in working ?