Example usage for java.util.concurrent SynchronousQueue put

List of usage examples for java.util.concurrent SynchronousQueue put

Introduction

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

Prototype

public void put(E e) throws InterruptedException 

Source Link

Document

Adds the specified element to this queue, waiting if necessary for another thread to receive it.

Usage

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.  j  a  v  a  2  s. 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);
            }
        }
    };
    pool = new ThreadPoolExecutor(1, poolSize, 60, TimeUnit.SECONDS, blockingQueue,
            Threads.newDaemonThreadFactory("crosssite-hbase-admin-"), rejectHandler);
    ((ThreadPoolExecutor) pool).allowCoreThreadTimeOut(true);
}

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;
    }//from   w  ww  . ja va  2 s  . c  om
    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.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 w w  .j  ava 2  s .co m*/
                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  ww.ja  v  a 2 s. co m
                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.MobUtils.java

/**
 * Creates a thread pool./*from   w  w  w  .j  ava 2 s  .  com*/
 * @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;
}