Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does Semaphor.drainPermits do if no permits are available?

I'm trying to understand the contract of drainPermits in the Java Semaphore class

The JavaDoc simply reads:

public int drainPermits()

Acquire and return all permits that are immediately available.

Returns:
    the number of permits

If no permits are currently available, does it block and wait until one is available?

like image 831
Uri Avatar asked Jan 23 '23 06:01

Uri


1 Answers

No, it will return 0 immediately. It doesn't require any permits to be available.

like image 182
Jon Skeet Avatar answered Feb 14 '23 09:02

Jon Skeet