Class TimedSemaphore.Builder

    • Constructor Detail

      • Builder

        public Builder()
        Constructs a new Builder.
    • Method Detail

      • setFair

        public TimedSemaphore.Builder setFair​(boolean fair)
        Sets whether blocking acquisitions use FIFO ordering.

        Fairness is disabled by default. When enabled, calls to TimedSemaphore.acquire() are ordered by entry into the internal waiting queue, not by thread start time or method return order. New calls made with the limit disabled and calls to TimedSemaphore.tryAcquire() may bypass waiting callers.

        Parameters:
        fair - Whether to enable FIFO ordering.
        Returns:
        this instance.
        Since:
        3.22.0
      • setLimit

        public TimedSemaphore.Builder setLimit​(int limit)
        Sets the limit.
        Parameters:
        limit - The limit.
        Returns:
        this instance.
      • setPeriod

        public TimedSemaphore.Builder setPeriod​(long period)
        Sets the time period.
        Parameters:
        period - The time period.
        Returns:
        this instance.
      • setService

        public TimedSemaphore.Builder setService​(java.util.concurrent.ScheduledExecutorService service)
        Sets the executor service.
        Parameters:
        service - The executor service.
        Returns:
        this instance.
      • setTimeUnit

        public TimedSemaphore.Builder setTimeUnit​(java.util.concurrent.TimeUnit timeUnit)
        Sets the time unit for the period.
        Parameters:
        timeUnit - The time unit for the period.
        Returns:
        this instance.