Class MdcScheduledExecutorService

java.lang.Object
com.sportradar.unifiedodds.sdk.internal.impl.util.MdcScheduledExecutorService
All Implemented Interfaces:
Executor, ExecutorService, ScheduledExecutorService

public class MdcScheduledExecutorService extends Object implements ScheduledExecutorService
  • Constructor Summary

    Constructors
    Constructor
    Description
    Initializes a new instance of the MdcScheduledExecutorService class
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    awaitTermination(long timeout, TimeUnit unit)
    Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.
    void
    execute(Runnable command)
    Executes the given command at some time in the future.
    <T> List<Future<T>>
    invokeAll(Collection<? extends Callable<T>> tasks)
    Executes the given tasks, returning a list of Futures holding their status and results when all complete.
    <T> List<Future<T>>
    invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
    Executes the given tasks, returning a list of Futures holding their status and results when all complete or the timeout expires, whichever happens first.
    <T> T
    invokeAny(Collection<? extends Callable<T>> tasks)
    Executes the given tasks, returning the result of one that has completed successfully (i.e., without throwing an exception), if any do.
    <T> T
    invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
    Executes the given tasks, returning the result of one that has completed successfully (i.e., without throwing an exception), if any do before the given timeout elapses.
    boolean
    Returns true if this executor has been shut down.
    boolean
    Returns true if all tasks have completed following shut down.
    schedule(Runnable command, long delay, TimeUnit unit)
    Creates and executes a one-shot action that becomes enabled after the given delay.
    schedule(Callable<V> callable, long delay, TimeUnit unit)
    Creates and executes a ScheduledFuture that becomes enabled after the given delay.
    scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit)
    Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period; that is executions will commence after initialDelay then initialDelay+period, then initialDelay + 2 * period, and so on.
    scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit)
    Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given delay between the termination of one execution and the commencement of the next.
    void
    Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.
    Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.
    Submits a Runnable task for execution and returns a Future representing that task.
    <T> Future<T>
    submit(Runnable task, T result)
    Submits a Runnable task for execution and returns a Future representing that task.
    <T> Future<T>
    submit(Callable<T> task)
    Submits a value-returning task for execution and returns a Future representing the pending results of the task.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • schedule

      public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit)
      Creates and executes a one-shot action that becomes enabled after the given delay.
      Specified by:
      schedule in interface ScheduledExecutorService
      Parameters:
      command - the task to execute
      delay - the time from now to delay execution
      unit - the time unit of the delay parameter
      Returns:
      a ScheduledFuture representing pending completion of the task and whose get() method will return null upon completion
      Throws:
      RejectedExecutionException - if the task cannot be scheduled for execution
      NullPointerException - if command is null
    • schedule

      public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit)
      Creates and executes a ScheduledFuture that becomes enabled after the given delay.
      Specified by:
      schedule in interface ScheduledExecutorService
      Parameters:
      callable - the function to execute
      delay - the time from now to delay execution
      unit - the time unit of the delay parameter
      Returns:
      a ScheduledFuture that can be used to extract result or cancel
      Throws:
      RejectedExecutionException - if the task cannot be scheduled for execution
      NullPointerException - if callable is null
    • scheduleAtFixedRate

      public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit)
      Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period; that is executions will commence after initialDelay then initialDelay+period, then initialDelay + 2 * period, and so on. If any execution of the task encounters an exception, subsequent executions are suppressed. Otherwise, the task will only terminate via cancellation or termination of the executor. If any execution of this task takes longer than its period, then subsequent executions may start late, but will not concurrently execute.
      Specified by:
      scheduleAtFixedRate in interface ScheduledExecutorService
      Parameters:
      command - the task to execute
      initialDelay - the time to delay first execution
      period - the period between successive executions
      unit - the time unit of the initialDelay and period parameters
      Returns:
      a ScheduledFuture representing pending completion of the task, and whose get() method will throw an exception upon cancellation
      Throws:
      RejectedExecutionException - if the task cannot be scheduled for execution
      NullPointerException - if command is null
      IllegalArgumentException - if period less than or equal to zero
    • scheduleWithFixedDelay

      public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit)
      Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given delay between the termination of one execution and the commencement of the next. If any execution of the task encounters an exception, subsequent executions are suppressed. Otherwise, the task will only terminate via cancellation or termination of the executor.
      Specified by:
      scheduleWithFixedDelay in interface ScheduledExecutorService
      Parameters:
      command - the task to execute
      initialDelay - the time to delay first execution
      delay - the delay between the termination of one execution and the commencement of the next
      unit - the time unit of the initialDelay and delay parameters
      Returns:
      a ScheduledFuture representing pending completion of the task, and whose get() method will throw an exception upon cancellation
      Throws:
      RejectedExecutionException - if the task cannot be scheduled for execution
      NullPointerException - if command is null
      IllegalArgumentException - if delay less than or equal to zero
    • shutdown

      public void shutdown()
      Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted. Invocation has no additional effect if already shut down.

      This method does not wait for previously submitted tasks to complete execution. Use awaitTermination to do that.

      Specified by:
      shutdown in interface ExecutorService
      Throws:
      SecurityException - if a security manager exists and shutting down this ExecutorService may manipulate threads that the caller is not permitted to modify because it does not hold RuntimePermission("modifyThread"), or the security manager's checkAccess method denies access.
    • shutdownNow

      public List<Runnable> shutdownNow()
      Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.

      This method does not wait for actively executing tasks to terminate. Use awaitTermination to do that.

      There are no guarantees beyond best-effort attempts to stop processing actively executing tasks. For example, typical implementations will cancel via Thread.interrupt(), so any task that fails to respond to interrupts may never terminate.

      Specified by:
      shutdownNow in interface ExecutorService
      Returns:
      list of tasks that never commenced execution
      Throws:
      SecurityException - if a security manager exists and shutting down this ExecutorService may manipulate threads that the caller is not permitted to modify because it does not hold RuntimePermission("modifyThread"), or the security manager's checkAccess method denies access.
    • isShutdown

      public boolean isShutdown()
      Returns true if this executor has been shut down.
      Specified by:
      isShutdown in interface ExecutorService
      Returns:
      true if this executor has been shut down
    • isTerminated

      public boolean isTerminated()
      Returns true if all tasks have completed following shut down. Note that isTerminated is never true unless either shutdown or shutdownNow was called first.
      Specified by:
      isTerminated in interface ExecutorService
      Returns:
      true if all tasks have completed following shut down
    • awaitTermination

      public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException
      Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.
      Specified by:
      awaitTermination in interface ExecutorService
      Parameters:
      timeout - the maximum time to wait
      unit - the time unit of the timeout argument
      Returns:
      true if this executor terminated and false if the timeout elapsed before termination
      Throws:
      InterruptedException - if interrupted while waiting
    • submit

      public <T> Future<T> submit(Callable<T> task)
      Submits a value-returning task for execution and returns a Future representing the pending results of the task. The Future's get method will return the task's result upon successful completion.

      If you would like to immediately block waiting for a task, you can use constructions of the form result = exec.submit(aCallable).get();

      Note: The Executors class includes a set of methods that can convert some other common closure-like objects, for example, PrivilegedAction to Callable form so they can be submitted.

      Specified by:
      submit in interface ExecutorService
      Parameters:
      task - the task to submit
      Returns:
      a Future representing pending completion of the task
      Throws:
      RejectedExecutionException - if the task cannot be scheduled for execution
      NullPointerException - if the task is null
    • submit

      public <T> Future<T> submit(Runnable task, T result)
      Submits a Runnable task for execution and returns a Future representing that task. The Future's get method will return the given result upon successful completion.
      Specified by:
      submit in interface ExecutorService
      Parameters:
      task - the task to submit
      result - the result to return
      Returns:
      a Future representing pending completion of the task
      Throws:
      RejectedExecutionException - if the task cannot be scheduled for execution
      NullPointerException - if the task is null
    • submit

      public Future<?> submit(Runnable task)
      Submits a Runnable task for execution and returns a Future representing that task. The Future's get method will return null upon successful completion.
      Specified by:
      submit in interface ExecutorService
      Parameters:
      task - the task to submit
      Returns:
      a Future representing pending completion of the task
      Throws:
      RejectedExecutionException - if the task cannot be scheduled for execution
      NullPointerException - if the task is null
    • invokeAll

      public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException
      Executes the given tasks, returning a list of Futures holding their status and results when all complete. Future.isDone() is true for each element of the returned list. Note that a completed task could have terminated either normally or by throwing an exception. The results of this method are undefined if the given collection is modified while this operation is in progress.
      Specified by:
      invokeAll in interface ExecutorService
      Parameters:
      tasks - the collection of tasks
      Returns:
      A list of Futures representing the tasks, in the same sequential order as produced by the iterator for the given task list, each of which has completed.
      Throws:
      InterruptedException - if interrupted while waiting, in which case unfinished tasks are cancelled.
      NullPointerException - if tasks or any of its elements are null
      RejectedExecutionException - if any task cannot be scheduled for execution
    • invokeAll

      public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException
      Executes the given tasks, returning a list of Futures holding their status and results when all complete or the timeout expires, whichever happens first. Future.isDone() is true for each element of the returned list. Upon return, tasks that have not completed are cancelled. Note that a completed task could have terminated either normally or by throwing an exception. The results of this method are undefined if the given collection is modified while this operation is in progress.
      Specified by:
      invokeAll in interface ExecutorService
      Parameters:
      tasks - the collection of tasks
      timeout - the maximum time to wait
      unit - the time unit of the timeout argument
      Returns:
      a list of Futures representing the tasks, in the same sequential order as produced by the iterator for the given task list. If the operation did not time out, each task will have completed. If it did time out, some of these tasks will not have completed.
      Throws:
      InterruptedException - if interrupted while waiting, in which case unfinished tasks are cancelled
      NullPointerException - if tasks, any of its elements, or unit are null
      RejectedExecutionException - if any task cannot be scheduled for execution
    • invokeAny

      public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException
      Executes the given tasks, returning the result of one that has completed successfully (i.e., without throwing an exception), if any do. Upon normal or exceptional return, tasks that have not completed are cancelled. The results of this method are undefined if the given collection is modified while this operation is in progress.
      Specified by:
      invokeAny in interface ExecutorService
      Parameters:
      tasks - the collection of tasks
      Returns:
      the result returned by one of the tasks
      Throws:
      InterruptedException - if interrupted while waiting
      NullPointerException - if tasks or any element task subject to execution is null
      IllegalArgumentException - if tasks is empty
      ExecutionException - if no task successfully completes
      RejectedExecutionException - if tasks cannot be scheduled for execution
    • invokeAny

      public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
      Executes the given tasks, returning the result of one that has completed successfully (i.e., without throwing an exception), if any do before the given timeout elapses. Upon normal or exceptional return, tasks that have not completed are cancelled. The results of this method are undefined if the given collection is modified while this operation is in progress.
      Specified by:
      invokeAny in interface ExecutorService
      Parameters:
      tasks - the collection of tasks
      timeout - the maximum time to wait
      unit - the time unit of the timeout argument
      Returns:
      the result returned by one of the tasks.
      Throws:
      InterruptedException - if interrupted while waiting
      NullPointerException - if tasks, or unit, or any element task subject to execution is null
      TimeoutException - if the given timeout elapses before any task successfully completes
      ExecutionException - if no task successfully completes
      RejectedExecutionException - if tasks cannot be scheduled for execution
    • execute

      public void execute(Runnable command)
      Executes the given command at some time in the future. The command may execute in a new thread, in a pooled thread, or in the calling thread, at the discretion of the Executor implementation.
      Specified by:
      execute in interface Executor
      Parameters:
      command - the runnable task
      Throws:
      RejectedExecutionException - if this task cannot be accepted for execution.
      NullPointerException - if command is null