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


Java BlockingDeque类代码示例

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


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

示例1: testGet_concurrent

import java.util.concurrent.BlockingDeque; //导入依赖的package包/类
public void testGet_concurrent() {
  assertTrue(ArbitraryInstances.get(BlockingDeque.class).isEmpty());
  assertTrue(ArbitraryInstances.get(BlockingQueue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(DelayQueue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(SynchronousQueue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(PriorityBlockingQueue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(ConcurrentMap.class).isEmpty());
  assertTrue(ArbitraryInstances.get(ConcurrentNavigableMap.class).isEmpty());
  ArbitraryInstances.get(Executor.class).execute(ArbitraryInstances.get(Runnable.class));
  assertNotNull(ArbitraryInstances.get(ThreadFactory.class));
  assertFreshInstanceReturned(
      BlockingQueue.class, BlockingDeque.class, PriorityBlockingQueue.class,
      DelayQueue.class, SynchronousQueue.class,
      ConcurrentMap.class, ConcurrentNavigableMap.class,
      AtomicReference.class, AtomicBoolean.class,
      AtomicInteger.class, AtomicLong.class, AtomicDouble.class);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:18,代码来源:ArbitraryInstancesTest.java

示例2: instantiateCollectionFromInterface

import java.util.concurrent.BlockingDeque; //导入依赖的package包/类
private <T> Collection<T> instantiateCollectionFromInterface(Class<? extends T> collectionType) {
    if (List.class.isAssignableFrom(collectionType)) {
        return new ArrayList<T>();
    } else if (SortedSet.class.isAssignableFrom(collectionType)) {
        return new TreeSet<T>();
    } else if (Set.class.isAssignableFrom(collectionType)) {
        return new LinkedHashSet<T>();
    } else if (BlockingDeque.class.isAssignableFrom(collectionType)) {
        return new LinkedBlockingDeque<T>();
    } else if (Deque.class.isAssignableFrom(collectionType)) {
        return new ArrayDeque<T>();
    } else if (BlockingQueue.class.isAssignableFrom(collectionType)) {
        return new LinkedBlockingDeque<T>();
    } else if (Queue.class.isAssignableFrom(collectionType)) {
        return new LinkedList<T>();
    }
    return new ArrayList<T>();
}
 
开发者ID:Yoio,项目名称:X4J,代码行数:19,代码来源:DynamicParsers.java

示例3: testTakeFirstFromEmptyBlocksInterruptibly

import java.util.concurrent.BlockingDeque; //导入依赖的package包/类
/**
 * takeFirst() blocks interruptibly when empty
 */
public void testTakeFirstFromEmptyBlocksInterruptibly() {
    final BlockingDeque q = new LinkedBlockingDeque();
    final CountDownLatch threadStarted = new CountDownLatch(1);
    Thread t = newStartedThread(new CheckedRunnable() {
        public void realRun() {
            threadStarted.countDown();
            try {
                q.takeFirst();
                shouldThrow();
            } catch (InterruptedException success) {}
            assertFalse(Thread.interrupted());
        }});

    await(threadStarted);
    assertThreadBlocks(t, Thread.State.WAITING);
    t.interrupt();
    awaitTermination(t);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:LinkedBlockingDequeTest.java

示例4: testTakeLastFromEmptyBlocksInterruptibly

import java.util.concurrent.BlockingDeque; //导入依赖的package包/类
/**
 * takeLast() blocks interruptibly when empty
 */
public void testTakeLastFromEmptyBlocksInterruptibly() {
    final BlockingDeque q = new LinkedBlockingDeque();
    final CountDownLatch threadStarted = new CountDownLatch(1);
    Thread t = newStartedThread(new CheckedRunnable() {
        public void realRun() {
            threadStarted.countDown();
            try {
                q.takeLast();
                shouldThrow();
            } catch (InterruptedException success) {}
            assertFalse(Thread.interrupted());
        }});

    await(threadStarted);
    assertThreadBlocks(t, Thread.State.WAITING);
    t.interrupt();
    awaitTermination(t);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:LinkedBlockingDequeTest.java

示例5: putAllCollections

import java.util.concurrent.BlockingDeque; //导入依赖的package包/类
static void putAllCollections(Map<Class<?>, IntFunction<?>> map, Map<Class<?>, Function<?, ?>> unmodMap)
{
    safePut(map, ArrayList.class, ArrayList::new);
    safePut(map, HashSet.class, LinkedHashSet::new);
    safePut(map, Properties.class, x -> new Properties());
    safePut(map, Hashtable.class, Hashtable::new);

    safePut(map, Collection.class, ArrayList::new);
    safePut(map, Set.class, LinkedHashSet::new);
    safePut(map, List.class, ArrayList::new);
    safePut(map, SortedSet.class, x -> new TreeSet<>());
    safePut(map, Queue.class, x -> new ConcurrentLinkedQueue<>());
    safePut(map, Deque.class, x -> new ConcurrentLinkedDeque<>());
    safePut(map, BlockingQueue.class, x -> new LinkedBlockingQueue<>());
    safePut(map, BlockingDeque.class, x -> new LinkedBlockingDeque<>());


    safePut(map, HashMap.class, LinkedHashMap::new);
    safePut(map, LinkedHashMap.class, LinkedHashMap::new);
    safePut(map, ConcurrentHashMap.class, ConcurrentHashMap::new);

    safePut(map, Map.class, LinkedHashMap::new);
    safePut(map, ConcurrentMap.class, x -> new ConcurrentSkipListMap<>());
    safePut(map, ConcurrentNavigableMap.class, x -> new ConcurrentSkipListMap<>());
    safePut(map, SortedMap.class, i -> new TreeMap<>());
}
 
开发者ID:GotoFinal,项目名称:diorite-configs-java8,代码行数:27,代码来源:YamlCollectionCreator.java

示例6: testTakeFirstFromEmptyBlocksInterruptibly

import java.util.concurrent.BlockingDeque; //导入依赖的package包/类
/**
 * takeFirst() blocks interruptibly when empty
 */
public void testTakeFirstFromEmptyBlocksInterruptibly() {
    final BlockingDeque q = new LinkedBlockingDeque();
    final CountDownLatch threadStarted = new CountDownLatch(1);
    Thread t = newStartedThread(new CheckedRunnable() {
        public void realRun() {
            threadStarted.countDown();
            try {
                q.takeFirst();
                shouldThrow();
            } catch (InterruptedException success) {}
            assertFalse(Thread.interrupted());
        }});

    await(threadStarted);
    assertThreadStaysAlive(t);
    t.interrupt();
    awaitTermination(t);
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:22,代码来源:LinkedBlockingDequeTest.java

示例7: testTakeLastFromEmptyBlocksInterruptibly

import java.util.concurrent.BlockingDeque; //导入依赖的package包/类
/**
 * takeLast() blocks interruptibly when empty
 */
public void testTakeLastFromEmptyBlocksInterruptibly() {
    final BlockingDeque q = new LinkedBlockingDeque();
    final CountDownLatch threadStarted = new CountDownLatch(1);
    Thread t = newStartedThread(new CheckedRunnable() {
        public void realRun() {
            threadStarted.countDown();
            try {
                q.takeLast();
                shouldThrow();
            } catch (InterruptedException success) {}
            assertFalse(Thread.interrupted());
        }});

    await(threadStarted);
    assertThreadStaysAlive(t);
    t.interrupt();
    awaitTermination(t);
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:22,代码来源:LinkedBlockingDequeTest.java

示例8: finishScanningCycle

import java.util.concurrent.BlockingDeque; //导入依赖的package包/类
private void finishScanningCycle() {
    for (Map.Entry<String, BlockingDeque<Integer>> entry : mScanHistory.entrySet()) {
        final BlockingDeque<Integer> values = entry.getValue();


        if (values.size() < BUFFER_SIZE) {
            Log.d(TAG, entry.getKey() + ": Sorry, only got " + values.size() + " out of " + BUFFER_SIZE);
        }

        DescriptiveStatistics stats = BeaconFilter.statistics(values);

        synchronized (mScanResults) {
            for (ScanItem info : mScanResults) {
                if (info.getMacAddress().equalsIgnoreCase((entry.getKey()))) {
                    info.setRssi((int) stats.getMean());
                    Log.d(TAG, entry.getKey() + ": Calculated mean of RSSI to " + info.getRssi());
                    break;
                }
            }
        }
        mScanHistory.get(entry.getKey()).clear();
    }
    parcelIntent.putParcelableArrayListExtra(BluetoothScannerService.TAG_PARCEL, mScanResults);
    sendBroadcast(parcelIntent);
}
 
开发者ID:hugolm84,项目名称:BeaconFinder,代码行数:26,代码来源:BluetoothScannerService.java

示例9: putAllCollections

import java.util.concurrent.BlockingDeque; //导入依赖的package包/类
static void putAllCollections(Map<Class<?>, IntFunction<?>> map)
{
    safePut(map, ArrayList.class, ArrayList::new);
    safePut(map, HashSet.class, LinkedHashSet::new);
    safePut(map, Properties.class, x -> new Properties());
    safePut(map, Hashtable.class, Hashtable::new);

    safePut(map, Collection.class, ArrayList::new);
    safePut(map, Set.class, LinkedHashSet::new);
    safePut(map, List.class, ArrayList::new);
    safePut(map, SortedSet.class, x -> new TreeSet<>());
    safePut(map, Queue.class, x -> new ConcurrentLinkedQueue<>());
    safePut(map, Deque.class, x -> new ConcurrentLinkedDeque<>());
    safePut(map, BlockingQueue.class, x -> new LinkedBlockingQueue<>());
    safePut(map, BlockingDeque.class, x -> new LinkedBlockingDeque<>());


    safePut(map, HashMap.class, LinkedHashMap::new);
    safePut(map, LinkedHashMap.class, LinkedHashMap::new);
    safePut(map, ConcurrentHashMap.class, ConcurrentHashMap::new);

    safePut(map, Map.class, LinkedHashMap::new);
    safePut(map, ConcurrentMap.class, x -> new ConcurrentSkipListMap<>());
    safePut(map, ConcurrentNavigableMap.class, x -> new ConcurrentSkipListMap<>());
    safePut(map, SortedMap.class, i -> new TreeMap<>());
}
 
开发者ID:Diorite,项目名称:Diorite,代码行数:27,代码来源:YamlCollectionCreator.java

示例10: startFuzzer

import java.util.concurrent.BlockingDeque; //导入依赖的package包/类
private static void startFuzzer(String targetHost, Integer targetPort, Integer fuzzerPort, String fuzzType) throws IOException {
    BlockingDeque<String> queue = new LinkedBlockingDeque<String>();
    AgentEventReader reader = new AgentEventReader(queue, fuzzerPort);
    PayloadGenerator generator = new RandomBytesPayloadGenerator();

    PayloadSender sender = null;
    if ("TCP".equals(fuzzType)) {
        sender = new TCPSocketPayloadSender(targetHost, targetPort);
    } else if ("HTTP".equals(fuzzType)) {
        // TODO implement payload generator for http
    } else if ("JMX".equals(fuzzType)) {
        // TODO implement payload generator for jmx
    }

    PayloadService service = new PayloadService(queue, generator, sender);

    System.out.println(format("Fuzzer has started on %s:%d", targetHost, targetPort));

    ExecutorService executorService = Executors.newFixedThreadPool(2);
    executorService.execute(reader);
    executorService.execute(service);
}
 
开发者ID:pawelprazak,项目名称:jeff,代码行数:23,代码来源:Fuzzer.java

示例11: testGet_concurrent

import java.util.concurrent.BlockingDeque; //导入依赖的package包/类
public void testGet_concurrent() {
  assertTrue(ArbitraryInstances.get(BlockingDeque.class).isEmpty());
  assertTrue(ArbitraryInstances.get(BlockingQueue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(DelayQueue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(SynchronousQueue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(PriorityBlockingQueue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(ConcurrentMap.class).isEmpty());
  assertTrue(ArbitraryInstances.get(ConcurrentNavigableMap.class).isEmpty());
  ArbitraryInstances.get(Executor.class).execute(ArbitraryInstances.get(Runnable.class));
  assertNotNull(ArbitraryInstances.get(ThreadFactory.class));
  assertFreshInstanceReturned(
      BlockingQueue.class,
      BlockingDeque.class,
      PriorityBlockingQueue.class,
      DelayQueue.class,
      SynchronousQueue.class,
      ConcurrentMap.class,
      ConcurrentNavigableMap.class,
      AtomicReference.class,
      AtomicBoolean.class,
      AtomicInteger.class,
      AtomicLong.class,
      AtomicDouble.class);
}
 
开发者ID:google,项目名称:guava,代码行数:25,代码来源:ArbitraryInstancesTest.java

示例12: proxy

import java.util.concurrent.BlockingDeque; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static BlockingDeque<String> proxy(Object inputDeque) throws NoSuchMethodException {
    if (inputDeque instanceof BlockingDeque) {
        return (BlockingDeque<String>) inputDeque;
    }
    final ClassLoader cl = Thread.currentThread().getContextClassLoader();

    final Method put = inputDeque.getClass().getMethod("put", Object.class);
    final Method take = inputDeque.getClass().getMethod("take");
    final Method isEmpty = inputDeque.getClass().getMethod("isEmpty");

    return (BlockingDeque<String>)Proxy.newProxyInstance(cl, new Class[]{BlockingDeque.class}, (proxy, method, args) -> {
        switch (method.getName()) {
            case "put":
                return put.invoke(inputDeque, args);
            case "take":
                return take.invoke(inputDeque, args);
            case "isEmpty":
                return isEmpty.invoke(inputDeque, args);
        }
        throw new UnsupportedOperationException(method.toGenericString() + " is not supported");
    });
}
 
开发者ID:WeTheInternet,项目名称:xapi,代码行数:24,代码来源:GwtcJobMonitorImpl.java

示例13: pack

import java.util.concurrent.BlockingDeque; //导入依赖的package包/类
@Override
public void pack(BlockingDeque<PackItem> itemsDeque,
                 File packsDir,
                 String packId,
                 Consumer<PackItem> newItemSuccess,
                 Consumer<PackItem> newItemFail,
                 Consumer<File> done,
                 Runnable failed) {
    final File packFile = new File(packsDir, packId + ".zip");
    try (final ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(packFile))) {
        PackItem item = takeItem(itemsDeque);
        if (item == null) {
            failed.run();
            return;
        }
        while (!item.getFileName().equals("end")) {
            final boolean added = PackSupport.saveToZip(item, zos);
            if (added) newItemSuccess.accept(item);
            else newItemFail.accept(item);
            item = takeItem(itemsDeque);
            if (item == null) {
                failed.run();
                return;
            }
        }
    } catch (IOException e) {
        failed.run();
        return;
    }
    done.accept(packFile);
}
 
开发者ID:dreyman,项目名称:inpacker,代码行数:32,代码来源:ZipPacker.java

示例14: takeItem

import java.util.concurrent.BlockingDeque; //导入依赖的package包/类
private <I extends PackItem> I takeItem(BlockingDeque<I> deque) {
    try {
        return deque.take();
    } catch (InterruptedException e) {
        return null;
    }
}
 
开发者ID:dreyman,项目名称:inpacker,代码行数:8,代码来源:ZipPacker.java

示例15: pack

import java.util.concurrent.BlockingDeque; //导入依赖的package包/类
void pack(BlockingDeque<PackItem> itemsDeque,
File packsDir,
String packId,
Consumer<PackItem> newItemSuccess,
Consumer<PackItem> newItemFail,
Consumer<File> done,
Runnable failed);
 
开发者ID:dreyman,项目名称:inpacker,代码行数:8,代码来源:Packer.java


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