Example usage for java.util.concurrent ThreadPoolExecutor.CallerRunsPolicy ThreadPoolExecutor.CallerRunsPolicy

List of usage examples for java.util.concurrent ThreadPoolExecutor.CallerRunsPolicy ThreadPoolExecutor.CallerRunsPolicy

Introduction

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

Prototype

ThreadPoolExecutor.CallerRunsPolicy

Source Link

Usage

From source file:Main.java

@Deprecated
public static ExecutorService newFixedThreadPool(int nThreads) {
    ThreadPoolExecutor exec = new ThreadPoolExecutor(nThreads, nThreads, 0L, TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<Runnable>(nThreads));
    exec.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
    return exec;/*from   w  w  w. j a  v  a 2  s . co m*/
}

From source file:org.apache.streams.elasticsearch.example.ElasticsearchDelete.java

private static ExecutorService newFixedThreadPoolWithQueueSize(int nThreads, int queueSize) {
    return new ThreadPoolExecutor(nThreads, nThreads, 5000L, TimeUnit.MILLISECONDS,
            new ArrayBlockingQueue<Runnable>(queueSize, true), new ThreadPoolExecutor.CallerRunsPolicy());
}

From source file:com.oneops.util.ReliableExecutor.java

public ReliableExecutor(int threadPoolSize, boolean doSyncOnRejection) {
    this.threadPoolSize = threadPoolSize;
    RejectedExecutionHandler handler;
    if (doSyncOnRejection) {
        handler = new ThreadPoolExecutor.CallerRunsPolicy();
    } else {/*ww  w. j a v  a2s  .  c  o m*/
        handler = new ThreadPoolExecutor.AbortPolicy();
    }
    executors = new ThreadPoolExecutor(0, threadPoolSize, 60L, TimeUnit.SECONDS,
            new SynchronousQueue<Runnable>(), handler);
}

From source file:com.splicemachine.derby.stream.control.ControlDataSet.java

@Override
public DataSet<V> union(DataSet<V> dataSet) {
    ThreadPoolExecutor tpe = null;
    try {//from w  w w .j  a v a 2  s . com

        ThreadFactory factory = new ThreadFactoryBuilder().setNameFormat("union-begin-query-%d")
                .setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
                    @Override
                    public void uncaughtException(Thread t, Throwable e) {
                        e.printStackTrace();
                    }
                }).build();
        tpe = new ThreadPoolExecutor(2, 2, 60, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), factory,
                new ThreadPoolExecutor.CallerRunsPolicy());
        tpe.allowCoreThreadTimeOut(false);
        tpe.prestartAllCoreThreads();
        Future<Iterator<V>> leftSideFuture = tpe.submit(new NonLazy(iterator));
        Future<Iterator<V>> rightSideFuture = tpe.submit(new NonLazy(((ControlDataSet<V>) dataSet).iterator));

        return new ControlDataSet<>(Iterators.concat(leftSideFuture.get(), rightSideFuture.get()));
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        if (tpe != null)
            tpe.shutdown();
    }
}

From source file:ca.gnewton.lusql.core.LuSql.java

void initThreadPoolExecutor() {
    if (numThreads < minThreadPoolThreads)
        minThreadPoolThreads = numThreads;

    recordQueue = new ArrayBlockingQueue<Runnable>(makeQueueSize());
    //threadPoolExecutor = new ThreadPoolExecutor(2,
    if (threadPoolExecutor == null)
        threadPoolExecutor = new AddDocumentExecutor(minThreadPoolThreads, numThreads, 16l, TimeUnit.SECONDS,
                recordQueue, new ThreadPoolExecutor.CallerRunsPolicy(), this);
}