trait Semaphore extends AnyRef
A trait for a non-blocking semaphore that ensures limiting concurrent execution to tasks that have been granted the requested number of permits from a limited pool of permits. The acquire method is used to request the execution of a task once the requested number of permits become available. If the permits are not immediately available, the request is placed into a FIFO queue while waiting for permits to become available. The permit pool size is typically static with permits released back to the pool upon completion of tasks. However, some implementations may have dynamic sized pools that expend permits instead of releasing them, replenishing permits through some other mechanism.
Note1: Because Semaphore accepts a function to the task to run, it is not possible for callers to double lock, double release or forget to release permits. Note2: Semaphore is NOT reentrant Note3: Semaphore should never be used when other options make more sense. Semaphore is designed for synchronizing many tasks (100+) and/or long running tasks (10ms+). Unlike other options, Semaphore does not block and consume a thread while waiting for permits to become available. However, Semaphore is not the most performant option.
- Alphabetic
- By Inheritance
- Semaphore
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Abstract Value Members
-
abstract
def
acquire[X](permitCount: Int)(task: ⇒ Future[X])(implicit ec: ExecutionContext): DeferredFuture[X]
- task
the task to run once permits are available
- returns
a future that completes once permitCount permits are available AND task completes. task is started once permitCount permits are available. The permits are removed from the pool while task is running and after task completes the permits are returned to the pool.
- Exceptions thrown
java.lang.IllegalArgumentException
if the number of requested permits exceeds maxAvailablePermits
-
abstract
def
availablePermits: Int
- returns
the current number of permits available
-
abstract
def
maxAvailablePermits: Int
- returns
the maximum number of permits in the pool
-
abstract
def
waitQueueLength: Int
- returns
the count of callers currently waiting on permits to become available
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )