lowLatency
lowLatency

Reputation: 5654

Java semaphore + No synchronization lock is held when acquire() is called

I am not able to understand the meaning of below line which is provided on link JavaWorld

No synchronization lock is held when acquire() is called because that would prevent an item from being returned to the pool.

Kindly help me understanding this.

Upvotes: 1

Views: 96

Answers (2)

Grigoriev Nick
Grigoriev Nick

Reputation: 1129

Look on this animated video it help you

Upvotes: 0

Gyanendra Dwivedi
Gyanendra Dwivedi

Reputation: 5538

In the context of the article and code explanation, the above line says that whenever acquire() method is being called, it does not actually lock the resource it is trying to acquire. Why it is so?

Semaphore is like sleeping lock. When a task attempts to acquire a semaphore that is already held, the semaphore places the task onto a wait queue and puts the task to sleep.

Because from semaphore usage, you are requesting to get the lock, and waiting in a queue. You will get the lock only when you are actually given the resource.

Upvotes: 3

Related Questions