/** * Return whether the thread is the main thread. * * @return {@code true}: yes<br>{@code false}: no */ publicstaticbooleanisMainThread(){ return Looper.myLooper() == Looper.getMainLooper(); }
/** * Return a thread pool that reuses a fixed number of threads * operating off a shared unbounded queue, using the provided * ThreadFactory to create new threads when needed. * * @param size The size of thread in the pool. * @return a fixed thread pool */ publicstatic ExecutorService getFixedPool(@IntRange(from = 1)finalint size) { return getPoolByTypeAndPriority(size); }
/** * Return a thread pool that reuses a fixed number of threads * operating off a shared unbounded queue, using the provided * ThreadFactory to create new threads when needed. * * @param size The size of thread in the pool. * @param priority The priority of thread in the poll. * @return a fixed thread pool */ publicstatic ExecutorService getFixedPool(@IntRange(from = 1)finalint size, @IntRange(from = 1, to = 10)finalint priority) { return getPoolByTypeAndPriority(size, priority); }
/** * Return a thread pool that uses a single worker thread operating * off an unbounded queue, and uses the provided ThreadFactory to * create a new thread when needed. * * @return a single thread pool */ publicstatic ExecutorService getSinglePool(){ return getPoolByTypeAndPriority(TYPE_SINGLE); }
/** * Return a thread pool that uses a single worker thread operating * off an unbounded queue, and uses the provided ThreadFactory to * create a new thread when needed. * * @param priority The priority of thread in the poll. * @return a single thread pool */ publicstatic ExecutorService getSinglePool(@IntRange(from = 1, to = 10)finalint priority) { return getPoolByTypeAndPriority(TYPE_SINGLE, priority); }
/** * Return a thread pool that creates new threads as needed, but * will reuse previously constructed threads when they are * available. * * @return a cached thread pool */ publicstatic ExecutorService getCachedPool(){ return getPoolByTypeAndPriority(TYPE_CACHED); }
/** * Return a thread pool that creates new threads as needed, but * will reuse previously constructed threads when they are * available. * * @param priority The priority of thread in the poll. * @return a cached thread pool */ publicstatic ExecutorService getCachedPool(@IntRange(from = 1, to = 10)finalint priority) { return getPoolByTypeAndPriority(TYPE_CACHED, priority); }
/** * Return a thread pool that creates (2 * CPU_COUNT + 1) threads * operating off a queue which size is 128. * * @return a IO thread pool */ publicstatic ExecutorService getIoPool(){ return getPoolByTypeAndPriority(TYPE_CACHED); }
/** * Return a thread pool that creates (2 * CPU_COUNT + 1) threads * operating off a queue which size is 128. * * @param priority The priority of thread in the poll. * @return a IO thread pool */ publicstatic ExecutorService getIoPool(@IntRange(from = 1, to = 10)finalint priority) { return getPoolByTypeAndPriority(TYPE_CACHED, priority); }
/** * Return a thread pool that creates (CPU_COUNT + 1) threads * operating off a queue which size is 128 and the maximum * number of threads equals (2 * CPU_COUNT + 1). * * @return a cpu thread pool for */ publicstatic ExecutorService getCpuPool(){ return getPoolByTypeAndPriority(TYPE_CPU); }
/** * Return a thread pool that creates (CPU_COUNT + 1) threads * operating off a queue which size is 128 and the maximum * number of threads equals (2 * CPU_COUNT + 1). * * @param priority The priority of thread in the poll. * @return a cpu thread pool for */ publicstatic ExecutorService getCpuPool(@IntRange(from = 1, to = 10)finalint priority) { return getPoolByTypeAndPriority(TYPE_CPU, priority); }
/** * Executes the given task in a fixed thread pool. * * @param size The size of thread in the fixed thread pool. * @param task The task to execute. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByFixed(@IntRange(from = 1)finalint size, final Task<T> task) { execute(getPoolByTypeAndPriority(size), task); }
/** * Executes the given task in a fixed thread pool. * * @param size The size of thread in the fixed thread pool. * @param task The task to execute. * @param priority The priority of thread in the poll. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByFixed(@IntRange(from = 1)finalint size, final Task<T> task, @IntRange(from = 1, to = 10)finalint priority) { execute(getPoolByTypeAndPriority(size, priority), task); }
/** * Executes the given task in a fixed thread pool after the given delay. * * @param size The size of thread in the fixed thread pool. * @param task The task to execute. * @param delay The time from now to delay execution. * @param unit The time unit of the delay parameter. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByFixedWithDelay(@IntRange(from = 1)finalint size, final Task<T> task, finallong delay, final TimeUnit unit) { executeWithDelay(getPoolByTypeAndPriority(size), task, delay, unit); }
/** * Executes the given task in a fixed thread pool after the given delay. * * @param size The size of thread in the fixed thread pool. * @param task The task to execute. * @param delay The time from now to delay execution. * @param unit The time unit of the delay parameter. * @param priority The priority of thread in the poll. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByFixedWithDelay(@IntRange(from = 1)finalint size, final Task<T> task, finallong delay, final TimeUnit unit, @IntRange(from = 1, to = 10)finalint priority) { executeWithDelay(getPoolByTypeAndPriority(size, priority), task, delay, unit); }
/** * Executes the given task in a fixed thread pool at fix rate. * * @param size The size of thread in the fixed thread pool. * @param task The task to execute. * @param period The period between successive executions. * @param unit The time unit of the period parameter. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByFixedAtFixRate(@IntRange(from = 1)finalint size, final Task<T> task, finallong period, final TimeUnit unit) { executeAtFixedRate(getPoolByTypeAndPriority(size), task, 0, period, unit); }
/** * Executes the given task in a fixed thread pool at fix rate. * * @param size The size of thread in the fixed thread pool. * @param task The task to execute. * @param period The period between successive executions. * @param unit The time unit of the period parameter. * @param priority The priority of thread in the poll. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByFixedAtFixRate(@IntRange(from = 1)finalint size, final Task<T> task, finallong period, final TimeUnit unit, @IntRange(from = 1, to = 10)finalint priority) { executeAtFixedRate(getPoolByTypeAndPriority(size, priority), task, 0, period, unit); }
/** * Executes the given task in a fixed thread pool at fix rate. * * @param size The size of thread in the fixed thread pool. * @param task The task to execute. * @param initialDelay The time to delay first execution. * @param period The period between successive executions. * @param unit The time unit of the initialDelay and period parameters. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByFixedAtFixRate(@IntRange(from = 1)finalint size, final Task<T> task, long initialDelay, finallong period, final TimeUnit unit) { executeAtFixedRate(getPoolByTypeAndPriority(size), task, initialDelay, period, unit); }
/** * Executes the given task in a fixed thread pool at fix rate. * * @param size The size of thread in the fixed thread pool. * @param task The task to execute. * @param initialDelay The time to delay first execution. * @param period The period between successive executions. * @param unit The time unit of the initialDelay and period parameters. * @param priority The priority of thread in the poll. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByFixedAtFixRate(@IntRange(from = 1)finalint size, final Task<T> task, long initialDelay, finallong period, final TimeUnit unit, @IntRange(from = 1, to = 10)finalint priority) { executeAtFixedRate(getPoolByTypeAndPriority(size, priority), task, initialDelay, period, unit); }
/** * Executes the given task in a single thread pool. * * @param task The task to execute. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteBySingle(final Task<T> task){ execute(getPoolByTypeAndPriority(TYPE_SINGLE), task); }
/** * Executes the given task in a single thread pool. * * @param task The task to execute. * @param priority The priority of thread in the poll. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteBySingle(final Task<T> task, @IntRange(from = 1, to = 10)finalint priority) { execute(getPoolByTypeAndPriority(TYPE_SINGLE, priority), task); }
/** * Executes the given task in a single thread pool after the given delay. * * @param task The task to execute. * @param delay The time from now to delay execution. * @param unit The time unit of the delay parameter. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteBySingleWithDelay(final Task<T> task, finallong delay, final TimeUnit unit){ executeWithDelay(getPoolByTypeAndPriority(TYPE_SINGLE), task, delay, unit); }
/** * Executes the given task in a single thread pool after the given delay. * * @param task The task to execute. * @param delay The time from now to delay execution. * @param unit The time unit of the delay parameter. * @param priority The priority of thread in the poll. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteBySingleWithDelay(final Task<T> task, finallong delay, final TimeUnit unit, @IntRange(from = 1, to = 10)finalint priority) { executeWithDelay(getPoolByTypeAndPriority(TYPE_SINGLE, priority), task, delay, unit); }
/** * Executes the given task in a single thread pool at fix rate. * * @param task The task to execute. * @param period The period between successive executions. * @param unit The time unit of the period parameter. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteBySingleAtFixRate(final Task<T> task, finallong period, final TimeUnit unit){ executeAtFixedRate(getPoolByTypeAndPriority(TYPE_SINGLE), task, 0, period, unit); }
/** * Executes the given task in a single thread pool at fix rate. * * @param task The task to execute. * @param period The period between successive executions. * @param unit The time unit of the period parameter. * @param priority The priority of thread in the poll. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteBySingleAtFixRate(final Task<T> task, finallong period, final TimeUnit unit, @IntRange(from = 1, to = 10)finalint priority) { executeAtFixedRate(getPoolByTypeAndPriority(TYPE_SINGLE, priority), task, 0, period, unit); }
/** * Executes the given task in a single thread pool at fix rate. * * @param task The task to execute. * @param initialDelay The time to delay first execution. * @param period The period between successive executions. * @param unit The time unit of the initialDelay and period parameters. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteBySingleAtFixRate(final Task<T> task, long initialDelay, finallong period, final TimeUnit unit){ executeAtFixedRate(getPoolByTypeAndPriority(TYPE_SINGLE), task, initialDelay, period, unit); }
/** * Executes the given task in a single thread pool at fix rate. * * @param task The task to execute. * @param initialDelay The time to delay first execution. * @param period The period between successive executions. * @param unit The time unit of the initialDelay and period parameters. * @param priority The priority of thread in the poll. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteBySingleAtFixRate(final Task<T> task, long initialDelay, finallong period, final TimeUnit unit, @IntRange(from = 1, to = 10)finalint priority) { executeAtFixedRate( getPoolByTypeAndPriority(TYPE_SINGLE, priority), task, initialDelay, period, unit ); }
/** * Executes the given task in a cached thread pool. * * @param task The task to execute. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByCached(final Task<T> task){ execute(getPoolByTypeAndPriority(TYPE_CACHED), task); }
/** * Executes the given task in a cached thread pool. * * @param task The task to execute. * @param priority The priority of thread in the poll. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByCached(final Task<T> task, @IntRange(from = 1, to = 10)finalint priority) { execute(getPoolByTypeAndPriority(TYPE_CACHED, priority), task); }
/** * Executes the given task in a cached thread pool after the given delay. * * @param task The task to execute. * @param delay The time from now to delay execution. * @param unit The time unit of the delay parameter. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByCachedWithDelay(final Task<T> task, finallong delay, final TimeUnit unit){ executeWithDelay(getPoolByTypeAndPriority(TYPE_CACHED), task, delay, unit); }
/** * Executes the given task in a cached thread pool after the given delay. * * @param task The task to execute. * @param delay The time from now to delay execution. * @param unit The time unit of the delay parameter. * @param priority The priority of thread in the poll. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByCachedWithDelay(final Task<T> task, finallong delay, final TimeUnit unit, @IntRange(from = 1, to = 10)finalint priority) { executeWithDelay(getPoolByTypeAndPriority(TYPE_CACHED, priority), task, delay, unit); }
/** * Executes the given task in a cached thread pool at fix rate. * * @param task The task to execute. * @param period The period between successive executions. * @param unit The time unit of the period parameter. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByCachedAtFixRate(final Task<T> task, finallong period, final TimeUnit unit){ executeAtFixedRate(getPoolByTypeAndPriority(TYPE_CACHED), task, 0, period, unit); }
/** * Executes the given task in a cached thread pool at fix rate. * * @param task The task to execute. * @param period The period between successive executions. * @param unit The time unit of the period parameter. * @param priority The priority of thread in the poll. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByCachedAtFixRate(final Task<T> task, finallong period, final TimeUnit unit, @IntRange(from = 1, to = 10)finalint priority) { executeAtFixedRate(getPoolByTypeAndPriority(TYPE_CACHED, priority), task, 0, period, unit); }
/** * Executes the given task in a cached thread pool at fix rate. * * @param task The task to execute. * @param initialDelay The time to delay first execution. * @param period The period between successive executions. * @param unit The time unit of the initialDelay and period parameters. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByCachedAtFixRate(final Task<T> task, long initialDelay, finallong period, final TimeUnit unit){ executeAtFixedRate(getPoolByTypeAndPriority(TYPE_CACHED), task, initialDelay, period, unit); }
/** * Executes the given task in a cached thread pool at fix rate. * * @param task The task to execute. * @param initialDelay The time to delay first execution. * @param period The period between successive executions. * @param unit The time unit of the initialDelay and period parameters. * @param priority The priority of thread in the poll. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByCachedAtFixRate(final Task<T> task, long initialDelay, finallong period, final TimeUnit unit, @IntRange(from = 1, to = 10)finalint priority) { executeAtFixedRate( getPoolByTypeAndPriority(TYPE_CACHED, priority), task, initialDelay, period, unit ); }
/** * Executes the given task in an IO thread pool. * * @param task The task to execute. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByIo(final Task<T> task){ execute(getPoolByTypeAndPriority(TYPE_IO), task); }
/** * Executes the given task in an IO thread pool. * * @param task The task to execute. * @param priority The priority of thread in the poll. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByIo(final Task<T> task, @IntRange(from = 1, to = 10)finalint priority) { execute(getPoolByTypeAndPriority(TYPE_IO, priority), task); }
/** * Executes the given task in an IO thread pool after the given delay. * * @param task The task to execute. * @param delay The time from now to delay execution. * @param unit The time unit of the delay parameter. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByIoWithDelay(final Task<T> task, finallong delay, final TimeUnit unit){ executeWithDelay(getPoolByTypeAndPriority(TYPE_IO), task, delay, unit); }
/** * Executes the given task in an IO thread pool after the given delay. * * @param task The task to execute. * @param delay The time from now to delay execution. * @param unit The time unit of the delay parameter. * @param priority The priority of thread in the poll. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByIoWithDelay(final Task<T> task, finallong delay, final TimeUnit unit, @IntRange(from = 1, to = 10)finalint priority) { executeWithDelay(getPoolByTypeAndPriority(TYPE_IO, priority), task, delay, unit); }
/** * Executes the given task in an IO thread pool at fix rate. * * @param task The task to execute. * @param period The period between successive executions. * @param unit The time unit of the period parameter. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByIoAtFixRate(final Task<T> task, finallong period, final TimeUnit unit){ executeAtFixedRate(getPoolByTypeAndPriority(TYPE_IO), task, 0, period, unit); }
/** * Executes the given task in an IO thread pool at fix rate. * * @param task The task to execute. * @param period The period between successive executions. * @param unit The time unit of the period parameter. * @param priority The priority of thread in the poll. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByIoAtFixRate(final Task<T> task, finallong period, final TimeUnit unit, @IntRange(from = 1, to = 10)finalint priority) { executeAtFixedRate(getPoolByTypeAndPriority(TYPE_IO, priority), task, 0, period, unit); }
/** * Executes the given task in an IO thread pool at fix rate. * * @param task The task to execute. * @param initialDelay The time to delay first execution. * @param period The period between successive executions. * @param unit The time unit of the initialDelay and period parameters. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByIoAtFixRate(final Task<T> task, long initialDelay, finallong period, final TimeUnit unit){ executeAtFixedRate(getPoolByTypeAndPriority(TYPE_IO), task, initialDelay, period, unit); }
/** * Executes the given task in an IO thread pool at fix rate. * * @param task The task to execute. * @param initialDelay The time to delay first execution. * @param period The period between successive executions. * @param unit The time unit of the initialDelay and period parameters. * @param priority The priority of thread in the poll. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByIoAtFixRate(final Task<T> task, long initialDelay, finallong period, final TimeUnit unit, @IntRange(from = 1, to = 10)finalint priority) { executeAtFixedRate( getPoolByTypeAndPriority(TYPE_IO, priority), task, initialDelay, period, unit ); }
/** * Executes the given task in a cpu thread pool. * * @param task The task to execute. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByCpu(final Task<T> task){ execute(getPoolByTypeAndPriority(TYPE_CPU), task); }
/** * Executes the given task in a cpu thread pool. * * @param task The task to execute. * @param priority The priority of thread in the poll. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByCpu(final Task<T> task, @IntRange(from = 1, to = 10)finalint priority) { execute(getPoolByTypeAndPriority(TYPE_CPU, priority), task); }
/** * Executes the given task in a cpu thread pool after the given delay. * * @param task The task to execute. * @param delay The time from now to delay execution. * @param unit The time unit of the delay parameter. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByCpuWithDelay(final Task<T> task, finallong delay, final TimeUnit unit){ executeWithDelay(getPoolByTypeAndPriority(TYPE_CPU), task, delay, unit); }
/** * Executes the given task in a cpu thread pool after the given delay. * * @param task The task to execute. * @param delay The time from now to delay execution. * @param unit The time unit of the delay parameter. * @param priority The priority of thread in the poll. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByCpuWithDelay(final Task<T> task, finallong delay, final TimeUnit unit, @IntRange(from = 1, to = 10)finalint priority) { executeWithDelay(getPoolByTypeAndPriority(TYPE_CPU, priority), task, delay, unit); }
/** * Executes the given task in a cpu thread pool at fix rate. * * @param task The task to execute. * @param period The period between successive executions. * @param unit The time unit of the period parameter. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByCpuAtFixRate(final Task<T> task, finallong period, final TimeUnit unit){ executeAtFixedRate(getPoolByTypeAndPriority(TYPE_CPU), task, 0, period, unit); }
/** * Executes the given task in a cpu thread pool at fix rate. * * @param task The task to execute. * @param period The period between successive executions. * @param unit The time unit of the period parameter. * @param priority The priority of thread in the poll. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByCpuAtFixRate(final Task<T> task, finallong period, final TimeUnit unit, @IntRange(from = 1, to = 10)finalint priority) { executeAtFixedRate(getPoolByTypeAndPriority(TYPE_CPU, priority), task, 0, period, unit); }
/** * Executes the given task in a cpu thread pool at fix rate. * * @param task The task to execute. * @param initialDelay The time to delay first execution. * @param period The period between successive executions. * @param unit The time unit of the initialDelay and period parameters. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByCpuAtFixRate(final Task<T> task, long initialDelay, finallong period, final TimeUnit unit){ executeAtFixedRate(getPoolByTypeAndPriority(TYPE_CPU), task, initialDelay, period, unit); }
/** * Executes the given task in a cpu thread pool at fix rate. * * @param task The task to execute. * @param initialDelay The time to delay first execution. * @param period The period between successive executions. * @param unit The time unit of the initialDelay and period parameters. * @param priority The priority of thread in the poll. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByCpuAtFixRate(final Task<T> task, long initialDelay, finallong period, final TimeUnit unit, @IntRange(from = 1, to = 10)finalint priority) { executeAtFixedRate( getPoolByTypeAndPriority(TYPE_CPU, priority), task, initialDelay, period, unit ); }
/** * Executes the given task in a custom thread pool. * * @param pool The custom thread pool. * @param task The task to execute. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByCustom(final ExecutorService pool, final Task<T> task){ execute(pool, task); }
/** * Executes the given task in a custom thread pool after the given delay. * * @param pool The custom thread pool. * @param task The task to execute. * @param delay The time from now to delay execution. * @param unit The time unit of the delay parameter. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByCustomWithDelay(final ExecutorService pool, final Task<T> task, finallong delay, final TimeUnit unit){ executeWithDelay(pool, task, delay, unit); }
/** * Executes the given task in a custom thread pool at fix rate. * * @param pool The custom thread pool. * @param task The task to execute. * @param period The period between successive executions. * @param unit The time unit of the period parameter. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByCustomAtFixRate(final ExecutorService pool, final Task<T> task, finallong period, final TimeUnit unit){ executeAtFixedRate(pool, task, 0, period, unit); }
/** * Executes the given task in a custom thread pool at fix rate. * * @param pool The custom thread pool. * @param task The task to execute. * @param initialDelay The time to delay first execution. * @param period The period between successive executions. * @param unit The time unit of the initialDelay and period parameters. * @param <T> The type of the task's result. */ publicstatic <T> voidexecuteByCustomAtFixRate(final ExecutorService pool, final Task<T> task, long initialDelay, finallong period, final TimeUnit unit){ executeAtFixedRate(pool, task, initialDelay, period, unit); }
/** * Cancel the given task. * * @param task The task to cancel. */ publicstaticvoidcancel(final Task task){ task.cancel(); }
privatestatic <T> voidexecute(final ExecutorService pool, final Task<T> task){ executeWithDelay(pool, task, 0, TimeUnit.MILLISECONDS); }