Example usage for java.util.concurrent LinkedBlockingQueue LinkedBlockingQueue

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

Introduction

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

Prototype

public LinkedBlockingQueue() 

Source Link

Document

Creates a LinkedBlockingQueue with a capacity of Integer#MAX_VALUE .

Usage

From source file:no.group09.connection.Protocol.java

/**
 * Default constructor called by sub-classes
 *///from  w  w w  . j a  v a 2  s  .  c  om
public Protocol() {
    currentCommand = new Command();
    waitingForAck = null;
    tempAckProcessor = null;
    pendingInstructions = new LinkedBlockingQueue<ProtocolInstruction>();
}

From source file:WorkQueue.java

/**
 * Creates a new work queue with the specified number of threads executing
 * tasks./*from www.java2 s  .c  om*/
 */
public WorkQueue(int numThreads) {
    workQueue = new LinkedBlockingQueue<Runnable>();
    threads = new ArrayList<Thread>();
    taskKeyToLatch = new ConcurrentHashMap<Object, CountDownLatch>();
    for (int i = 0; i < numThreads; ++i) {
        Thread t = new WorkerThread(workQueue);
        threads.add(t);
        t.start();
    }
}

From source file:com.connection.factory.SftpConnectionApacheLib.java

@Override
public void readAllFilesWalkingPathWithListener(FileListener listener, String remotePath) {
    //     List<RemoteFileObject> willReturnObject = new ArrayList<>();
    Queue<RemoteFileObject> directorylist = new LinkedBlockingQueue<>();
    RemoteFileObject object = null;//from  ww  w .j a  v  a 2 s  .  co m
    object = new FtpApacheFileObject(FileInfoEnum.DIRECTORY);
    object.setDirectPath(remotePath);
    directorylist.add(object);
    try {
        while (!directorylist.isEmpty()) {
            object = directorylist.poll();
            List<ChannelSftp.LsEntry> list = command.ls(object.getPath());
            for (ChannelSftp.LsEntry each : list) {
                if (each.getFilename().equals(".") || each.getFilename().equals("..")) {
                    continue;
                }
                RemoteFileObject objectTemp = null;
                SftpATTRS attributes = each.getAttrs();
                if (attributes.isDir()) {
                    objectTemp = new SftpApacheFileObject(FileInfoEnum.DIRECTORY);
                    objectTemp.setFileName(each.getFilename());
                    objectTemp.setAbsolutePath(object.getPath());
                    directorylist.add(objectTemp);
                } else if (attributes.isReg()) {
                    objectTemp = new SftpApacheFileObject(FileInfoEnum.FILE);
                    objectTemp.setFileName(each.getFilename());
                    objectTemp.setAbsolutePath(object.getPath());
                    objectTemp.setFileSize(attributes.getSize());
                    objectTemp.setDate(attributes.getMtimeString());
                    objectTemp.setFileType();
                    listener.handleRemoteFile(object);
                }
            }
            object = null;
            list = null;
        }

    } catch (ConnectionException | SftpException ex) {
        //  ex.printStackTrace();
    }
    //return willReturnObject;
}

From source file:au.org.ala.layers.stats.ObjectsStatsGenerator.java

