當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。