当前位置: 首页>>代码示例>>Java>>正文


Java BlockingQueue.isEmpty方法代码示例

本文整理汇总了Java中java.util.concurrent.BlockingQueue.isEmpty方法的典型用法代码示例。如果您正苦于以下问题:Java BlockingQueue.isEmpty方法的具体用法?Java BlockingQueue.isEmpty怎么用?Java BlockingQueue.isEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.BlockingQueue的用法示例。


在下文中一共展示了BlockingQueue.isEmpty方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shutdownProcessors

import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
public static void shutdownProcessors(ExecutorService executorService, BlockingQueue<?> queue, long timeout, TimeUnit timeUnit) {
    if (executorService != null) {
        executorService.shutdown();
        long timeoutInMillis = timeUnit.toMillis(timeout);
        /**
         * no more events can be added to the queue so simple wait till it's
         * empty.
         */
        try {
            while (queue != null && !queue.isEmpty() && timeoutInMillis > 0) {
                Thread.sleep(SHUTDOWN_WAIT_STEP_IN_MILLIS);
                timeoutInMillis -= SHUTDOWN_WAIT_STEP_IN_MILLIS;
            }
            executorService.shutdownNow();
            if (!executorService.awaitTermination(10, TimeUnit.SECONDS)) {
                LOGGER.debug("executoreService did not terminate in time");
            }
        } catch (InterruptedException ie) {
            executorService.shutdownNow();
        }
    }
}
 
开发者ID:hylkevds,项目名称:SensorThingsProcessor,代码行数:23,代码来源:ProcessorHelper.java

示例2: streamBaseXInfos

import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
private void streamBaseXInfos(String graph, String version, InputStream inputStream, boolean isSegmentXInfo)
        throws XInfoNotSupportedException, GraphImportException, GraphStorageException, GraphNotExistsException {
    //First checkk if already another import is running. The singleton serverStatus has to be injected therefore
    if (!serverStatus.registerImport()) {
        throw new GraphImportException("Sorry, system is busy, a graph import is currently executed");
    }
    IBaseSegmentProducer<IBaseSegment> producer = null;
    try {

        BlockingQueue<IBaseSegment> segmentsQueue;

        segmentsQueue = new ArrayBlockingQueue<>(queueSize);

        producer = new BaseSegmentProducerImpl<>(inputFormat, inputStream, segmentsQueue);

        Thread producerThread = new Thread(producer, "basesegment-xinfo-parser-thread");
        producerThread.start();

        List<IBaseSegment> segments = new ArrayList<>();
        while (producerThread.isAlive() || !segmentsQueue.isEmpty()) {
            if (!segmentsQueue.isEmpty()) {
                segments.add(segmentsQueue.poll());
            }
            if (segments.size() >= this.batchSize) {
                this.writeSegments(segments,graph,version,isSegmentXInfo);
                segments.clear();
            }
        }
        this.writeSegments(segments,graph,version,isSegmentXInfo);
    } finally {
        serverStatus.unregisterImport();
        if (producer != null && producer.getException() != null) {
            throw new GraphImportException("Graph could not be imported",producer.getException());
        }
    }
}
 
开发者ID:graphium-project,项目名称:graphium,代码行数:37,代码来源:BaseSegmentXInfoService.java

示例3: readSegments

import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
/**
 * @param graphName
 * @param version
 * @throws WaySegmentSerializationException 
 * @throws GraphNotExistsException 
 * @throws InterruptedException 
 */
private void readSegments(String graphName, String version) throws GraphNotExistsException, WaySegmentSerializationException, InterruptedException {
	BlockingQueue<IWaySegment> segmentsQueue = new ArrayBlockingQueue<IWaySegment>(10);
	readDao.readStreetSegments(segmentsQueue, graphName, version);
	log.info("Stored segments:");
	while (!segmentsQueue.isEmpty()) {
		IWaySegment seg = segmentsQueue.poll(10, TimeUnit.MILLISECONDS);
		log.info(seg.toString());
		log.info("XInfo:");
		if (seg.getXInfo() == null || seg.getXInfo().isEmpty()) {
			log.info("empty");
		} else {
			for (IXInfo xinfo : seg.getXInfo()) {
				log.info(xinfo.toString());
			}
		}
	}
}
 
