How and why can a Semaphore give out more permits than it was initialized with?

前端 未结 6 1292
庸人自扰
庸人自扰 2021-02-08 12:18

I am reading the book Java Concurrency in Practice. In a section about java.util.concurrent.Semaphore, the below lines are present in the book. It is a comment abou

6条回答
  •  情书的邮戳
    2021-02-08 13:02

    Can somebody explain this ? From the above statement, it looks like the "permits" can keep growing.

    A semaphore is a counter of permits. acquire is like decrement which waits rather than go below zero. It has no upper limit.

    Why is it designed this way ?

    Because its simple to do so.

提交回复
热议问题