List of usage examples for java.util.concurrent ArrayBlockingQueue ArrayBlockingQueue
public ArrayBlockingQueue(int capacity, boolean fair)
From source file:Main.java
public static void main(String[] argv) throws Exception { int capacity = 10; ArrayBlockingQueue<Integer> queue = new ArrayBlockingQueue<Integer>(capacity, false); int numWorkers = 2; Worker[] workers = new Worker[numWorkers]; for (int i = 0; i < workers.length; i++) { workers[i] = new Worker(queue); workers[i].start();/* w w w. j a v a2 s .c om*/ } for (int i = 0; i < 100; i++) { queue.put(i); } }
From source file:Main.java
public static <E> ArrayBlockingQueue<E> newArrayBlockingQueue(final int capacity, final boolean fair) { return new ArrayBlockingQueue<E>(capacity, fair); }
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.yobidrive.diskmap.TokenSynchronizer.java
public TokenSynchronizer(int allowedConcurrent) { super();/* w w w.ja va 2 s. co m*/ processingQ = new ArrayBlockingQueue<Integer>(allowedConcurrent, true); try { for (int i = 0; i < allowedConcurrent; i++) { Integer iInt = new Integer(i); processingQ.put(iInt); } } catch (Throwable th) { logger.error("Error putting tokens", th); } }
From source file:com.joshlong.esb.springintegration.modules.net.sftp.QueuedSFTPSessionPool.java
public void afterPropertiesSet() throws Exception { assert maxPoolSize > 0 : "poolSize must be greater than 0!"; queue = new ArrayBlockingQueue<SFTPSession>(maxPoolSize, true); // size, faireness to avoid starvation assert sftpSessionFactory != null : "sftpSessionFactory must not be null!"; }
From source file:ch.cyberduck.core.transfer.TransferQueue.java
public TransferQueue(final int size) { this.running = new ArrayBlockingQueue<Transfer>(size, true); }
From source file:org.nebula.framework.core.EventPoller.java
public EventPoller(NebulaClient nebulaClient, E nodeDefinition, List<String> realms, Configuration configuration) { this.nebulaClient = nebulaClient; this.nodeDefinition = nodeDefinition; this.realms = realms; this.configuration = configuration; int maxExecutionThreads = configuration.getMaxExecutionThreads(); this.nodeExecutor = new ThreadPoolExecutor(1, maxExecutionThreads, 60L, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(maxExecutionThreads, true), new ThreadPoolExecutor.CallerRunsPolicy()); }
From source file:org.opendaylight.sxp.route.core.RouteReactorZipImpl.java
/** * @param delegate service used for delegation *///from w w w. jav a 2 s .c o m public RouteReactorZipImpl(RouteReactor delegate) { this.delegate = Objects.requireNonNull(delegate); compressionQueue = new ArrayBlockingQueue<>(1, true); queueGuard = new Semaphore(1, true); updateRouteTask = createUpdateRoutingTask(); }
From source file:org.apache.lucene.gdata.storage.IDGenerator.java
/** * Constructs a new ID generator. with a fixed capacity of prebuild ids. The * default capacity is 10. Every given parameter less than 10 will be * ignored. /*from w w w . jav a 2 s.c om*/ * * @param capacity - * capacity of the prebuild id queue * @throws NoSuchAlgorithmException - * if the algorithm does not exist */ public IDGenerator(int capacity) throws NoSuchAlgorithmException { this.secureRandom = SecureRandom.getInstance("SHA1PRNG"); this.mdigest = MessageDigest.getInstance("SHA-1"); this.blockingQueue = new ArrayBlockingQueue<String>( (capacity < DEFAULT_CAPACITY ? DEFAULT_CAPACITY : capacity), false); startIDProducer(); }
From source file:net.solarnetwork.node.backup.DefaultBackupManager.java
private static ExecutorService defaultExecutorService() { // we want at most one backup happening at a time by default return new ThreadPoolExecutor(0, 1, 5, TimeUnit.MINUTES, new ArrayBlockingQueue<Runnable>(3, true)); }