本文整理汇总了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();
}
}
}
示例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());
}
}
}
示例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());
}
}
}
}
示例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();
}
示例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();
}
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
}
示例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);
}
}
示例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();
}
});
}