java.util.concurrent.BlockingQueue.toArray()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(132)

本文整理了Java中java.util.concurrent.BlockingQueue.toArray()方法的一些代码示例,展示了BlockingQueue.toArray()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BlockingQueue.toArray()方法的具体详情如下:
包路径:java.util.concurrent.BlockingQueue
类名称:BlockingQueue
方法名:toArray

BlockingQueue.toArray介绍

暂无

代码示例

代码示例来源:origin: apache/hbase

@Override
public Object[] toArray() {
 return underlyingQueue.toArray();
}

代码示例来源:origin: apache/hbase

@Override
public <T> T[] toArray(T[] array) {
 return underlyingQueue.toArray(array);
}

代码示例来源:origin: apache/nifi

public void retainConsumers() {
  Arrays.stream(pooledLeases.toArray(new ConsumerLease[]{}))
      .forEach(ConsumerLease::retainConnection);
}

代码示例来源:origin: robovm/robovm

/**
 * 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;
  ArrayList<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;
}

代码示例来源:origin: robovm/robovm

/**
 * Tries to remove from the work queue all {@link Future}
 * tasks that have been cancelled. This method can be useful as a
 * storage reclamation operation, that has no other impact on
 * functionality. Cancelled tasks are never executed, but may
 * accumulate in work queues until worker threads can actively
 * remove them. Invoking this method instead tries to remove them now.
 * However, this method may fail to remove tasks in
 * the presence of interference by other threads.
 */
public void purge() {
  final BlockingQueue<Runnable> q = workQueue;
  try {
    Iterator<Runnable> it = q.iterator();
    while (it.hasNext()) {
      Runnable r = it.next();
      if (r instanceof Future<?> && ((Future<?>)r).isCancelled())
        it.remove();
    }
  } catch (ConcurrentModificationException fallThrough) {
    // Take slow path if we encounter interference during traversal.
    // Make copy for traversal and call remove for cancelled entries.
    // The slow path is more likely to be O(N*N).
    for (Object r : q.toArray())
      if (r instanceof Future<?> && ((Future<?>)r).isCancelled())
        q.remove(r);
  }
  tryTerminate(); // In case SHUTDOWN and now empty
}

代码示例来源:origin: robovm/robovm

