List of usage examples for java.util.concurrent LinkedBlockingQueue LinkedBlockingQueue
public LinkedBlockingQueue()
From source file:org.doxu.g2.gwc.crawler.Crawler.java
public void start() { String startUrl = "http://cache.trillinux.org/g2/bazooka.php"; session.addURL(startUrl);//from w w w . ja v a 2s .co m RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(Crawler.CONNECT_TIMEOUT) .setSocketTimeout(Crawler.CONNECT_TIMEOUT).build(); try (CloseableHttpClient httpClient = HttpClients.custom().setUserAgent("doxu/" + Crawler.VERSION) .setDefaultRequestConfig(requestConfig).disableAutomaticRetries().build()) { CrawlerThreadPoolExecutor executor = new CrawlerThreadPoolExecutor(GWC_CRAWLER_THREADS, GWC_CRAWLER_THREADS, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>()); executor.setListener(new IdleListener() { @Override public void idle() { // If the thread pool is idle and the queue of GWCs to crawl is empty // the crawl of GWCs is complete if (session.peek() == null) { crawlCompletedBarrier.countDown(); } } }); CrawlThreadFactory factory = CrawlThreadFactory.newFactory(session, httpClient); runQueueProcessor(factory, executor); executor.shutdown(); try { executor.awaitTermination(30, TimeUnit.SECONDS); } catch (InterruptedException ex) { Logger.getLogger(Crawler.class.getName()).log(Level.SEVERE, null, ex); } } catch (IOException ex) { Logger.getLogger(Crawler.class.getName()).log(Level.SEVERE, null, ex); } HostChecker hostChecker = new HostChecker(session); hostChecker.start(); printStats(); System.out.println(session.toXML()); }
From source file:net.ymate.platform.serv.nio.support.NioSession.java
public NioSession(NioEventGroup<LISTENER> eventGroup) throws IOException { super();/*from ww w .ja v a 2s . co m*/ __eventGroup = eventGroup; __writeBufferQueue = new LinkedBlockingQueue<ByteBuffer>(); }
From source file:com.offbynull.portmapper.common.UdpCommunicator.java
/** * Constructs a {@link UdpCommunicator} channel. * @param channels channels to use for communication (these will be closed when this class is shutdown) * @throws NullPointerException if any argument is or contains {@code null} *//*from ww w . j av a2s.c om*/ public UdpCommunicator(List<DatagramChannel> channels) { Validate.noNullElements(channels); listeners = new LinkedBlockingQueue<>(); Map<DatagramChannel, LinkedBlockingQueue<ImmutablePair<InetSocketAddress, ByteBuffer>>> intSendQueue = new HashMap<>(); for (DatagramChannel channel : channels) { intSendQueue.put(channel, new LinkedBlockingQueue<ImmutablePair<InetSocketAddress, ByteBuffer>>()); } sendQueue = Collections.unmodifiableMap(intSendQueue); }
From source file:com.easarrive.datasource.redis.etago.write.impl.TestThumborConfigureDao.java
@Before public void init() { this.callURLQueue = new LinkedBlockingQueue<ThumborCallBackURL>(); this.callURLQueue.add(new ThumborCallBackURL( "http://127.0.0.1:3081/thumbor-executer-1.0.0.0.1-SNAPSHOT/api/config/reload", 0, System.currentTimeMillis())); this.maxCallCount = 3; this.maxTimeInterval = 5000; }
From source file:net.yacy.cora.storage.Files.java
public static BlockingQueue<String> concurentLineReader(final File f) throws IOException { final BlockingQueue<String> q = new LinkedBlockingQueue<String>(); final InputStream is = read(f); final BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)); Thread t = new Thread() { @Override// w ww.ja v a 2 s. c o m public void run() { Thread.currentThread().setName("Files.concurrentLineReader:" + f); String line; try { while ((line = br.readLine()) != null) { q.put(line); } } catch (final IOException e) { } catch (final InterruptedException e) { } finally { try { q.put(POISON_LINE); try { br.close(); is.close(); } catch (final IOException ee) { } } catch (final InterruptedException e) { // last try q.add(POISON_LINE); try { br.close(); is.close(); } catch (final IOException ee) { } } } } }; t.start(); return q; }
From source file:com.buaa.cfs.nfs3.AsyncDataService.java
public AsyncDataService() { threadFactory = new ThreadFactory() { @Override//from w w w. j av a 2s .c o m public Thread newThread(Runnable r) { return new Thread(threadGroup, r); } }; executor = new ThreadPoolExecutor(CORE_THREADS_PER_VOLUME, MAXIMUM_THREADS_PER_VOLUME, THREADS_KEEP_ALIVE_SECONDS, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), threadFactory); // This can reduce the number of running threads executor.allowCoreThreadTimeOut(true); }
From source file:org.apache.ambari.log4j.hadoop.mapreduce.jobhistory.JobHistoryAppender.java
public JobHistoryAppender() { events = new LinkedBlockingQueue<LoggingEvent>(); logParser = new MapReduceJobHistoryParser(); logStore = nullStore; }
From source file:com.fusesource.forge.jmstest.executor.AbstractBenchmarkExecutionContainer.java
synchronized public void start(String[] args) { handleArguments(args);/*from w w w. ja v a 2 s .c o m*/ if (!started) { if (isAutoTerminate()) { executor = new TerminatingThreadPoolExecutor("BenchmarkExecutor", 1, 1, 10, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>()); } else { executor = new ThreadPoolExecutor(1, 1, 10, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>()); } executor.submit(this); started = true; } }
From source file:com.idlegandalf.ledd.services.ColorService.java
@Override public IBinder onBind(Intent intent) { queue = new LinkedBlockingQueue<>(); worker = new Worker<>(queue); new Thread(worker).start(); return mBinder; }
From source file:nebula.plugin.metrics.dispatcher.AbstractQueuedExecutionThreadService.java
public AbstractQueuedExecutionThreadService(boolean failOnError, boolean verboseErrorOuput) { this(new LinkedBlockingQueue<E>(), failOnError, verboseErrorOuput); }