Returns true if and only if the specified executor is an ExecutorService and is shut down. - Java java.util.concurrent

Java examples for java.util.concurrent:ExecutorService

Description

Returns true if and only if the specified executor is an ExecutorService and is shut down.

Demo Code

/*/*  w  w  w.j a  v  a  2  s  .  c om*/
 * Copyright 2009 Red Hat, Inc.
 *
 * Red Hat licenses this file to you under the Apache License, version 2.0
 * (the "License"); you may not use this file except in compliance with the
 * License.  You may obtain a copy of the License at:
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
//package com.java2s;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;

public class Main {
    /**
     * Returns {@code true} if and only if the specified {@code executor}
     * is an {@link ExecutorService} and is shut down.  Please note that this
     * method returns {@code false} if the specified {@code executor} is not an
     * {@link ExecutorService}.
     */
    public static boolean isShutdown(Executor executor) {
        if (executor instanceof ExecutorService) {
            if (((ExecutorService) executor).isShutdown()) {
                return true;
            }
        }
        return false;
    }
}

Related Tutorials