當前位置: 首頁>>代碼示例>>Java>>正文


Java BlockingQueue.remove方法代碼示例

本文整理匯總了Java中java.util.concurrent.BlockingQueue.remove方法的典型用法代碼示例。如果您正苦於以下問題:Java BlockingQueue.remove方法的具體用法?Java BlockingQueue.remove怎麽用?Java BlockingQueue.remove使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.concurrent.BlockingQueue的用法示例。


在下文中一共展示了BlockingQueue.remove方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addsAndRemoves

import java.util.concurrent.BlockingQueue; //導入方法依賴的package包/類
@Benchmark void addsAndRemoves(int reps) {
  int capacity = this.capacity;
  BlockingQueue<String> queue = this.queue;
  String[] strings = this.strings;
  for (int i = 0; i < reps; i++) {
    for (int j = 0; j < capacity; j++) {
      queue.add(strings[j]);
    }
    for (int j = 0; j < capacity; j++) {
      queue.remove();
    }
  }
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:14,代碼來源:MonitorBenchmark.java

示例2: 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

示例3: main

import java.util.concurrent.BlockingQueue; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName relSvcName = new ObjectName("a:type=relationService");
    RelationServiceMBean relSvc =
            JMX.newMBeanProxy(mbs, relSvcName, RelationServiceMBean.class);
    mbs.createMBean("javax.management.relation.RelationService",
                    relSvcName,
                    new Object[] {Boolean.TRUE},
                    new String[] {"boolean"});

    final BlockingQueue<Notification> q =
            new ArrayBlockingQueue<Notification>(100);
    NotificationListener qListener = new NotificationListener() {
        public void handleNotification(Notification notification,
                                       Object handback) {
            q.add(notification);
        }
    };
    mbs.addNotificationListener(relSvcName, qListener, null, null);

    RoleInfo leftInfo =
        new RoleInfo("left", "javax.management.timer.TimerMBean");
    RoleInfo rightInfo =
        new RoleInfo("right", "javax.management.timer.Timer");
    relSvc.createRelationType("typeName", new RoleInfo[] {leftInfo, rightInfo});
    ObjectName timer1 = new ObjectName("a:type=timer,number=1");
    ObjectName timer2 = new ObjectName("a:type=timer,number=2");
    mbs.createMBean("javax.management.timer.Timer", timer1);
    mbs.createMBean("javax.management.timer.Timer", timer2);

    Role leftRole =
        new Role("left", Arrays.asList(new ObjectName[] {timer1}));
    Role rightRole =
        new Role("right", Arrays.asList(new ObjectName[] {timer2}));
    RoleList roles =
        new RoleList(Arrays.asList(new Role[] {leftRole, rightRole}));

    final int NREPEAT = 10;

    for (int i = 0; i < NREPEAT; i++) {
        relSvc.createRelation("relationName", "typeName", roles);
        relSvc.removeRelation("relationName");
    }

    Notification firstNotif = q.remove();
    long seqNo = firstNotif.getSequenceNumber();
    for (int i = 0; i < NREPEAT * 2 - 1; i++) {
        Notification n = q.remove();
        long nSeqNo = n.getSequenceNumber();
        if (nSeqNo != seqNo + 1) {
            throw new Exception(
                    "TEST FAILED: expected seqNo " + (seqNo + 1) + "; got " +
                    nSeqNo);
        }
        seqNo++;
    }
    System.out.println("TEST PASSED: got " + (NREPEAT * 2) + " notifications " +
            "with contiguous sequence numbers");
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:60,代碼來源:RelationNotificationSeqNoTest.java


注:本文中的java.util.concurrent.BlockingQueue.remove方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。