getContinueExistingPeriodicTasksAfterShutdownPolicy();
if (!keepDelayed && !keepPeriodic) {
  for (Object e : q.toArray())
    if (e instanceof RunnableScheduledFuture<?>)
      ((RunnableScheduledFuture<?>) e).cancel(false);
  for (Object e : q.toArray()) {
    if (e instanceof RunnableScheduledFuture) {
      RunnableScheduledFuture<?> t =

代码示例来源:origin: google/guava

void checkEmpty(BlockingQueue q) {
 try {
  assertTrue(q.isEmpty());
  assertEquals(0, q.size());
  assertNull(q.peek());
  assertNull(q.poll());
  assertNull(q.poll(0, MILLISECONDS));
  assertEquals("[]", q.toString());
  assertTrue(Arrays.equals(q.toArray(), new Object[0]));
  assertFalse(q.iterator().hasNext());
  try {
   q.element();
   shouldThrow();
  } catch (NoSuchElementException success) {
  }
  try {
   q.iterator().next();
   shouldThrow();
  } catch (NoSuchElementException success) {
  }
  try {
   q.remove();
   shouldThrow();
  } catch (NoSuchElementException success) {
  }
 } catch (InterruptedException ie) {
  threadUnexpectedException(ie);
 }
}

代码示例来源:origin: ben-manes/caffeine

void checkEmpty(BlockingQueue q) {
  try {
    assertTrue(q.isEmpty());
    assertEquals(0, q.size());
    assertNull(q.peek());
    assertNull(q.poll());
    assertNull(q.poll(0, MILLISECONDS));
    assertEquals(q.toString(), "[]");
    assertTrue(Arrays.equals(q.toArray(), new Object[0]));
    assertFalse(q.iterator().hasNext());
    try {
      q.element();
      shouldThrow();
    } catch (NoSuchElementException success) {}
    try {
      q.iterator().next();
      shouldThrow();
    } catch (NoSuchElementException success) {}
    try {
      q.remove();
      shouldThrow();
    } catch (NoSuchElementException success) {}
  } catch (InterruptedException fail) { threadUnexpectedException(fail); }
}

代码示例来源:origin: jankotek/mapdb

void checkEmpty(BlockingQueue q) {
  try {
    assertTrue(q.isEmpty());
    assertEquals(0, q.size());
    assertNull(q.peek());
    assertNull(q.poll());
    assertNull(q.poll(randomExpiredTimeout(), randomTimeUnit()));
    assertEquals(q.toString(), "[]");
    assertTrue(Arrays.equals(q.toArray(), new Object[0]));
    assertFalse(q.iterator().hasNext());
    try {
      q.element();
      shouldThrow();
    } catch (NoSuchElementException success) {}
    try {
      q.iterator().next();
      shouldThrow();
    } catch (NoSuchElementException success) {}
    try {
      q.remove();
      shouldThrow();
    } catch (NoSuchElementException success) {}
  } catch (InterruptedException fail) { threadUnexpectedException(fail); }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
public Object[] toArray() {
  return queue.toArray();
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
public <T> T[] toArray(T[] a) {
  return (T[]) queue.toArray(a);
}

代码示例来源:origin: rsb/rsb

@Override
public <TargetType> TargetType[] toArray(
    @SuppressWarnings("PMD.ShortVariable") final TargetType[] a) {
  synchronized (this) {
    return this.queue.toArray(a);
  }
}

代码示例来源:origin: org.eclipse.net4j/util

public <T> T[] toArray(T[] array)
{
 synchronized (list)
 {
  return list.toArray(array);
 }
}

代码示例来源:origin: rsb/rsb

@Override
public Object[] toArray() {
  synchronized (this) {
    return this.queue.toArray();
  }
}

代码示例来源:origin: org.eclipse.net4j/util

public Object[] toArray()
{
 synchronized (list)
 {
  return list.toArray();
 }
}

代码示例来源:origin: com.github.kaitoy.sneo/sneo-core

public Object[] toArray() {
 if (isRunning()) {
  return q.toArray();
 }
 else {
  return new Object[0];
 }
}

代码示例来源:origin: org.terracotta/product-upgradability-testing-utils

public <T> T[] toArray(T[] a) {
 Lock l = lock.readLock();
 l.lock();
 try {
 return backing.toArray(a);
 } finally {
  l.unlock();
 }
}

代码示例来源:origin: eventuate-clients/eventuate-client-java

public ReceivedEvent assertMessagePublished(String message, Predicate<ReceivedEvent> predicate) {
  return eventuallyReturning(eventTrackerIterations, eventTrackerInterval, TimeUnit.SECONDS, () -> {
   ReceivedEvent[] currentEvents = events.toArray(new ReceivedEvent[events.size()]);
   for (ReceivedEvent event : currentEvents) {
    if (predicate.test(event)) {
     return event;
    }
   }
   throw new RuntimeException(message);
  });
 }
}

代码示例来源:origin: networknt/light-eventuate-4j

public <T extends Event> DispatchedEvent<T> assertMessagePublished(String entityId, Class<T> eventClass) {
  return eventuallyReturning(30, 1, TimeUnit.SECONDS, () -> {
   DispatchedEvent<Event>[] currentEvents = events.toArray(new DispatchedEvent[events.size()]);
   for (DispatchedEvent<Event> event : currentEvents) {
    if (event.getEntityId().equals(entityId) && event.getEventType().equals(eventClass))
     return (DispatchedEvent<T>)event;
   }
   throw new RuntimeException(String.format("Haven't found event from %s of type %s", entityId, eventClass));
  });
 }
}

代码示例来源:origin: com.github.kaitoy.sneo/sneo-core

public <T> T[] toArray(T[] a) {
 if (isRunning()) {
  return q.toArray(a);
 }
 else {
  return new LinkedBlockingQueue<T>(0).toArray(a);
 }
}

相关文章