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


Java ConcurrentLinkedQueue.size方法代码示例

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


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

示例1: longIdleHeartBeat

import java.util.concurrent.ConcurrentLinkedQueue; //导入方法依赖的package包/类
/**
 * check if the connection is not be used for a while & do connection heart beat
 *
 * @param linkedQueue
 * @param hearBeatTime
 */
private void longIdleHeartBeat(ConcurrentLinkedQueue<BackendConnection> linkedQueue, long hearBeatTime) {
    long length = linkedQueue.size();
    for (int i = 0; i < length; i++) {
        BackendConnection con = linkedQueue.poll();
        if (con.isClosedOrQuit()) {
            continue;
        } else if (con.getLastTime() < hearBeatTime) { //if the connection is idle for a long time
            con.setBorrowed(true);
            new ConnectionHeartBeatHandler().doHeartBeat(con);
        } else {
            linkedQueue.offer(con);
            break;
        }
    }
}
 
开发者ID:actiontech,项目名称:dble,代码行数:22,代码来源:PhysicalDatasource.java

示例2: getGeographicCenter

import java.util.concurrent.ConcurrentLinkedQueue; //导入方法依赖的package包/类
/**
 * Calculate the average geometric center of a Queue that contains cartesian coordinates
 * Reference: http://stackoverflow.com/questions/6671183/calculate-the-center-point-of-multiple-latitude-longitude-coordinate-pairs
 * Reference: http://stackoverflow.com/questions/1185408/converting-from-longitude-latitude-to-cartesian-coordinates
 * Reference: http://en.wikipedia.org/wiki/Spherical_coordinate_system
 * @param queue The location buffer queue
 * @return Returns a Coordinate object
 */
public static Coordinate getGeographicCenter(final ConcurrentLinkedQueue<Coordinate> queue){
    double x = 0;
    double y = 0;
    double z = 0;
    float accuracy = 0;

    for(final Coordinate coordinate : queue){
        accuracy += coordinate.accuracy;

        // Convert latitude and longitude to radians
        final double latRad = Math.PI * coordinate.latitude / 180;
        final double lonRad = Math.PI * coordinate.longitude / 180;

        // Convert to cartesian coords
        x += _radiusKM * Math.cos(latRad) * Math.cos(lonRad);
        y += _radiusKM * Math.cos(latRad) * Math.sin(lonRad);
        z += _radiusKM * Math.sin(latRad);
    }

    // Get our averages
    final double xAvg = x / queue.size();
    final double yAvg = y / queue.size();
    final double zAvg = z / queue.size();
    final float accuracyAvg = accuracy / queue.size();

    // Convert cartesian back to radians
    final double sphericalLatRads = Math.asin(zAvg / _radiusKM);
    final double sphericalLonRads = Math.atan2(yAvg, xAvg);

    final Coordinate centerPoint = new Coordinate();
    centerPoint.latitude = sphericalLatRads * (180 / Math.PI);
    centerPoint.longitude = sphericalLonRads * (180 / Math.PI);
    centerPoint.accuracy = accuracyAvg;

    return centerPoint;
}
 
开发者ID:SUTFutureCoder,项目名称:localcloud_fe,代码行数:45,代码来源:GeodataHelper.java

示例3: parallelCheckpoint

import java.util.concurrent.ConcurrentLinkedQueue; //导入方法依赖的package包/类
/** This shows that checkpointing is consistent when callbacks are on different threads. */
@Test
public void parallelCheckpoint() throws Exception {
  int spansPerEvent = 3;

  // We checkpoint at or over the checkpoint batch size. By default, our batch size is
  // 10, so if we have 3 spans per event, we checkpoint on the 3rd event (span count 12 not 10).
  int eventsPerCheckpoint = processor.checkpointBatchSize / spansPerEvent;
  if (processor.checkpointBatchSize % spansPerEvent > 0) eventsPerCheckpoint++;

  // make a lot of events to ensure concurrency works.
  int eventCount = 1000;
  final ConcurrentLinkedQueue<EventData> events = new ConcurrentLinkedQueue<>();
  for (int i = 0; i < eventCount; i++) {
    events.add(jsonMessageWithThreeSpans(Integer.toHexString(i + 1), 1 + i));
  }

  // We currently don't know if onEvents is always called from the same thread or not.
  //
  // To test logic is consistent, we fire up 10 threads who will pull events of the queue and
  // invoke onEvents with that event. This will happen concurrently and out-of-order.
  // If we don't end up with an exact number of checkpoints, we might have a concurrency bug.
  CountDownLatch latch = new CountDownLatch(events.size());
  int threadCount = 10;
  ExecutorService exec = Executors.newFixedThreadPool(threadCount);
  for (int i = 0; i < threadCount; i++) {
    exec.execute(() -> {
      EventData event;
      while ((event = events.poll()) != null) {
        try {
          processor.onEvents(context, asList(event));
        } catch (Exception e) {
          e.printStackTrace();
        }
        latch.countDown();
      }
    });
  }

  //latch.await();

  exec.shutdown();
  exec.awaitTermination(1, TimeUnit.SECONDS);

  assertThat(processor.countSinceCheckpoint)
      .isZero();
  assertThat(checkpointEvents)
      .hasSize(eventCount / eventsPerCheckpoint);
}
 
开发者ID:openzipkin,项目名称:zipkin-azure,代码行数:50,代码来源:ZipkinEventProcessorTest.java

示例4: requestCount

import java.util.concurrent.ConcurrentLinkedQueue; //导入方法依赖的package包/类
public int requestCount(Node node) {
    ConcurrentLinkedQueue<ClientRequest> requests = unsent.get(node);
    return requests == null ? 0 : requests.size();
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:5,代码来源:ConsumerNetworkClient.java


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