private static void updateArea(String fid) {

    try {// w w  w  . j a v  a 2  s. c o m
        Connection conn = getConnection();
        String sql = "SELECT pid from objects where area_km is null and st_geometrytype(the_geom) <> 'Point'";
        if (fid != null) {
            sql = sql + " and fid = '" + fid + "'";
        }

        sql = sql + " limit 200000;";

        System.out.println("loading area_km ...");
        Statement s1 = conn.createStatement();
        ResultSet rs1 = s1.executeQuery(sql);

        LinkedBlockingQueue<String> data = new LinkedBlockingQueue<String>();
        while (rs1.next()) {
            data.put(rs1.getString("pid"));
        }

        CountDownLatch cdl = new CountDownLatch(data.size());

        AreaThread[] threads = new AreaThread[CONCURRENT_THREADS];
        for (int j = 0; j < CONCURRENT_THREADS; j++) {
            threads[j] = new AreaThread(data, cdl, getConnection().createStatement());
            threads[j].start();
        }

        cdl.await();

        for (int j = 0; j < CONCURRENT_THREADS; j++) {
            threads[j].s.close();
            threads[j].interrupt();
        }
        rs1.close();
        s1.close();
        conn.close();
        return;
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
    return;
}

From source file:com.espertech.esper.core.thread.ThreadingServiceImpl.java

private BlockingQueue<Runnable> makeQueue(Integer threadPoolTimerExecCapacity) {
    if ((threadPoolTimerExecCapacity == null) || (threadPoolTimerExecCapacity <= 0)
            || (threadPoolTimerExecCapacity == Integer.MAX_VALUE)) {
        return new LinkedBlockingQueue<Runnable>();
    } else {//  w  ww . j  a  va2  s.  c  o m
        return new ArrayBlockingQueue<Runnable>(threadPoolTimerExecCapacity);
    }
}

From source file:com.datatorrent.lib.bucket.BucketManagerImpl.java

public BucketManagerImpl() {
    eventQueue = new LinkedBlockingQueue<Long>();
    evictionCandidates = Sets.newHashSet();
    dirtyBuckets = Maps.newConcurrentMap();
    bucketHeap = MinMaxPriorityQueue.orderedBy(new Comparator<Bucket<T>>() {
        @Override//from   w w w  .ja  v a 2 s  .  c  o m
        public int compare(Bucket<T> bucket1, Bucket<T> bucket2) {
            if (bucket1.lastUpdateTime() < bucket2.lastUpdateTime()) {
                return -1;
            }
            if (bucket1.lastUpdateTime() > bucket2.lastUpdateTime()) {
                return 1;
            }
            return 0;
        }

    }).create();
    lock = new Lock();
    committedWindow = -1;

    noOfBuckets = DEF_NUM_BUCKETS;
    noOfBucketsInMemory = DEF_NUM_BUCKETS_MEM;
    maxNoOfBucketsInMemory = DEF_NUM_BUCKETS_MEM + 100;
    millisPreventingBucketEviction = DEF_MILLIS_PREVENTING_EVICTION;
    writeEventKeysOnly = true;
}

From source file:Main.java

private Future<?> getOperationResult(List<BlockingQueue<T>> queues, Function<Stream<T>, ?> f) {
    BlockingQueue<T> queue = new LinkedBlockingQueue<>();
    queues.add(queue);//ww w .  java2 s  .c o m
    Spliterator<T> spliterator = new BlockingQueueSpliterator<>(queue);
    Stream<T> source = StreamSupport.stream(spliterator, false);
    return CompletableFuture.supplyAsync(() -> f.apply(source));
}

From source file:IndexService.IndexServer.java

public IndexServer(Configuration conf2) {
    initialize(conf2);//w  w  w .j  a  v  a  2 s .co  m
    MDC_check_interval = conf.getInt("se.indexer.MDC_interval", 10000);
    DPM_check_interval = conf.getInt("se.indexer.DPM_interval", 10000);
    TQM_check_interval = conf.getInt("se.indexer.TQM_interval", 5000);
    IPM_check_merge_interval = conf.getInt("se.indexer.IPM_merge_interval", 3600 * 1000);
    mergeindexfilelimit = conf.getInt("mergeindexfilelimit", 200);

    Indexer_max_jobnum = conf.getInt("indexer.max.jobnum", 10);
    poolExecutor = new ThreadPoolExecutor(Indexer_max_jobnum, Indexer_max_jobnum * 2, 30, TimeUnit.SECONDS,
            new LinkedBlockingQueue<Runnable>());
}

From source file:com.necla.simba.server.simbastore.Main.java

public void serve() {
    try {//  w w w  .j a  v  a2s . co  m
        tables = new ConcurrentHashMap<String, SimbaTable>();
        objectStore = new SwiftHandler(properties);
        tableStore = new CassandraHandler(properties);
        transactions = new ConcurrentHashMap<Integer, SyncTransaction>();

        int threads = Integer.parseInt(properties.getProperty("thread.count"));

        queues = new LinkedBlockingQueue[threads];
        workerThreads = new Thread[threads];

        hasher = new ConsistentHash();

        gm = new GatewayManager(queues, properties);

        server = new SimbaStoreServer(InetAddress.getLocalHost(),
                Integer.parseInt(properties.getProperty("port")), queues, hasher, gm);

        subscriptionManager = new SubscriptionManager(server);

        for (int i = 0; i < threads; i++) {
            queues[i] = new LinkedBlockingQueue<ServerDataEvent>();

            SimbaStoreWorker worker = new SimbaStoreWorker(properties, queues[i], objectStore, tableStore,
                    tables, subscriptionManager, transactions, gm);

            worker.setSimbaServer(server);
            workerThreads[i] = new Thread(worker, Integer.toString(i));
            workerThreads[i].start();
        }

        new Thread(server, "server").start();

        gm.setServer(server);
        gm.start();

        LOG.debug("SimbaServer start-up complete.");

    } catch (IOException e) {
        LOG.error("Could not start SimbaServer: " + e.getMessage());
        System.exit(1);
    }

}

From source file:com.bah.lucene.blockcache_v2.BaseCache.java

public BaseCache(long totalNumberOfBytes, Size fileBufferSize, Size cacheBlockSize, FileNameFilter readFilter,
        FileNameFilter writeFilter, Quiet quiet, STORE store) {
    _cacheMap = new ConcurrentLinkedHashMap.Builder<CacheKey, CacheValue>().weigher(new BaseCacheWeigher())
            .maximumWeightedCapacity(totalNumberOfBytes).listener(new BaseCacheEvictionListener()).build();
    _fileBufferSize = fileBufferSize;// w  ww  .ja va  2  s .  c  o  m
    _readFilter = readFilter;
    _writeFilter = writeFilter;
    _store = store;
    _cacheBlockSize = cacheBlockSize;
    _quiet = quiet;
    _releaseQueue = new LinkedBlockingQueue<ReleaseEntry>();
    _oldFileDaemonThread = new Thread(new Runnable() {
        @Override
        public void run() {
            while (_running.get()) {
                cleanupOldFiles();
                try {
                    Thread.sleep(_1_MINUTE);
                } catch (InterruptedException e) {
                    return;
                }
            }
        }
    });
    _oldFileDaemonThread.setDaemon(true);
    _oldFileDaemonThread.setName("BaseCacheOldFileCleanup");
    _oldFileDaemonThread.setPriority(Thread.MIN_PRIORITY);
    _oldFileDaemonThread.start();

    _oldCacheValueDaemonThread = new Thread(new Runnable() {
        @Override
        public void run() {
            while (_running.get()) {
                cleanupOldCacheValues();
                try {
                    Thread.sleep(_10_SECOND);
                } catch (InterruptedException e) {
                    return;
                }
            }
        }
    });
    _oldCacheValueDaemonThread.setDaemon(true);
    _oldCacheValueDaemonThread.setName("BaseCacheCleanupCacheValues");
    _oldCacheValueDaemonThread.start();
}