Create FutureTask from Runnable - Android java.util.concurrent

Android examples for java.util.concurrent:FutureTask

Description

Create FutureTask from Runnable

Demo Code


//package com.java2s;

import android.support.annotation.NonNull;
import java.util.concurrent.FutureTask;

public class Main {
    public static FutureTask backgroundThread(
            @NonNull final Runnable runnable) {
        final FutureTask<Void> futureTask = new FutureTask<>(
                new Runnable() {
                    @Override/*from   w ww .j a  v  a2  s  .c  o  m*/
                    public void run() {
                        new Thread(runnable).start();
                    }
                }, null);
        futureTask.run();
        return futureTask;
    }
}

Related Tutorials