Class SingleThreadExecutor

    • Constructor Detail

      • SingleThreadExecutor

        public SingleThreadExecutor()
        Creates a single thread executor.

        A new thread is created and started immediately.

    • Method Detail

      • run

        public void run()
        Description copied from interface: Runnable
        When an object implementing interface Runnable is used to create a thread, starting the thread causes the object's run method to be called in that separately executing thread.

        The general contract of the method run is that it may take any action whatsoever.

        Specified by:
        run in interface Runnable
        See Also:
        Thread.run()
      • execute

        public void execute​(Runnable r)
        Description copied from interface: Executor
        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:
        r - the runnable task
      • shutdown

        public void shutdown()
        Description copied from interface: ExecutorService
        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
      • isShutdown

        public boolean isShutdown()
        Description copied from interface: ExecutorService
        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()
        Description copied from interface: ExecutorService
        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
      • submit

        public <T> Future<T> submit​(Callable<T> task)
        Description copied from interface: ExecutorService
        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();

        Specified by:
        submit in interface ExecutorService
        Parameters:
        task - the task to submit
        Returns:
        a Future representing pending completion of the task
      • submit

        public <T> Future<T> submit​(Runnable task,
                                    T result)
        This method is unsupported by this implementation.

        Calling this method will throw an UnsupportedOperationException.

        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
      • submit

        public Future<?> submit​(Runnable task)
        This method is unsupported by this implementation.

        Calling this method will throw an UnsupportedOperationException.

        Specified by:
        submit in interface ExecutorService
        Parameters:
        task - the task to submit
        Returns:
        a Future representing pending completion of the task
      • invokeAll

        public <T> List<Future<T>> invokeAll​(Collection<? extends Callable<T>> tasks)
                                      throws InterruptedException
        This method is unsupported by this implementation.

        Calling this method will throw an UnsupportedOperationException.

        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.
      • invokeAll

        public <T> List<Future<T>> invokeAll​(Collection<? extends Callable<T>> tasks,
                                             long timeout,
                                             TimeUnit unit)
                                      throws InterruptedException
        This method is unsupported by this implementation.

        Calling this method will throw an UnsupportedOperationException.

        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