开发者ID:graphium-project,项目名称:graphium,代码行数:25,代码来源:TestExtendSegmentWithXInfo.java

示例4: formatPlaylist

import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
private String formatPlaylist(BlockingQueue<AudioTrack> queue) {
	if(queue.isEmpty()) {
		return "**The playlist is empty.**";
	}

	StringBuilder playlist = new StringBuilder(String.format("**%s in the playlist:**\n", StringUtils.pluralOf(queue.size(), "music")));

	int count = 1;
	for(AudioTrack track : queue) {
		String name = String.format("%n\t**%d.** %s", count, FormatUtils.formatTrackName(track.getInfo()));
		if(playlist.length() + name.length() < 1800) {
			playlist.append(name);
		} else {
			playlist.append("\n\t...");
			break;
		}
		count++;
	}
	return playlist.toString();
}
 
开发者ID:Shadorc,项目名称:Shadbot,代码行数:21,代码来源:PlaylistCmd.java

示例5: shutdown

import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
private void shutdown(BlockingQueue<WebDriverEx> queue) {
    if (queue != null) {
        while (!queue.isEmpty()) {
            try {
                queue.take().shutdown();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
 
开发者ID:brucezee,项目名称:jspider,代码行数:12,代码来源:WebDriverPool.java

示例6: queueIsReallyEmpty

import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
/**
 * Checks if queue is empty by checking at CHECKPOINT_NUM points with
 * CHECKPOINT_INTERVAL_MS interval.
 * This doesn't mean the queue might not fill up at some point later, but
 * it should decrease the probability that we lose a call this way.
 */
private boolean queueIsReallyEmpty(BlockingQueue<?> q) {
  for (int i = 0; i < CHECKPOINT_NUM; i++) {
    try {
      Thread.sleep(CHECKPOINT_INTERVAL_MS);
    } catch (InterruptedException ie) {
      return false;
    }
    if (!q.isEmpty()) {
      return false;
    }
  }
  return true;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:20,代码来源:CallQueueManager.java

示例7: queueIsReallyEmpty

import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
/**
 * Checks if queue is empty by checking at two points in time.
 * This doesn't mean the queue might not fill up at some point later, but
 * it should decrease the probability that we lose a call this way.
 */
private boolean queueIsReallyEmpty(BlockingQueue<?> q) {
  boolean wasEmpty = q.isEmpty();
  try {
    Thread.sleep(10);
  } catch (InterruptedException ie) {
    return false;
  }
  return q.isEmpty() && wasEmpty;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:15,代码来源:CallQueueManager.java

示例8: drainQueue

import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
/**
 * Drains the task queue into a new list, normally using drainTo. But if the queue is a DelayQueue or any other kind
 * of queue for which poll or drainTo may fail to remove some elements, it deletes them one by one.
 */
private List<Runnable> drainQueue() {

    BlockingQueue<Runnable> q = workQueue;
    List<Runnable> taskList = new ArrayList<Runnable>();
    q.drainTo(taskList);
    if (!q.isEmpty()) {
        for (Runnable r : q.toArray(new Runnable[0])) {
            if (q.remove(r))
                taskList.add(r);
        }
    }
    return taskList;
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:18,代码来源:QueueWorkerThreadPoolExecutor.java

示例9: waitUntilDeploymentConfigIsAvailable

import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
private void waitUntilDeploymentConfigIsAvailable(final OpenShiftClient client, String namespace) {
    final BlockingQueue<Object> queue = new ArrayBlockingQueue<Object>(1);

    final Runnable readinessPoller = new Runnable() {
        public void run() {
            try {
                if (isDeploymentAvailable(client, namespace)) {
                    queue.put(true);
                    return;
                } else {
                    queue.put(false);
                    return;
                }
            } catch (Throwable t) {
                try {
                    if (queue.isEmpty()) {
                        queue.put(false);
                    }
                    return;
                } catch (InterruptedException e) {
                }
            }
        }
    };

    ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
    ScheduledFuture<?> poller = executor.scheduleWithFixedDelay(readinessPoller, 0, 500, TimeUnit.MILLISECONDS);
    executor.schedule(new Runnable() {

        @Override
        public void run() {
            poller.cancel(true);
        }
    }, Integer.valueOf(startTimeout), TimeUnit.MILLISECONDS);

    try {
        while (!waitUntilReady(queue)) {
        }
    } finally {
        if (!poller.isDone()) {
            poller.cancel(true);
        }
        executor.shutdown();
    }
}
 
开发者ID:redhat-developer,项目名称:che-starter,代码行数:46,代码来源:CheDeploymentConfig.java

示例10: execute

import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
public <T> void execute(BlockingQueue<T> blockingQueue,
                        Handler<T> handler) throws InterruptedException {

    if (blockingQueue.isEmpty()) {
        return;
    }

    if (null == this.executorService){
        this.executorService = Executors.newFixedThreadPool(threadCount);
    }

    final CountDownLatch countDownLatch = new CountDownLatch(this.threadCount);

    for (int i = 0; i < this.threadCount; i++) {
        this.executorService.execute(new Runnable() {
            @Override
            public void run() {

                try {

                    while (true) {

                        T t = blockingQueue.poll();

                        if (null == t) {
                            break;
                        }

                        handler.handle(t);
                    }
                } catch (GradleException gradleException) {
                    hasException = true;
                    exception = gradleException;
                } finally {
                    countDownLatch.countDown();
                }
            }
        });
    }

    countDownLatch.await();

    if (hasException) {
        throw new GradleException(exception.getMessage(), exception);
    }
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:47,代码来源:ExecutorServicesHelper.java

示例11: validateInternetStatus

import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
/**
 * Check if internet is available if we can open a http connection to google
 *
 * @param numberRetries Number of retries of this request.
 */
public static void validateInternetStatus(final int numberRetries) {
    //Avoid having multiple internet updates running, let just the last run
    BlockingQueue<Runnable> tasksQueue = threadPool.getQueue();
    if (!tasksQueue.isEmpty()) {
        tasksQueue.clear();
    }

    threadPool.execute(new Runnable() {
        @Override
        public void run() {

            int retries = numberRetries;
            do {
                try {
                    URL url = new URL(mInternetAddress);
                    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                    conn.setReadTimeout(mInternetValidationTimeout);
                    isInternetAvailable =
                            conn.getResponseCode() == HTTP_200
                                    || conn.getResponseCode() == HTTP_201;

                    LOG.v(LOG_TAG, "Response code -> " + conn.getResponseCode());

                    isInternetAvailable &= conn
                            .getURL().toString()
                            .startsWith(mInternetHttpValidationAddress) || conn
                            .getURL().toString()
                            .startsWith(mInternetHttpsValidationAddress);

                    LOG.v(LOG_TAG, "URL -> ", conn.getURL().toString());

                    conn.disconnect();

                    if (isInternetAvailable) {
                        LOG.v(LOG_TAG, "INTERNET IS AVAILABLE");
                        retries = 0;
                    } else {
                        LOG.v(LOG_TAG, "INTERNET IS NOT AVAILABLE");
                        retries--;
                        Thread.sleep(ONE_SECOND);
                    }
                } catch (Exception ex) {
                    LOG.e(LOG_TAG, ex, "ConnectivityReceiver isConnected");
                    isInternetAvailable = false;
                }

            } while (retries > 0);

            notifyConnectionStatus();
        }

    });
}
 
开发者ID:Mindera,项目名称:skeletoid,代码行数:59,代码来源:ConnectivityReceiver.java


注:本文中的java.util.concurrent.BlockingQueue.isEmpty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。