java类java.util.concurrent.ConcurrentLinkedQueue的实例源码

CachedThreadScheduler.java 文件源码 项目:boohee_v5.6 阅读 49 收藏 0 点赞 0 评论 0
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;
}
YamlCollectionCreator.java 文件源码 项目:diorite-configs-java8 阅读 45 收藏 0 点赞 0 评论 0
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<>());
}
ObjectDiffCalculator.java 文件源码 项目:object-diff 阅读 39 收藏 0 点赞 0 评论 0
@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;
}
ImapClient.java 文件源码 项目:NioImapClient 阅读 41 收藏 0 点赞 0 评论 0
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();
}
RemovePollRace.java 文件源码 项目:jdk8u-jdk 阅读 46 收藏 0 点赞 0 评论 0
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;
}
CorpusReader.java 文件源码 项目:information-retrieval 阅读 45 收藏 0 点赞 0 评论 0
/**
 * 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
}
RemovePollRace.java 文件源码 项目:openjdk-jdk10 阅读 33 收藏 0 点赞 0 评论 0
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;
}
MessageSystem.java 文件源码 项目:otus_java_2017_06 阅读 30 收藏 0 点赞 0 评论 0
@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();
    }
}
PerfInserterBase.java 文件源码 项目:ditb 阅读 44 收藏 0 点赞 0 评论 0
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;
}
HTTPBuilder.java 文件源码 项目:onedatashare 阅读 33 收藏 0 点赞 0 评论 0
/** 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());
  }
}
RotatingList.java 文件源码 项目:iot-plat 阅读 45 收藏 0 点赞 0 评论 0
public Object remove(K key) {
    for (ConcurrentLinkedQueue<K> bucket : _buckets) {
        if (contains(key,bucket)) {
            return bucket.remove(key);
        }
    }
    return null;
}
ConcurrentLinkedQueueTest.java 文件源码 项目:openjdk-jdk10 阅读 42 收藏 0 点赞 0 评论 0
/**
 * addAll(this) throws IllegalArgumentException
 */
public void testAddAllSelf() {
    ConcurrentLinkedQueue q = populatedQueue(SIZE);
    try {
        q.addAll(q);
        shouldThrow();
    } catch (IllegalArgumentException success) {}
}
ConcurrentLinkedQueueTest.java 文件源码 项目:openjdk-jdk10 阅读 49 收藏 0 点赞 0 评论 0
/**
 * addAll(null) throws NullPointerException
 */
