Trait/Object

s_mach.concurrent.util

Semaphore

Related Docs: object Semaphore | package util

Permalink

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.

Linear Supertypes
AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Semaphore
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def acquire[X](permitCount: Int)(task: ⇒ Future[X])(implicit ec: ExecutionContext): DeferredFuture[X]

    Permalink

    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

  2. abstract def availablePermits: Int

    Permalink

    returns

    the current number of permits available

  3. abstract def maxAvailablePermits: Int

    Permalink

    returns

    the maximum number of permits in the pool

  4. abstract def waitQueueLength: Int

    Permalink

    returns

    the count of callers currently waiting on permits to become available

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  6. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  7. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  8. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  9. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  10. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  11. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  12. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  13. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  14. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  15. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  16. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  17. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  18. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  19. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped