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) 

Source Link

Document

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

Usage

From source file:org.flowable.engine.impl.asyncexecutor.DefaultAsyncJobExecutor.java

protected void initAsyncJobExecutionThreadPool() {
    if (threadPoolQueue == null) {
        log.info("Creating thread pool queue of size {}", queueSize);
        threadPoolQueue = new ArrayBlockingQueue<Runnable>(queueSize);
    }//ww  w.  j  a v a 2 s  .c  o  m

    if (executorService == null) {
        log.info("Creating executor service with corePoolSize {}, maxPoolSize {} and keepAliveTime {}",
                corePoolSize, maxPoolSize, keepAliveTime);

        BasicThreadFactory threadFactory = new BasicThreadFactory.Builder()
                .namingPattern("flowable-async-job-executor-thread-%d").build();
        executorService = new ThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveTime,
                TimeUnit.MILLISECONDS, threadPoolQueue, threadFactory);
    }

    if (unlockOwnedJobs) {
        unlockOwnedJobs();
    }
}

From source file:org.htrace.impl.HBaseSpanReceiver.java

public HBaseSpanReceiver() {
    this.queue = new ArrayBlockingQueue<Span>(1000);
    this.tf = new ThreadFactoryBuilder().setDaemon(true).setNameFormat("hbaseSpanReceiver-%d").build();
}

From source file:com.flipkart.poseidon.Poseidon.java

public void start() {
    try {//w  w  w. j  av a 2 s.c om
        JettyConfiguration jettyConfiguration = configuration.getJettyConfiguration();
        if (jettyConfiguration != null) {
            // Use a bounded queue over jetty's default unbounded queue
            // https://wiki.eclipse.org/Jetty/Howto/High_Load#Thread_Pool
            BlockingQueue<Runnable> queue = new ArrayBlockingQueue<>(jettyConfiguration.getTaskQueueSize());
            QueuedThreadPool threadPool = new QueuedThreadPool(jettyConfiguration.getMaxThreads(),
                    jettyConfiguration.getMinThreads(), jettyConfiguration.getThreadIdleTimeout(), queue);
            server = new Server(threadPool);
            ServerConnector connector = new ServerConnector(server, jettyConfiguration.getAcceptors(),
                    jettyConfiguration.getSelectors(),
                    Optional.ofNullable(jettyConfiguration.getHttpConnectionFactory())
                            .orElseGet(HttpConnectionFactory::new));
            connector.setPort(configuration.getPort());
            connector.setAcceptQueueSize(jettyConfiguration.getAcceptQueueSize());
            server.setConnectors(new Connector[] { connector });
        } else {
            server = new Server(configuration.getPort());
        }
        if (!configuration.sendServerVersion()) {
            disableSendingServerVersion();
        }

        server.setHandler(getHandlers());
        application.init(dataSourceES, filterES);
        initializeMetricReporters();

        server.start();
        STARTUP_LOGGER.info("*** Poseidon started ***");
    } catch (Exception e) {
        STARTUP_LOGGER.error("Unable to start Poseidon.", e);
        throw new RuntimeException("Unable to start Poseidon", e);
    }
}

From source file:org.sourceopen.hadoop.hbase.replication.consumer.FileChannelManager.java

public void start() throws Exception {
    init();//ww w  . j ava  2s  .  c  o m
    scanProducerFilesAndAddToZK();
    FileChannelRunnable runn;
    dataLoadingManager.setConf(conf);
    dataLoadingManager.init();
    for (int i = 1; i < conf.getInt(ConsumerConstants.CONFKEY_REP_FILE_CHANNEL_POOL_SIZE, 10); i++) {
        runn = new FileChannelRunnable(conf, dataLoadingManager, adapter, stopflag);
        runn.setZoo(zoo);
        fileChannelPool.execute(runn);
    }

    crushPool = new ThreadPoolExecutor(
            conf.getInt(ProducerConstants.CONFKEY_REP_REJECT_POOL_SIZE, ProducerConstants.REP_REJECT_POOL_SIZE),
            conf.getInt(ProducerConstants.CONFKEY_REP_REJECT_POOL_SIZE, ProducerConstants.REP_REJECT_POOL_SIZE),
            conf.getInt(ProducerConstants.CONFKEY_THREADPOOL_KEEPALIVE_TIME, 100), TimeUnit.SECONDS,
            new ArrayBlockingQueue<Runnable>(conf.getInt(ProducerConstants.CONFKEY_THREADPOOL_SIZE, 100)));
    CrushScanner crush;
    for (int i = 0; i < conf.getInt(ProducerConstants.CONFKEY_REP_REJECT_POOL_SIZE,
            ProducerConstants.REP_REJECT_POOL_SIZE); i++) {
        crush = CrushScanner.newInstance(conf, zoo);
        crushPool.execute(crush);
    }

    while (true) {
        try {
            Thread.sleep(5000);
            scanProducerFilesAndAddToZK();
        } catch (IOException e) {
            if (LOG.isErrorEnabled()) {
                LOG.error("scanProducerFilesAndAddToZK error while looping.", e);
            }
        } catch (InterruptedException e) {
            LOG.warn("FileChannelManager sleep interrupted.Break the loop!");
            break;
        }
    }
}

From source file:com.datatorrent.lib.io.jms.AbstractJMSInputOperator.java

public AbstractJMSInputOperator() {
    counters = new BasicCounters<MutableLong>(MutableLong.class);
    throwable = new AtomicReference<Throwable>();
    pendingAck = Sets.newHashSet();// w ww.j a  v  a  2 s .c o  m
    windowDataManager = new FSWindowDataManager();

    lock = new Lock();

    //Recovery state is a linked hash map to maintain the order of tuples.
    currentWindowRecoveryState = Maps.newLinkedHashMap();
    holdingBuffer = new ArrayBlockingQueue<Message>(bufferSize) {
        private static final long serialVersionUID = 201411151139L;

        @SuppressWarnings("Contract")
        @Override
        public boolean add(Message message) {
            synchronized (lock) {
                try {
                    return messageConsumed(message) && super.add(message);
                } catch (JMSException e) {
                    LOG.error("message consumption", e);
                    throwable.set(e);
                    throw new RuntimeException(e);
                }
            }
        }
    };
}

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

/**
 * {@link ArrayBlockingQueue}?????//w w w .  j ava  2s  . c  om
 * 
 * @param <E> {@link ArrayBlockingQueue}??
 * @param capacity ??
 * @return {@link ArrayBlockingQueue}???
 * @see ArrayBlockingQueue#ArrayBlockingQueue(int)
 */
public static <E> ArrayBlockingQueue<E> newArrayBlockingQueue(int capacity) {
    return new ArrayBlockingQueue<E>(capacity);
}

From source file:org.opentripplanner.routing.algorithm.strategies.WeightTable.java

/**
 * Build the weight table, parallelized according to the number of processors 
 *//* ww w . j a  v a 2 s  .  c o  m*/
public void buildTable() {
    ArrayList<TransitStop> stopVertices;

    LOG.debug("Number of vertices: " + g.getVertices().size());
    stopVertices = new ArrayList<TransitStop>();
    for (Vertex gv : g.getVertices())
        if (gv instanceof TransitStop)
            stopVertices.add((TransitStop) gv);
    int nStops = stopVertices.size();

    stopIndices = new IdentityHashMap<Vertex, Integer>(nStops);
    for (int i = 0; i < nStops; i++)
        stopIndices.put(stopVertices.get(i), i);
    LOG.debug("Number of stops: " + nStops);

    table = new float[nStops][nStops];
    for (float[] row : table)
        Arrays.fill(row, Float.POSITIVE_INFINITY);

    LOG.debug("Performing search at each transit stop.");

    int nThreads = Runtime.getRuntime().availableProcessors();
    LOG.debug("number of threads: " + nThreads);
    ArrayBlockingQueue<Runnable> taskQueue = new ArrayBlockingQueue<Runnable>(nStops);
    ThreadPoolExecutor threadPool = new ThreadPoolExecutor(nThreads, nThreads, 10, TimeUnit.SECONDS, taskQueue);
    GenericObjectPool heapPool = new GenericObjectPool(
            new PoolableBinHeapFactory<State>(g.getVertices().size()), nThreads);

    // make one heap and recycle it
    RoutingRequest options = new RoutingRequest();
    // TODO LG Check this change:
    options.setWalkSpeed(maxWalkSpeed);
    final double MAX_WEIGHT = 60 * 60 * options.walkReluctance;
    final double OPTIMISTIC_BOARD_COST = options.getBoardCostLowerBound();

    // create a task for each transit stop in the graph
    ArrayList<Callable<Void>> tasks = new ArrayList<Callable<Void>>();
    for (TransitStop origin : stopVertices) {
        SPTComputer task = new SPTComputer(heapPool, options, MAX_WEIGHT, OPTIMISTIC_BOARD_COST, origin);
        tasks.add(task);
    }
    try {
        //invoke all of tasks.
        threadPool.invokeAll(tasks);
        threadPool.shutdown();
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
    floyd();
}

From source file:com.alibaba.napoli.metamorphosis.client.extension.producer.LocalMessageStorageManager.java

public LocalMessageStorageManager(final MetaClientConfig metaClientConfig, final String path,
        final MessageRecoverer messageRecoverer) {
    super();// w  w w.ja  va 2s  . c o  m
    this.META_LOCALMESSAGE_PATH = StringUtils.isNotBlank(path) ? path : DEFAULT_META_LOCALMESSAGE_PATH;
    this.messageRecoverer = messageRecoverer;

    if (this.META_LOCALMESSAGE_CODEC_TYPE.equals("java")) {
        this.serializer = new JavaSerializer();
        this.deserializer = new JavaDeserializer();
    } else if (this.META_LOCALMESSAGE_CODEC_TYPE.equals("hessian1")) {
        this.serializer = new Hessian1Serializer();
        this.deserializer = new Hessian1Deserializer();
    } else {
        throw new UnknowCodecTypeException(this.META_LOCALMESSAGE_CODEC_TYPE);
    }

    // ?RecoverThreadCount
    this.threadPoolExecutor = new ThreadPoolExecutor(metaClientConfig.getRecoverThreadCount(),
            metaClientConfig.getRecoverThreadCount(), 60, TimeUnit.SECONDS,
            new ArrayBlockingQueue<Runnable>(100), new NamedThreadFactory("SendRecover-thread"),
            new ThreadPoolExecutor.CallerRunsPolicy());

    this.makeDataDir();
    this.loadStores();

    // ????,??topic???
    this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
        @Override
        public void run() {
            log.info("????...");
            LocalMessageStorageManager.this.recover();
        }
    }, 0, metaClientConfig.getRecoverMessageIntervalInMills(), TimeUnit.MILLISECONDS);

}

From source file:ubic.gemma.loader.genome.goldenpath.GoldenPathBioSequenceLoader.java

/**
 * Load from a database source.//from   w w w.j  a  v  a2  s .  co m
 * 
 * @param dumper
 */
public void load(final GoldenPathDumper dumper) {
    final BlockingQueue<BioSequence> queue = new ArrayBlockingQueue<BioSequence>(QUEUE_SIZE);

    final SecurityContext context = SecurityContextHolder.getContext();
    assert context != null;
    Thread parseThread = new Thread(new Runnable() {
        @Override
        public void run() {
            dumper.dumpTranscriptBioSequences(limit, queue);
            log.info("Done dumping");
            producerDone = true;
        }
    }, "Parser");

    parseThread.start();

    Thread loadThread = new Thread(new Runnable() {
        @Override
        public void run() {
            SecurityContextHolder.setContext(context);
            log.info("Starting loading");
            load(queue);
        }
    }, "Loader");

    loadThread.start();

    while (!producerDone || !consumerDone) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

From source file:org.apache.htrace.impl.ZipkinSpanReceiver.java

public ZipkinSpanReceiver(HTraceConfiguration conf) {
    this.transport = createTransport(conf);
    this.queue = new ArrayBlockingQueue<Span>(1000);
    this.protocolFactory = new TBinaryProtocol.Factory();
    configure(conf);/*from  w  ww .  j av  a  2 s. c  o  m*/
}