Example usage for java.util.concurrent RejectedExecutionException RejectedExecutionException

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

Introduction

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

Prototype

public RejectedExecutionException(Throwable cause) 

Source Link

Document

Constructs a RejectedExecutionException with the specified cause.

Usage

From source file:org.apache.hadoop.hbase.client.crosssite.CrossSiteHTable.java

public static ThreadPoolExecutor getDefaultExecutor(Configuration conf) {
    int maxThreads = conf.getInt("hbase.crosssite.table.threads.max", Integer.MAX_VALUE);
    if (maxThreads <= 0) {
        maxThreads = Integer.MAX_VALUE;
    }//w w w .ja v a  2s .  co m
    final SynchronousQueue<Runnable> blockingQueue = new SynchronousQueue<Runnable>();
    RejectedExecutionHandler rejectHandler = new RejectedExecutionHandler() {

        @Override
        public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
            try {
                blockingQueue.put(r);
            } catch (InterruptedException e) {
                throw new RejectedExecutionException(e);
            }
        }
    };
    long keepAliveTime = conf.getLong("hbase.table.threads.keepalivetime", 60);
    ThreadPoolExecutor pool = new ThreadPoolExecutor(1, maxThreads, keepAliveTime, TimeUnit.SECONDS,
            blockingQueue, Threads.newDaemonThreadFactory("crosssite-hbase-table"), rejectHandler);
    ((ThreadPoolExecutor) pool).allowCoreThreadTimeOut(true);
    return pool;
}

From source file:org.apache.hadoop.hbase.client.crosssite.CrossSiteHBaseAdmin.java

public CrossSiteHBaseAdmin(Configuration conf) throws IOException, KeeperException {
    //    super();
    // create the connection to the global zk of the CrossSiteHBaseAdmin
    Configuration crossSiteZKConf = new Configuration(conf);
    ZKUtil.applyClusterKeyToConf(crossSiteZKConf, conf.get(CrossSiteConstants.CROSS_SITE_ZOOKEEPER));
    this.conf = crossSiteZKConf;
    zkw = new ZooKeeperWatcher(this.conf, "connection to global zookeeper", this, false);
    znodes = new CrossSiteZNodes(zkw);
    this.numRetries = this.conf.getInt("hbase.crosssite.client.retries.number", 5);
    this.retryLongerMultiplier = this.conf.getInt("hbase.crosssite.client.retries.longer.multiplier", 2);
    this.pause = this.conf.getLong("hbase.crosssite.client.pause", 1000);

    int poolSize = this.conf.getInt("hbase.crosssite.admin.pool.size", Integer.MAX_VALUE);
    if (poolSize <= 0) {
        poolSize = Integer.MAX_VALUE;
    }//from  w w w  . jav  a2s. c o  m
    final SynchronousQueue<Runnable> blockingQueue = new SynchronousQueue<Runnable>();
    RejectedExecutionHandler rejectHandler = new RejectedExecutionHandler() {
        @Override
        public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
            try {
                blockingQueue.put(r);
            } catch (InterruptedException e) {
                throw new RejectedExecutionException(e);
            }
        }
    };
    pool = new ThreadPoolExecutor(1, poolSize, 60, TimeUnit.SECONDS, blockingQueue,
            Threads.newDaemonThreadFactory("crosssite-hbase-admin-"), rejectHandler);
    ((ThreadPoolExecutor) pool).allowCoreThreadTimeOut(true);
}

From source file:com.alibaba.napoli.gecko.service.timer.HashedWheelTimer.java

public Timeout newTimeout(final TimerTask task, long delay, final TimeUnit unit) {
    final long currentTime = System.currentTimeMillis();

    if (task == null) {
        throw new NullPointerException("task");
    }//ww w . j a v a 2  s.  co  m
    if (unit == null) {
        throw new NullPointerException("unit");
    }

    delay = unit.toMillis(delay);
    if (delay < this.tickDuration) {
        delay = this.tickDuration;
    }

    if (!this.workerThread.isAlive()) {
        this.start();
    }

    if (this.size.get() >= this.maxTimerCapacity) {
        throw new RejectedExecutionException(
                "Timer size " + this.size + " is great than maxTimerCapacity " + this.maxTimerCapacity);
    }

    // Prepare the required parameters to create the timeout object.
    HashedWheelTimeout timeout;
    final long lastRoundDelay = delay % this.roundDuration;
    final long lastTickDelay = delay % this.tickDuration;

    final long relativeIndex = lastRoundDelay / this.tickDuration + (lastTickDelay != 0 ? 1 : 0);

    final long deadline = currentTime + delay;

    final long remainingRounds = delay / this.roundDuration - (delay % this.roundDuration == 0 ? 1 : 0);

    // Add the timeout to the wheel.
    this.lock.readLock().lock();
    try {
        timeout = new HashedWheelTimeout(task, deadline, (int) (this.wheelCursor + relativeIndex & this.mask),
                remainingRounds);

        this.wheel[timeout.stopIndex].add(timeout);
    } finally {
        this.lock.readLock().unlock();
    }
    this.size.incrementAndGet();

    return timeout;
}

From source file:org.voltdb.iv2.LeaderAppointer.java

@Override
public void acceptPromotion() throws InterruptedException, ExecutionException {
    final SettableFuture<Object> blocker = SettableFuture.create();
    try {/*from   ww w  .  j a v  a 2  s .co  m*/
        m_es.submit(new Runnable() {
            @Override
            public void run() {
                try {
                    acceptPromotionImpl(blocker);
                } catch (Throwable t) {
                    blocker.setException(t);
                }
            }
        });
        blocker.get();
    } catch (RejectedExecutionException e) {
        if (m_es.isShutdown())
            return;
        throw new RejectedExecutionException(e);
    }
}

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

/**
 * Creates a thread pool./* w ww .ja  va2s .c o  m*/
 * @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   w  w  w  .  java2  s  .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 a va  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;
}