Example usage for java.util.concurrent RejectedExecutionHandler RejectedExecutionHandler

List of usage examples for java.util.concurrent RejectedExecutionHandler RejectedExecutionHandler

Introduction

In this page you can find the example usage for java.util.concurrent RejectedExecutionHandler RejectedExecutionHandler.

Prototype

RejectedExecutionHandler

Source Link

Usage

From source file:com.sentaroh.android.TaskAutomation.TaskManager.java

static final public void buildTaskCtrlThreadPool(final EnvironmentParms envParms,
        final TaskManagerParms taskMgrParms, final CommonUtilities util) {
    if (taskMgrParms.taskControlThreadPool != null)
        removeTaskCtrlThreadPool(envParms, taskMgrParms, util);
    SynchronousQueue<Runnable> slq = new SynchronousQueue<Runnable>();
    RejectedExecutionHandler rh = new RejectedExecutionHandler() {
        @Override//  w w w .  ja  v  a2 s  .co m
        public void rejectedExecution(final Runnable r, ThreadPoolExecutor executor) {
            util.addDebugMsg(1, "W", "Task control reject handler entered.");
            envParms.statsUseOutsideThreadPoolCountTaskCtrl++;
            Thread th = new Thread() {
                @Override
                public void run() {
                    r.run();
                }
            };
            th.start();
        }
    };
    taskMgrParms.taskControlThreadPool = new ThreadPoolExecutor(TASK_CTRL_THREAD_POOL_COUNT,
            TASK_CTRL_THREAD_POOL_COUNT, 10, TimeUnit.SECONDS, slq, rh);
    for (int i = 0; i < TASK_CTRL_THREAD_POOL_COUNT; i++) {
        final int num = i + 1;
        Runnable rt = new Runnable() {
            @Override
            public void run() {
                Thread.currentThread().setPriority(THREAD_PRIORITY_TASK_CTRL);
                Thread.currentThread().setName("TaskCtrl-" + num);
            }
        };
        taskMgrParms.taskControlThreadPool.execute(rt);
    }
    taskMgrParms.taskControlThreadPool.prestartAllCoreThreads();
    util.addDebugMsg(1, "I", "Task control thread pool was created.");
}

From source file:org.apache.hadoop.hbase.mob.MobUtils.java

/**
 * Creates a thread pool.//from w  ww  .j a  v a 2 s. c  om
 * @param conf the Configuration
 * @return A thread pool.
 */
public static ExecutorService createMobCompactorThreadPool(Configuration conf) {
    int maxThreads = conf.getInt(MobConstants.MOB_COMPACTION_THREADS_MAX,
            MobConstants.DEFAULT_MOB_COMPACTION_THREADS_MAX);
    if (maxThreads == 0) {
        maxThreads = 1;
    }
    final SynchronousQueue<Runnable> queue = new SynchronousQueue<Runnable>();
    ThreadPoolExecutor pool = new ThreadPoolExecutor(1, maxThreads, 60, TimeUnit.SECONDS, queue,
            Threads.newDaemonThreadFactory("MobCompactor"), new RejectedExecutionHandler() {
                @Override
                public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
                    try {
                        // waiting for a thread to pick up instead of throwing exceptions.
                        queue.put(r);
                    } catch (InterruptedException e) {
                        throw new RejectedExecutionException(e);
                    }
                }
            });
    ((ThreadPoolExecutor) pool).allowCoreThreadTimeOut(true);
    return pool;
}

From source file:org.apache.hadoop.hbase.mob.compactions.TestPartitionedMobCompactor.java

private static ExecutorService createThreadPool() {
    int maxThreads = 10;
    long keepAliveTime = 60;
    final SynchronousQueue<Runnable> queue = new SynchronousQueue<Runnable>();
    ThreadPoolExecutor pool = new ThreadPoolExecutor(1, maxThreads, keepAliveTime, TimeUnit.SECONDS, queue,
            Threads.newDaemonThreadFactory("MobFileCompactionChore"), new RejectedExecutionHandler() {
                @Override/*from ww  w  . j ava 2s .  com*/
                public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
                    try {
                        // waiting for a thread to pick up instead of throwing exceptions.
                        queue.put(r);
                    } catch (InterruptedException e) {
                        throw new RejectedExecutionException(e);
                    }
                }
            });
    ((ThreadPoolExecutor) pool).allowCoreThreadTimeOut(true);
    return pool;
}

From source file:org.apache.hadoop.hbase.mob.compactions.TestMobCompactor.java

private static ExecutorService createThreadPool(Configuration conf) {
    int maxThreads = 10;
    long keepAliveTime = 60;
    final SynchronousQueue<Runnable> queue = new SynchronousQueue<Runnable>();
    ThreadPoolExecutor pool = new ThreadPoolExecutor(1, maxThreads, keepAliveTime, TimeUnit.SECONDS, queue,
            Threads.newDaemonThreadFactory("MobFileCompactionChore"), new RejectedExecutionHandler() {
                @Override// w  ww  . j av  a 2  s . c om
                public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
                    try {
                        // waiting for a thread to pick up instead of throwing exceptions.
                        queue.put(r);
                    } catch (InterruptedException e) {
                        throw new RejectedExecutionException(e);
                    }
                }
            });
    ((ThreadPoolExecutor) pool).allowCoreThreadTimeOut(true);
    return pool;
}