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


Java ConcurrentLinkedQueue類代碼示例

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


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

示例1: CachedWorkerPool

import java.util.concurrent.ConcurrentLinkedQueue; //導入依賴的package包/類
CachedWorkerPool(long keepAliveTime, TimeUnit unit) {
    this.keepAliveTime = unit != null ? unit.toNanos(keepAliveTime) : 0;
    this.expiringWorkerQueue = new ConcurrentLinkedQueue();
    this.allWorkers = new CompositeSubscription();
    ScheduledExecutorService evictor = null;
    Future<?> task = null;
    if (unit != null) {
        evictor = Executors.newScheduledThreadPool(1, CachedThreadScheduler.EVICTOR_THREAD_FACTORY);
        NewThreadWorker.tryEnableCancelPolicy(evictor);
        task = evictor.scheduleWithFixedDelay(new Runnable() {
            public void run() {
                CachedWorkerPool.this.evictExpiredWorkers();
            }
        }, this.keepAliveTime, this.keepAliveTime, TimeUnit.NANOSECONDS);
    }
    this.evictorService = evictor;
    this.evictorTask = task;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:19,代碼來源:CachedThreadScheduler.java

示例2: putAllCollections

import java.util.concurrent.ConcurrentLinkedQueue; //導入依賴的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

示例3: apply

import java.util.concurrent.ConcurrentLinkedQueue; //導入依賴的package包/類
@Override
public Collection<Diff> apply(Object before, Object after, String description) {
    Collection<Diff> diffs = new ConcurrentLinkedQueue<>();
    if (before == null && after == null) {
        diffs.add(new Diff.Builder().hasNotChanged().setFieldDescription(description).build());
    } else if (before == null) {
        diffs.add(new Diff.Builder().isAdded().setAfterValue(after).setFieldDescription(description).build());
    } else if (after == null) {
        diffs.add(new Diff.Builder().isDeleted().setBeforeValue(before).setFieldDescription(description).build());
    } else {
        if (before.equals(after)) {
            diffs.add(new Diff.Builder().hasNotChanged().setBeforeValue(before).setAfterValue(after).setFieldDescription(description).build());
        } else {
            diffs.add(new Diff.Builder().isUpdated().setBeforeValue(before).setAfterValue(after).setFieldDescription(description).build());
        }
    }
    return diffs;
}
 
開發者ID:PareshNavalakha,項目名稱:object-diff,代碼行數:19,代碼來源:ObjectDiffCalculator.java

示例4: ImapClient

import java.util.concurrent.ConcurrentLinkedQueue; //導入依賴的package包/類
public ImapClient(ImapClientConfiguration configuration,
                  Channel channel,
                  SslContext sslContext,
                  EventExecutorGroup promiseExecutor,
                  String clientName) {
  this.logger = LogUtils.loggerWithName(ImapClient.class, clientName);
  this.configuration = configuration;
  this.channel = channel;
  this.sslContext = sslContext;
  this.promiseExecutor = promiseExecutor;
  this.clientState = new ImapClientState(clientName, promiseExecutor);
  this.codec = new ImapCodec(clientState);
  this.pendingWriteQueue = new ConcurrentLinkedQueue<>();
  this.connectionShutdown = new AtomicBoolean(false);
  this.connectionClosed = new AtomicBoolean(false);
  this.capabilities = new AtomicReference<>(null);

  configureChannel();
}
 
開發者ID:HubSpot,項目名稱:NioImapClient,代碼行數:20,代碼來源:ImapClient.java

示例5: concurrentQueues

import java.util.concurrent.ConcurrentLinkedQueue; //導入依賴的package包/類
Collection<Queue<Boolean>> concurrentQueues() {
    List<Queue<Boolean>> queues = new ArrayList<Queue<Boolean>>();
    queues.add(new ConcurrentLinkedDeque<Boolean>());
    queues.add(new ConcurrentLinkedQueue<Boolean>());
    queues.add(new ArrayBlockingQueue<Boolean>(count, false));
    queues.add(new ArrayBlockingQueue<Boolean>(count, true));
    queues.add(new LinkedBlockingQueue<Boolean>());
    queues.add(new LinkedBlockingDeque<Boolean>());
    queues.add(new LinkedTransferQueue<Boolean>());

    // Following additional implementations are available from:
    // http://gee.cs.oswego.edu/dl/concurrency-interest/index.html
    // queues.add(new SynchronizedLinkedListQueue<Boolean>());

    // Avoid "first fast, second slow" benchmark effect.
    Collections.shuffle(queues);
    return queues;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:19,代碼來源:RemovePollRace.java

示例6: parse

import java.util.concurrent.ConcurrentLinkedQueue; //導入依賴的package包/類
/**
 * Parses all document present in the referenced file path
 *
 * @param stringsQueue to parse
 * @return list with all documents with it's content in untokenized/unstemmed raw keywords
 */
public List<Document> parse(ConcurrentLinkedQueue<String> stringsQueue) {

    //compile our corpus regex so we can apply it on our parsing process
    Pattern id_content = Pattern.compile(CORPUS_REGEX_DOCUMENT);

    //parsing process
    return stringsQueue.parallelStream()
            .filter(line -> !line.isEmpty()) // line is not empty
            .map(id_content::matcher)// regex it
            .filter(Matcher::find) // did we regex anything? if so create document
            .map(match ->
            {
                //get the corpusID for this new file that we processing
                int corpusID = corpusCount.getAndIncrement();

                //map the corpusID to its corresponding filepath
                corpusIDToPath.computeIfAbsent(corpusID, v -> new ImmutablePair<>(match.group(4), Integer.parseInt(match.group(1))));
                return new Document(
                        corpusID, //first match is doc id and used to create our own doc id
                        Arrays.asList(match.group(5).split(" ")).parallelStream() // split document content in words
                                .collect(Collectors.toList())); // and put them in a list
            })
            .collect(Collectors.toList()); //collect all parsed lines
}
 
開發者ID:luminoso,項目名稱:information-retrieval,代碼行數:31,代碼來源:CorpusReader.java

示例7: concurrentQueues

import java.util.concurrent.ConcurrentLinkedQueue; //導入依賴的package包/類
Collection<Queue<Boolean>> concurrentQueues() {
    List<Queue<Boolean>> queues = new ArrayList<>();
    queues.add(new ConcurrentLinkedDeque<Boolean>());
    queues.add(new ConcurrentLinkedQueue<Boolean>());
    queues.add(new ArrayBlockingQueue<Boolean>(count, false));
    queues.add(new ArrayBlockingQueue<Boolean>(count, true));
    queues.add(new LinkedBlockingQueue<Boolean>());
    queues.add(new LinkedBlockingDeque<Boolean>());
    queues.add(new LinkedTransferQueue<Boolean>());

    // Following additional implementations are available from:
    // http://gee.cs.oswego.edu/dl/concurrency-interest/index.html
    // queues.add(new SynchronizedLinkedListQueue<Boolean>());

    // Avoid "first fast, second slow" benchmark effect.
    Collections.shuffle(queues);
    return queues;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:RemovePollRace.java

示例8: start

import java.util.concurrent.ConcurrentLinkedQueue; //導入依賴的package包/類
@SuppressWarnings("InfiniteLoopStatement")
public void start() {
    for (Map.Entry<Address, Addressee> entry : addresseeMap.entrySet()) {
        new Thread(() -> {
            while (true) {

                ConcurrentLinkedQueue<Message> queue = messagesMap.get(entry.getKey());
                while (!queue.isEmpty()) {
                    Message message = queue.poll();
                    message.exec(entry.getValue());
                }
                try {
                    Thread.sleep(MessageSystem.DEFAULT_STEP_TIME);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
}
 
開發者ID:vitaly-chibrikov,項目名稱:otus_java_2017_06,代碼行數:21,代碼來源:MessageSystem.java

示例9: PerfInserterBase

import java.util.concurrent.ConcurrentLinkedQueue; //導入依賴的package包/類
public PerfInserterBase(Configuration conf, TableName tableName, String loadDataDir,
    int processId, int threadNum, String statFilePath, ConcurrentLinkedQueue<String> reportQueue,
    AbstractWorkload workload) throws IOException {
  this.tableName = tableName;
  this.processId = processId;
  this.threadNum = threadNum;
  this.loadDataDir = loadDataDir;
  this.statFilePath = statFilePath;
  this.reportQueue = reportQueue;
  this.conf = conf;
  loaders = new RunnableDataLoader[threadNum];
  inserters = new RunnablePerfInserter[threadNum];
  threadFinishMark = new boolean[threadNum];
  threadLatency = new double[threadNum];
  globalBoxNumber = new int[ResultParser.LatencyBoxPivots.length];
  for (int i = 0; i < globalBoxNumber.length; ++i) {
    globalBoxNumber[i] = 0;
  }
  this.workload = workload;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:21,代碼來源:PerfInserterBase.java

示例10: HTTPBuilder

import java.util.concurrent.ConcurrentLinkedQueue; //導入依賴的package包/類
/** Constructor that sets up the connection */
public HTTPBuilder(HTTPSession session) {
  try {
    boot = new Bootstrap();
    boot.group(session.workGroup)
      .channel(HTTPChannel.class)
      .handler(new HTTPInitializer(session.uri.scheme(), this));

    // Channel setup
    onConnectBell = new Bell<Void>();
    setUri(session.uri);
    setupWithTest();

    // Tap bells queue setup
    tapBellQueue = new ConcurrentLinkedQueue<Bell<Void>>();
  } catch (HTTPException e) {
    System.err.println(e.getMessage());
  }
}
 
開發者ID:didclab,項目名稱:onedatashare,代碼行數:20,代碼來源:HTTPBuilder.java

示例11: remove

import java.util.concurrent.ConcurrentLinkedQueue; //導入依賴的package包/類
public Object remove(K key) {
	for (ConcurrentLinkedQueue<K> bucket : _buckets) {
		if (contains(key,bucket)) {
			return bucket.remove(key);
		}
	}
	return null;
}
 
開發者ID:langxianwei,項目名稱:iot-plat,代碼行數:9,代碼來源:RotatingList.java

示例12: testAddAllSelf

import java.util.concurrent.ConcurrentLinkedQueue; //導入依賴的package包/類
/**
 * addAll(this) throws IllegalArgumentException
 */
public void testAddAllSelf() {
    ConcurrentLinkedQueue q = populatedQueue(SIZE);
    try {
        q.addAll(q);
        shouldThrow();
    } catch (IllegalArgumentException success) {}
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:11,代碼來源:ConcurrentLinkedQueueTest.java

示例13: testAddAll1

import java.util.concurrent.ConcurrentLinkedQueue; //導入依賴的package包/類
/**
 * addAll(null) throws NullPointerException
 */
public void testAddAll1() {
    ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
    try {
        q.addAll(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:11,代碼來源:ConcurrentLinkedQueueTest.java

示例14: testSize

import java.util.concurrent.ConcurrentLinkedQueue; //導入依賴的package包/類
/**
 * size changes when elements added and removed
 */
public void testSize() {
    ConcurrentLinkedQueue q = populatedQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(SIZE - i, q.size());
        q.remove();
    }
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.size());
        q.add(new Integer(i));
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:ConcurrentLinkedQueueTest.java

示例15: testClear

import java.util.concurrent.ConcurrentLinkedQueue; //導入依賴的package包/類
/**
 * clear removes all elements
 */
public void testClear() {
    ConcurrentLinkedQueue q = populatedQueue(SIZE);
    q.clear();
    assertTrue(q.isEmpty());
    assertEquals(0, q.size());
    q.add(one);
    assertFalse(q.isEmpty());
    q.clear();
    assertTrue(q.isEmpty());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:ConcurrentLinkedQueueTest.java


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