Java Thread Executor Execute runInNewThread(Runnable task)

Here you can find the source of runInNewThread(Runnable task)

Description

Runs a Runnable task in a Thread different than the current one.

License

Open Source License

Parameter

Parameter Description
task task to run in a Thread different than the current one.

Declaration

public static void runInNewThread(Runnable task) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    private static final ExecutorService pool = Executors.newCachedThreadPool();

    /**/*from www  . jav  a2s  .  c o  m*/
     * Runs a {@link Runnable} task in a {@link Thread} different than the
     * current one.
     *
     * @param task task to run in a {@link Thread} different than the current
     *             one.
     */
    public static void runInNewThread(Runnable task) {
        pool.submit(task);
    }
}

Related

  1. run(Runnable target)
  2. runConcurrently(final Runnable[] threads)
  3. runConcurrently(Runnable... tasks)
  4. runInBackground(final Runnable task)
  5. runInBackground(Runnable run)
  6. runOnUI(Runnable runnable)
  7. runWithTimeout(final Runnable runnable, long timeout, TimeUnit timeUnit)