Package java.util.concurrent.atomic

Examples of java.util.concurrent.atomic.AtomicLong


    final List<FacetAccessible> list1 = new ArrayList<FacetAccessible>(numSegs);
    for (int i = 0; i < numSegs; ++i) {
      list1.add(buildSubAccessible(fname1, i, fspec));
    }

    final AtomicLong timeCounter = new AtomicLong();
    Thread[] threads = new Thread[nThreads];
    for (int i = 0; i < threads.length; ++i) {
      threads[i] = new Thread(new Runnable() {

        @Override
        public void run() {

          for (int i = 0; i < numIters; ++i) {
            long start = System.nanoTime();
            long end = System.nanoTime();
            timeCounter.getAndAdd(end - start);
          }
        }

      });
    }

    for (Thread t : threads) {
      t.start();
    }

    for (Thread t : threads) {
      t.join();
    }

    System.out
        .println("average time: " + timeCounter.get() / numIters / nThreads / 1000000 + " ms");

  }
View Full Code Here


    private AtomicLong sum;

    @Override
    public void prepare(TestCase tc) {
        this.count = new AtomicInteger();
        this.sum = new AtomicLong();
    }
View Full Code Here

  }

  public FileMaxSCNHandler(StaticConfig config)
  {
    _staticConfig = config;
    _flushCounter = new AtomicLong(0);
    _scn = new AtomicLong(0);
    _scnFileName = _staticConfig.getScnDir().getAbsolutePath() + File.separator + _staticConfig.getKey();
    LOG.info("creating file:" + _scnFileName);
  }
View Full Code Here

    /*
     controller初始化时需要调用该方法
     */
    public void addPath(Method api) {
        APIQPS.putIfAbsent(api, new Tuple3<AtomicLong, AtomicLong, AtomicLong>(new AtomicLong(SystemStartTime), new AtomicLong(), new AtomicLong()));
        APIAVGTIME.putIfAbsent(api, new AvgTime(new AtomicLong(SystemStartTime), new AtomicLong(), new AtomicLong(), new AtomicLong()));
        APISTATUS.putIfAbsent(api, new ConcurrentHashMap<Integer, AtomicLong>());
    }
View Full Code Here

     */
    public synchronized void statusIncrement(Method api, int status) {
        if (!enable() || api == null) return;
        ConcurrentHashMap<Integer, AtomicLong> chm = APISTATUS.get(api);
        if (!chm.containsKey(status)) {
            chm.put(status, new AtomicLong());
        }
        chm.get(status).incrementAndGet();
    }
View Full Code Here

  @Test
  public void testTimeout() throws InterruptedException,
      EventDeliveryException, InstantiationException, IllegalAccessException {
    setUp();
    Event event = EventBuilder.withBody("foo", Charsets.UTF_8);
    AtomicLong delay = new AtomicLong();
    Server server = createServer(new DelayMockAvroServer(delay));
    server.start();
    sink.start();
    Assert.assertTrue(LifecycleController.waitForOneOf(sink,
        LifecycleState.START_OR_ERROR, 5000));

    Transaction txn = channel.getTransaction();
    txn.begin();
    for (int i = 0; i < 4; i++) {
      channel.put(event);
    }
    txn.commit();
    txn.close();

    // should throw EventDeliveryException due to connect timeout
    delay.set(3000L); // because connect-timeout = 2000
    boolean threw = false;
    try {
      sink.process();
    } catch (EventDeliveryException ex) {
      logger.info("Correctly threw due to connect timeout. Exception follows.",
          ex);
      threw = true;
    }

    Assert.assertTrue("Must throw due to connect timeout", threw);

    // now, allow the connect handshake to occur
    delay.set(0);
    sink.process();

    // should throw another EventDeliveryException due to request timeout
    delay.set(4000L); // because request-timeout = 3000
    threw = false;
    try {
      sink.process();
    } catch (EventDeliveryException ex) {
      logger.info("Correctly threw due to request timeout. Exception follows.",
View Full Code Here

    Map<String, AtomicLong> counterInitMap = new HashMap<String, AtomicLong>();

    // Initialize the counters
    for (String attribute : attrs) {
      counterInitMap.put(attribute, new AtomicLong(0L));
    }

    counterMap = Collections.unmodifiableMap(counterInitMap);

    startTime = new AtomicLong(0L);
    stopTime = new AtomicLong(0L);

  }
View Full Code Here

   */
  public CountingInputStream(InputStream in)
  {
    Parameters.checkNotNull(in);
    this.in = in;
    this.counter = new AtomicLong();
  }
View Full Code Here

   */
  public CountingWriter(Writer out)
  {
    Parameters.checkNotNull(out);
    this.out = out;
    this.counter = new AtomicLong();
  }
View Full Code Here

   */
  public CountingReader(Reader reader)
  {
    Parameters.checkNotNull(reader);
    this.reader = reader;
    this.counter = new AtomicLong();
  }
View Full Code Here

TOP

Related Classes of java.util.concurrent.atomic.AtomicLong

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.