Java Thread Executor convert(Runnable runnable, T result)

Here you can find the source of convert(Runnable runnable, T result)

Description

Converts the specified Runnable to a Callable returning the specified result.

License

Open Source License

Parameter

Parameter Description
runnable the Runnable to convert
result the result the returned Callable shall return
T the type of result

Return

a Callable calling runnable and returning result

Declaration

static <T> Callable<T> convert(Runnable runnable, T result) 

Method Source Code


//package com.java2s;
/*/*w w w .ja  v a2s .co m*/
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This file is part of SequentialExecutorService.
 *
 * SequentialExecutorService contains non-parallel implementations
 * for Java's ExecutorService and ScheduledExecutorService.
 * Copyright (C) 2015 Matthias Johannes Reimchen
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.concurrent.Callable;

public class Main {
    /**
     * Converts the specified {@link Runnable} to a {@link Callable} returning
     * the specified result.
     *
     * @param runnable the Runnable to convert
     * @param result the result the returned Callable shall return
     * @param <T> the type of result
     * @return a Callable calling runnable and returning result
     */
    static <T> Callable<T> convert(Runnable runnable, T result) {
        return () -> {
            runnable.run();
            return result;
        };
    }
}

Related

  1. addExecutorShutdownHook(final ExecutorService exec)
  2. addThread(Runnable runnable)
  3. getActiveHelperInstanceCount(String helperName)
  4. getChannelService()
  5. getConstantLookup()
  6. getThreadExecutor(int nThreads)