Example usage for java.util.concurrent ArrayBlockingQueue ArrayBlockingQueue

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

Introduction

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

Prototype

public ArrayBlockingQueue(int capacity, boolean fair) 

Source Link

Document

Creates an ArrayBlockingQueue with the given (fixed) capacity and the specified access policy.

Usage

From source file:org.rifidi.emulator.common.DataBuffer.java

/**
 * A basic constructor for a data buffer. It takes in a maximum size
 * variable and a first-in, first-out selection variable.
 * // w  w  w. j  av  a 2s .c  om
 * @param maxBufferSize
 *            The maximum number of elements the buffer can hold before
 *            being full.
 */
public DataBuffer(int maxBufferSize) {
    /* Make a new FIFO queue */
    this.theQueue = new ArrayBlockingQueue<T>(maxBufferSize, true);

    /* Place the buffer in normal operating mode. */
    this.suspended = false;
    this.suspendAdds = false;
    this.interrupted = false;

}

From source file:AIR.Common.Threading.BoundedThreadPool.java

public BoundedThreadPool(int threadCount, String threadPoolName, int highWaterMark, int lowWaterMark,
        IThreadPoolStatsRecorder statsRecorder) {
    if (threadCount <= 0) {
        threadCount = Math.max(_numberOfProcessors, 2);
    }/*from  w ww.j  a  v  a2s.  c o  m*/
    _name = StringUtils.defaultString(threadPoolName);
    _taskQHighWaterMark = highWaterMark <= 0 ? Integer.MAX_VALUE : highWaterMark;
    _taskQLowWaterMark = lowWaterMark <= 0 ? highWaterMark : lowWaterMark;
    if (lowWaterMark > highWaterMark) {
        throw new IllegalArgumentException("The low watermark cannot be larger than the high watermark");
    }

    if (statsRecorder != null) {
        statsRecorder.setThreadPool(this);
    }
    _statsRecorder = statsRecorder;
    _taskQueue = new ArrayBlockingQueue<>(_taskQHighWaterMark, true);
    ThreadFactory threadFactory = new NamedThreadFactory();
    _workerThreadPool = new ThreadPoolExecutor(threadCount, threadCount, 0, TimeUnit.NANOSECONDS, _taskQueue,
            threadFactory);
    synchronized (_statusLock) {
        _workerThreadPool.prestartAllCoreThreads();
        _status = ThreadPoolStatus.Active;
    }
}

From source file:com.streamsets.datacollector.execution.runner.common.TestRulesConfigLoader.java

@Before
public void setUp() {
    productionObserveRequests = new ArrayBlockingQueue<>(10, true /*FIFO*/);
    observer = new ProductionObserver(new Configuration(), null);
    observer.setObserveRequests(productionObserveRequests);
}

From source file:com.ning.metrics.collector.processing.db.FeedEventSpoolProcessor.java

@Inject
public FeedEventSpoolProcessor(final CollectorConfig config, final SubscriptionStorage subscriptionStorage,
        final FeedEventStorage feedEventStorage, final Scheduler quartzScheduler) throws SchedulerException {
    this.config = config;
    this.subscriptionStorage = subscriptionStorage;
    this.feedEventStorage = feedEventStorage;
    this.eventStorageBuffer = new ArrayBlockingQueue<FeedEvent>(1000, false);
    this.executorShutdownTimeOut = config.getSpoolWriterExecutorShutdownTime();
    this.quartzScheduler = quartzScheduler;

    final List<String> eventTypesList = Splitter.on(config.getFilters()).omitEmptyStrings()
            .splitToList(config.getFiltersEventType());
    if (eventTypesList.contains(DBStorageTypes.FEED_EVENT.getDbStorageType())) {
        this.executorService = new LoggingExecutor(1, 1, Long.MAX_VALUE, TimeUnit.DAYS,
                new ArrayBlockingQueue<Runnable>(2), new NamedThreadFactory("FeedEvents-Storage-Threads"),
                new ThreadPoolExecutor.CallerRunsPolicy());
        this.executorService.submit(new FeedEventInserter(this.executorService, this));

        if (!quartzScheduler.isStarted()) {
            quartzScheduler.start();//from ww  w  . j  a  v a 2s.c om
            scheduleFeedEventCleanupCronJob();
        }
    } else {
        this.executorService = null;
    }

}

From source file:org.archive.io.WriterPool.java

/**
 * Constructor//w w w . ja  v  a  2 s.c om
 * @param serial  Used to generate unique filename sequences
 * @param factory Factory that knows how to make a {@link WriterPoolMember}.
 * @param settings Settings for this pool.
 * @param poolMaximumActive
 * @param poolMaximumWait
 */
