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


Java LinkedBlockingQueue.add方法代码示例

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


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

示例1: testIteratorRemove

import java.util.concurrent.LinkedBlockingQueue; //导入方法依赖的package包/类
/**
 * iterator.remove removes current element
 */
public void testIteratorRemove() {
    final LinkedBlockingQueue q = new LinkedBlockingQueue(3);
    q.add(two);
    q.add(one);
    q.add(three);

    Iterator it = q.iterator();
    it.next();
    it.remove();

    it = q.iterator();
    assertSame(it.next(), one);
    assertSame(it.next(), three);
    assertFalse(it.hasNext());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:LinkedBlockingQueueTest.java

示例2: testOfferInExecutor

import java.util.concurrent.LinkedBlockingQueue; //导入方法依赖的package包/类
/**
 * offer transfers elements across Executor tasks
 */
public void testOfferInExecutor() {
    final LinkedBlockingQueue q = new LinkedBlockingQueue(2);
    q.add(one);
    q.add(two);
    final CheckedBarrier threadsStarted = new CheckedBarrier(2);
    final ExecutorService executor = Executors.newFixedThreadPool(2);
    try (PoolCleaner cleaner = cleaner(executor)) {
        executor.execute(new CheckedRunnable() {
            public void realRun() throws InterruptedException {
                assertFalse(q.offer(three));
                threadsStarted.await();
                assertTrue(q.offer(three, LONG_DELAY_MS, MILLISECONDS));
                assertEquals(0, q.remainingCapacity());
            }});

        executor.execute(new CheckedRunnable() {
            public void realRun() throws InterruptedException {
                threadsStarted.await();
                assertSame(one, q.take());
            }});
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:LinkedBlockingQueueTest.java

示例3: testDrainTo

import java.util.concurrent.LinkedBlockingQueue; //导入方法依赖的package包/类
/**
 * drainTo(c) empties queue into another collection c
 */
public void testDrainTo() {
    LinkedBlockingQueue q = populatedQueue(SIZE);
    ArrayList l = new ArrayList();
    q.drainTo(l);
    assertEquals(0, q.size());
    assertEquals(SIZE, l.size());
    for (int i = 0; i < SIZE; ++i)
        assertEquals(l.get(i), new Integer(i));
    q.add(zero);
    q.add(one);
    assertFalse(q.isEmpty());
    assertTrue(q.contains(zero));
    assertTrue(q.contains(one));
    l.clear();
    q.drainTo(l);
    assertEquals(0, q.size());
    assertEquals(2, l.size());
    for (int i = 0; i < 2; ++i)
        assertEquals(l.get(i), new Integer(i));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:LinkedBlockingQueueTest.java

示例4: parseM3u8

import java.util.concurrent.LinkedBlockingQueue; //导入方法依赖的package包/类
private void parseM3u8(String m3u8Url, String newM3u8FileName, String outputPath, LinkedBlockingQueue<Map<String, String>> sizeDetectQueue, LinkedBlockingQueue<Map<String, String>> downloadQueue) throws IOException {
    String m3U8Content = HttpRequestUtil.getResponseString(HttpRequestUtil.sendGetRequest(m3u8Url));
    String newM3u8FileContent = "";
    boolean subFile = false;
    for(String lineStr:m3U8Content.split("\n")){
        if(lineStr.startsWith("#")){
            newM3u8FileContent = newM3u8FileContent+lineStr+"\n";
            if(lineStr.startsWith("#EXT-X-STREAM-INF")){
                subFile = true;
            }
        }else{
            String uuidStr = UUIDUtil.genUUID();
            String fileUrl = new URL(new URL(m3u8Url), lineStr.trim()).toString();
            if(subFile){
                subFile = false;
                parseM3u8(fileUrl, uuidStr+".m3u8", outputPath,sizeDetectQueue, downloadQueue);
                newM3u8FileContent = newM3u8FileContent+"/"+uuidStr + ".m3u8\n";
            }else{
                String videoFilePath = outputPath + File.separator + uuidStr + ".ts";
                HashMap<String, String> hashMap = new HashMap<String, String>();
                hashMap.put("url", fileUrl);
                hashMap.put("downloadPath", videoFilePath);
                sizeDetectQueue.add(hashMap);
                downloadQueue.add(hashMap);
                newM3u8FileContent = newM3u8FileContent+"/"+ uuidStr + ".ts\n";
            }
        }
    }
    FileUtil.stringToFile(newM3u8FileContent, outputPath+File.separator+newM3u8FileName);
}
 
开发者ID:xm0625,项目名称:VBrowser-Android,代码行数:31,代码来源:DownloadManager.java

示例5: test_queue_copy

import java.util.concurrent.LinkedBlockingQueue; //导入方法依赖的package包/类
@Test
    public void test_queue_copy() {
        LinkedBlockingQueue<String> queue = new LinkedBlockingQueue<String>();
        queue.add("abc");
        LinkedBlockingQueue<String> queueMileage = new LinkedBlockingQueue<String>(queue);
//        String trucknum = queueMileage.poll();
        queueMileage.remove();
//        System.out.println(trucknum);
        System.out.println(queue);
    }
 
开发者ID:alamby,项目名称:upgradeToy,代码行数:11,代码来源:CollectionTest.java

示例6: testEmptyFull

import java.util.concurrent.LinkedBlockingQueue; //导入方法依赖的package包/类
/**
 * Queue transitions from empty to full when elements added
 */
public void testEmptyFull() {
    LinkedBlockingQueue q = new LinkedBlockingQueue(2);
    assertTrue(q.isEmpty());
    assertEquals("should have room for 2", 2, q.remainingCapacity());
    q.add(one);
    assertFalse(q.isEmpty());
    q.add(two);
    assertFalse(q.isEmpty());
    assertEquals(0, q.remainingCapacity());
    assertFalse(q.offer(three));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:LinkedBlockingQueueTest.java

示例7: testAdd

import java.util.concurrent.LinkedBlockingQueue; //导入方法依赖的package包/类
/**
 * add succeeds if not full; throws IllegalStateException if full
 */
public void testAdd() {
    LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE);
    for (int i = 0; i < SIZE; ++i)
        assertTrue(q.add(new Integer(i)));
    assertEquals(0, q.remainingCapacity());
    try {
        q.add(new Integer(SIZE));
        shouldThrow();
    } catch (IllegalStateException success) {}
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:LinkedBlockingQueueTest.java

示例8: testClear

import java.util.concurrent.LinkedBlockingQueue; //导入方法依赖的package包/类
/**
 * clear removes all elements
 */
public void testClear() {
    LinkedBlockingQueue q = populatedQueue(SIZE);
    q.clear();
    assertTrue(q.isEmpty());
    assertEquals(0, q.size());
    assertEquals(SIZE, q.remainingCapacity());
    q.add(one);
    assertFalse(q.isEmpty());
    assertTrue(q.contains(one));
    q.clear();
    assertTrue(q.isEmpty());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:LinkedBlockingQueueTest.java

示例9: testContainsAll

import java.util.concurrent.LinkedBlockingQueue; //导入方法依赖的package包/类
/**
 * containsAll(c) is true when c contains a subset of elements
 */
public void testContainsAll() {
    LinkedBlockingQueue q = populatedQueue(SIZE);
    LinkedBlockingQueue p = new LinkedBlockingQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertTrue(q.containsAll(p));
        assertFalse(p.containsAll(q));
        p.add(new Integer(i));
    }
    assertTrue(p.containsAll(q));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:LinkedBlockingQueueTest.java

示例10: testIteratorOrdering

import java.util.concurrent.LinkedBlockingQueue; //导入方法依赖的package包/类
/**
 * iterator ordering is FIFO
 */
public void testIteratorOrdering() {
    final LinkedBlockingQueue q = new LinkedBlockingQueue(3);
    q.add(one);
    q.add(two);
    q.add(three);
    assertEquals(0, q.remainingCapacity());
    int k = 0;
    for (Iterator it = q.iterator(); it.hasNext();) {
        assertEquals(++k, it.next());
    }
    assertEquals(3, k);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:LinkedBlockingQueueTest.java

示例11: testWeaklyConsistentIteration

import java.util.concurrent.LinkedBlockingQueue; //导入方法依赖的package包/类
/**
 * Modifications do not cause iterators to fail
 */
public void testWeaklyConsistentIteration() {
    final LinkedBlockingQueue q = new LinkedBlockingQueue(3);
    q.add(one);
    q.add(two);
    q.add(three);
    for (Iterator it = q.iterator(); it.hasNext();) {
        q.remove();
        it.next();
    }
    assertEquals(0, q.size());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:LinkedBlockingQueueTest.java

示例12: insertData

import java.util.concurrent.LinkedBlockingQueue; //导入方法依赖的package包/类
private LinkedBlockingQueue<Long> insertData() throws IOException, InterruptedException {
  LinkedBlockingQueue<Long> rowKeys = new LinkedBlockingQueue<Long>(25000);
  BufferedMutator ht = util.getConnection().getBufferedMutator(this.tableName);
  byte[] value = new byte[300];
  for (int x = 0; x < 5000; x++) {
    TraceScope traceScope = Trace.startSpan("insertData", Sampler.ALWAYS);
    try {
      for (int i = 0; i < 5; i++) {
        long rk = random.nextLong();
        rowKeys.add(rk);
        Put p = new Put(Bytes.toBytes(rk));
        for (int y = 0; y < 10; y++) {
          random.nextBytes(value);
          p.add(familyName, Bytes.toBytes(random.nextLong()), value);
        }
        ht.mutate(p);
      }
      if ((x % 1000) == 0) {
        admin.flush(tableName);
      }
    } finally {
      traceScope.close();
    }
  }
  admin.flush(tableName);
  return rowKeys;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:28,代码来源:IntegrationTestSendTraceRequests.java


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