public void testAddAll1() {
    ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
    try {
        q.addAll(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
ConcurrentLinkedQueueTest.java 文件源码 项目:openjdk-jdk10 阅读 35 收藏 0 点赞 0 评论 0
/**
 * 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));
    }
}
ConcurrentLinkedQueueTest.java 文件源码 项目:openjdk-jdk10 阅读 30 收藏 0 点赞 0 评论 0
/**
 * 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());
}
ConcurrentLinkedQueueTest.java 文件源码 项目:openjdk-jdk10 阅读 41 收藏 0 点赞 0 评论 0
/**
 * Initializing from Collection with some null elements throws NPE
 */
public void testConstructor5() {
    Integer[] ints = new Integer[SIZE];
    for (int i = 0; i < SIZE - 1; ++i)
        ints[i] = new Integer(i);
    try {
        new ConcurrentLinkedQueue(Arrays.asList(ints));
        shouldThrow();
    } catch (NullPointerException success) {}
}
SeqObserverQueue.java 文件源码 项目:UDOOBluLib-android 阅读 44 收藏 0 点赞 0 评论 0
private void init(BlockingQueue<Callable> tBlockingQeque, int wait){
    tBlockingDeque = tBlockingQeque;
    mExecutorService = Executors.newSingleThreadExecutor();
    mBusy = new AtomicBoolean(false);
    observers = new ConcurrentLinkedQueue<>();
    changed = false;
    mWAIT = wait;
}
ConcurrentMessageDigest.java 文件源码 项目:apache-tomcat-7.0.73-with-comment 阅读 30 收藏 0 点赞 0 评论 0
/**
 * Ensures that {@link #digest(String, byte[][])} will support the specified
 * algorithm. This method <b>must</b> be called and return successfully
 * before using {@link #digest(String, byte[][])}.
 *
 * @param algorithm The message digest algorithm to be supported
 *
 * @throws NoSuchAlgorithmException If the algorithm is not supported by the
 *                                  JVM
 */
public static void init(String algorithm) throws NoSuchAlgorithmException {
    synchronized (queues) {
        if (!queues.containsKey(algorithm)) {
            MessageDigest md = MessageDigest.getInstance(algorithm);
            Queue<MessageDigest> queue =
                    new ConcurrentLinkedQueue<MessageDigest>();
            queue.add(md);
            queues.put(algorithm, queue);
        }
    }
}
CallsTelemetry.java 文件源码 项目:SpeechToText-WebSockets-Java 阅读 44 收藏 0 点赞 0 评论 0
public void recordCall(String endpoint) {
    String now = newTimestamp();
    Queue<String> timestamps = callTimestamps.get(endpoint);
    if (timestamps == null) {
        Queue<String> newTimestamps = new ConcurrentLinkedQueue<>();
        timestamps = callTimestamps.putIfAbsent(endpoint, newTimestamps);
        if (timestamps == null) {
            timestamps = newTimestamps;
        }
    }
    timestamps.add(now);
}
RakNetServer.java 文件源码 项目:Jenisys3 阅读 45 收藏 0 点赞 0 评论 0
public RakNetServer(ThreadedLogger logger, int port, String interfaz) {
    this.port = port;
    if (port < 1 || port > 65536) {
        throw new IllegalArgumentException("Invalid port range");
    }

    this.interfaz = interfaz;
    this.logger = logger;

    this.externalQueue = new ConcurrentLinkedQueue<>();
    this.internalQueue = new ConcurrentLinkedQueue<>();

    this.start();
}
WhiteBox.java 文件源码 项目:openjdk-jdk10 阅读 64 收藏 0 点赞 0 评论 0
int nodeCount(ConcurrentLinkedQueue q) {
    int i = 0;
    for (Object p = head(q); p != null; ) {
        i++;
        if (p == (p = next(p))) p = head(q);
    }
    return i;
}
BrokerFailureDetectorTest.java 文件源码 项目:cruise-control 阅读 50 收藏 0 点赞 0 评论 0
@Test
public void testDetectorStartWithFailedBrokers() throws Exception {
  Time mockTime = getMockTime();
  Queue<Anomaly> anomalies = new ConcurrentLinkedQueue<>();
  BrokerFailureDetector detector = createBrokerFailureDetector(anomalies, mockTime);

  try {
    int brokerId = 0;
    killBroker(brokerId);
    detector.startDetection();
    assertEquals(Collections.singletonMap(brokerId, 100L), detector.failedBrokers());
  } finally {
    detector.shutdown();
  }
}
CharEffectList.java 文件源码 项目:L2J-Global 阅读 46 收藏 0 点赞 0 评论 0
/**
 * Gets triggered skill skills.
 * @return the triggered skill skills
 */
public Queue<BuffInfo> getTriggered()
{
    if (_triggered == null)
    {
        synchronized (this)
        {
            if (_triggered == null)
            {
                _triggered = new ConcurrentLinkedQueue<>();
            }
        }
    }
    return _triggered;
}
ConcurrentLinkedQueueTest.java 文件源码 项目:openjdk-jdk10 阅读 38 收藏 0 点赞 0 评论 0
/**
 * Queue contains all elements of collection used to initialize
 */
public void testConstructor6() {
    Integer[] ints = new Integer[SIZE];
    for (int i = 0; i < SIZE; ++i)
        ints[i] = new Integer(i);
    ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(Arrays.asList(ints));
    for (int i = 0; i < SIZE; ++i)
        assertEquals(ints[i], q.poll());
}
FollowerZooKeeperServer.java 文件源码 项目:ZooKeeper 阅读 47 收藏 0 点赞 0 评论 0
/**
 * @param port
 * @param dataDir
 * @throws IOException
 */
FollowerZooKeeperServer(FileTxnSnapLog logFactory,QuorumPeer self,
        DataTreeBuilder treeBuilder, ZKDatabase zkDb) throws IOException {
    super(logFactory, self.tickTime, self.minSessionTimeout,
            self.maxSessionTimeout, treeBuilder, zkDb, self);
    this.pendingSyncs = new ConcurrentLinkedQueue<Request>();
}
BluetoothConnectManager.java 文件源码 项目:AndroidMuseumBleManager 阅读 43 收藏 0 点赞 0 评论 0
public BluetoothConnectManager(Context context) {
    super(context);
    subscribeQueue = new ConcurrentLinkedQueue<BluetoothSubScribeData>();
    mBluetoothUtils = BluetoothUtils.getInstance(context);
    bluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);
    gattMap = new ConcurrentHashMap<String, BluetoothGatt>(); //会有并发的断开和连接,故而必须使用并发ConcurrentHashMap才行,否则会有ConcurrentModificationException
    connectStateListeners = new ArrayList<>();
    BleManager.getBleParamsOptions();
}
RollingIndexNameFormatterTest.java 文件源码 项目:log4j2-elasticsearch 阅读 34 收藏 0 点赞 0 评论 0
private ConcurrentLinkedQueue<TestTuple> generateLogEvents() {
    ConcurrentLinkedQueue<TestTuple> events = new ConcurrentLinkedQueue<>();

    Random random = new Random();
    for (int ii = 0; ii < 1000; ii++) {
        LogEvent logEvent = mock(LogEvent.class);

        int increment = random.nextInt(3) - 1;
        when(logEvent.getTimeMillis()).thenReturn(DEFAULT_TEST_TIME_IN_MILLIS + increment * 60000 + random.nextInt(60000));
        events.add(new TestTuple(logEvent, increment));
    }
    return events;
}
HybridWorker.java 文件源码 项目:ditb 阅读 41 收藏 0 点赞 0 评论 0
public void loadAndExecuteOperations() throws InterruptedException, IOException {
  for (int i = 0; i < threadNum; ++i) {
    threadFinishMark[i] = false;
    ConcurrentLinkedQueue<Operation> queue = new ConcurrentLinkedQueue<>();
    loaders[i] = new OperationLoader(i, reportInterval,
        DITBUtil.getDataFileName(loadDataDir, processId, i), queue);
    executors[i] = getOperationExecutor(i, reportInterval, queue, finishCounter);
    new Thread(loaders[i]).start();
    new Thread(executors[i]).start();
  }
}
OfferRemoveLoops.java 文件源码 项目:openjdk-jdk10 阅读 49 收藏 0 点赞 0 评论 0
void test(String[] args) throws Throwable {
    testQueue(new LinkedBlockingQueue(10));
    testQueue(new LinkedBlockingQueue());
    testQueue(new LinkedBlockingDeque(10));
    testQueue(new LinkedBlockingDeque());
    testQueue(new ArrayBlockingQueue(10));
    testQueue(new PriorityBlockingQueue(10));
    testQueue(new ConcurrentLinkedDeque());
    testQueue(new ConcurrentLinkedQueue());
    testQueue(new LinkedTransferQueue());
}
Parallelizer.java 文件源码 项目:mug 阅读 43 收藏 0 点赞 0 评论 0
void board(Runnable task) {
  requireNonNull(task);
  AtomicBoolean done = new AtomicBoolean();
  // Use '<:' to denote happens-before throughout this method body.
  Future<?> future = executor.submit(() -> {
    try {
      try {
        task.run();
      } finally {
        done.set(true);  // A
        onboard.remove(done);  // B
      }
    } catch (Throwable e) {
      ConcurrentLinkedQueue<Throwable> toPropagate = thrown;
      if (toPropagate == null) {
        // The main thread propagates exceptions as soon as any task fails.
        // If a task did not respond in time and yet fails afterwards, the main thread has
        // already thrown and nothing will propagate this exception.
        // So just log it as best effort.
        logger.log(Level.WARNING, "Orphan task failure", e);
      } else {
        // Upon race condition, the exception may be added while the main thread is propagating.
        // It's ok though since the best we could have done is logging.
        toPropagate.add(e);
      }
    } finally {
      semaphore.release();
    }
  });
  onboard.put(done, future);  // C
  checkInFlight();
  // A <: B, C <: D <: E
  // if B <: C => A <: C => done == true => put() <: remove()
  // if C <: B => put() <: remove()
  // remove() could be executed more than once, but it's idempotent.
  if (done.get()) {  // D
    onboard.remove(done);  // E
  }
  propagateExceptions();
}


问题


面经


文章

微信
公众号

扫码关注公众号