public WriterPool(final AtomicInteger serial, final WriterPoolSettings settings, final int poolMaximumActive,
        final int poolMaximumWait) {
    logger.info("Initial configuration:" + " prefix=" + settings.getPrefix() + ", template="
            + settings.getTemplate() + ", compress=" + settings.getCompress() + ", maxSize="
            + settings.getMaxFileSizeBytes() + ", maxActive=" + poolMaximumActive + ", maxWait="
            + poolMaximumWait);
    this.settings = settings;
    this.maxActive = poolMaximumActive;
    this.maxWait = poolMaximumWait;
    availableWriters = new ArrayBlockingQueue<WriterPoolMember>(LARGEST_MAX_ACTIVE, true);
    this.serialNo = serial;
}

From source file:com.jkoolcloud.tnt4j.streams.inputs.AbstractBufferedStream.java

@Override
protected void initialize() throws Exception {
    inputBuffer = new ArrayBlockingQueue<>(bufferSize, true);

    super.initialize();
}

From source file:org.apache.streams.facebook.provider.FacebookFriendFeedProvider.java

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

From source file:org.jiemamy.utils.collection.CollectionsUtil.java

/**
 * {@link ArrayBlockingQueue}?????//from   w w w . j  a  va  2 s  .c  o  m
 * 
 * @param <E> {@link ArrayBlockingQueue}??
 * @param capacity ??
 * @param fair {@code true}???????????
 * @return {@link ArrayBlockingQueue}???
 * @see ArrayBlockingQueue#ArrayBlockingQueue(int, boolean)
 */
public static <E> ArrayBlockingQueue<E> newArrayBlockingQueue(int capacity, boolean fair) {
    return new ArrayBlockingQueue<E>(capacity, fair);
}

From source file:org.apache.streams.twitter.provider.TwitterUserInformationProvider.java

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

From source file:org.apache.solr.handler.component.AlfrescoHttpShardHandlerFactory.java

@Override
public void init(PluginInfo info) {
    NamedList args = info.initArgs;/*from www . j a  v  a 2s  . c o  m*/
    this.soTimeout = getParameter(args, HttpClientUtil.PROP_SO_TIMEOUT, soTimeout);
    this.scheme = getParameter(args, INIT_URL_SCHEME, null);
    if (StringUtils.endsWith(this.scheme, "://")) {
        this.scheme = StringUtils.removeEnd(this.scheme, "://");
    }
    this.connectionTimeout = getParameter(args, HttpClientUtil.PROP_CONNECTION_TIMEOUT, connectionTimeout);
    this.maxConnectionsPerHost = getParameter(args, HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST,
            maxConnectionsPerHost);
    this.corePoolSize = getParameter(args, INIT_CORE_POOL_SIZE, corePoolSize);
    this.maximumPoolSize = getParameter(args, INIT_MAX_POOL_SIZE, maximumPoolSize);
    this.keepAliveTime = getParameter(args, MAX_THREAD_IDLE_TIME, keepAliveTime);
    this.queueSize = getParameter(args, INIT_SIZE_OF_QUEUE, queueSize);
    this.accessPolicy = getParameter(args, INIT_FAIRNESS_POLICY, accessPolicy);

    // magic sysprop to make tests reproducible: set by SolrTestCaseJ4.
    String v = System.getProperty("tests.shardhandler.randomSeed");
    if (v != null) {
        r.setSeed(Long.parseLong(v));
    }

    BlockingQueue<Runnable> blockingQueue = (this.queueSize == -1)
            ? new SynchronousQueue<Runnable>(this.accessPolicy)
            : new ArrayBlockingQueue<Runnable>(this.queueSize, this.accessPolicy);

    this.commExecutor = new ThreadPoolExecutor(this.corePoolSize, this.maximumPoolSize, this.keepAliveTime,
            TimeUnit.SECONDS, blockingQueue, new DefaultSolrThreadFactory("httpShardExecutor"));

    ModifiableSolrParams clientParams = new ModifiableSolrParams();
    clientParams.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, maxConnectionsPerHost);
    clientParams.set(HttpClientUtil.PROP_MAX_CONNECTIONS, 10000);
    clientParams.set(HttpClientUtil.PROP_SO_TIMEOUT, soTimeout);
    clientParams.set(HttpClientUtil.PROP_CONNECTION_TIMEOUT, connectionTimeout);
    clientParams.set(HttpClientUtil.PROP_USE_RETRY, false);
    this.defaultClient = HttpClientUtil.createClient(clientParams);
    this.loadbalancer = createLoadbalancer(defaultClient);
}