Java Thread Executor Execute executeInThread(Runnable r)

Here you can find the source of executeInThread(Runnable r)

Description

Posts a Runnable in a new Thread

License

Creative Commons License

Parameter

Parameter Description
r : Runnable to be posted (get it from RunnableCreatorUtil )

Return

A to be able to manage failures & cancels.

Declaration

public static Future<?> executeInThread(Runnable r) 

Method Source Code


//package com.java2s;
//License from project: Creative Commons License 

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class Main {
    private static ExecutorService exService = Executors.newFixedThreadPool(5);

    /**// w  w w .  j a v a  2s  .co m
     * Posts a {@link Runnable} in a new {@link Thread}
     * @param r : {@link Runnable} to be posted (get it from {@link RunnableCreatorUtil})
     * @return A {@link Future} to be able to manage failures & cancels.
     */
    public static Future<?> executeInThread(Runnable r) {
        return exService.submit(r);
    }
}

Related

  1. executeAndWait(final Runnable r)
  2. executeAsynchronously(Runnable r)
  3. executeForever(final Runnable runnable)
  4. executeFuture(Callable callable)
  5. executeInCachedPool(Runnable runnable)
  6. executeInThreadPool(Runnable runnable)
  7. executeParallel(final List> callables, final int maxThreadCount)
  8. executePeriodicallyInThread(Runnable r, int delay, int period, TimeUnit unit)
  9. ExecuteThreads(ArrayList threads, int nThreads)