Package java.util.concurrent.atomic

Examples of java.util.concurrent.atomic.AtomicInteger


    public AtomicIntCounter() {
        this(0);
    }
   
    public AtomicIntCounter(int initValue) {
        this.value = new AtomicInteger(initValue);
    }
View Full Code Here


    public AtomicPseudoRandom() {
        this((int) System.nanoTime());
    }

    public AtomicPseudoRandom(int seed) {
        this.seed = new AtomicInteger(seed);
    }
View Full Code Here

        this._size = power2;
        this._mask = power2 - 1;

        this._cnts = new AtomicInteger[power2];
        for(int i = 0; i < power2; i++) {
            _cnts[i] = new AtomicInteger();
        }
    }
View Full Code Here

        final int power2 = HashUtils.nextPowerOfTwo(nstripe);
        this._size = power2;
        this._mask = power2 - 1;

        this._cnts = new AtomicInteger[power2];
        _cnts[0] = new AtomicInteger(initValue);
        for(int i = 1; i < power2; i++) {
            _cnts[i] = new AtomicInteger();
        }
    }
View Full Code Here

  }
   
 
  int perform(final int workers, final int loops, final int port, final Integer size) throws Exception {
   
    final AtomicInteger total = new AtomicInteger();
 

    running = 0;
    errors.clear();
   
    
    for (int i = 0; i < workers; i++) {
     
      Thread t = new Thread() {
        public void run() {
          running++;
         
          try {
            HttpClient httpClient = new HttpClient();
 
            for (int j = 0; j < loops; j++) {
              long start = System.currentTimeMillis();
              IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + port + "/"));

              long elapsed = (System.currentTimeMillis() - start);
              total.addAndGet((int) elapsed);
         
             
              Assert.assertEquals(200, response.getStatus());
              if (size != null) {
                Assert.assertEquals(size.intValue(), response.getBody().size());
              }

              //System.out.println(elapsed + " millis");
            }
           
          } catch (Exception e) {
            errors.add(e.toString());
          }

          running--;
        }
       
      };
      t.start();
    }
       
   

    do {
      QAUtil.sleep(100);
    } while (running > 0);

    return total.get();   
  }
View Full Code Here

  }

  public void testAtomicInteger()
    throws Exception
  {
    AtomicInteger seq = new AtomicInteger(47);
    assertEquals(48, seq.incrementAndGet());
  }
View Full Code Here

    if (getHashTable() != null) {
      for (Number max : getHashTable().maxIds(getShift(), getMod())) {
        ValueType code = valueOf(max);
        if (max.intValue() > minId(code).intValue()) {
          if (!seq.containsKey(code) || seq.get(code).intValue() < max.intValue()) {
            seq.put(code, new AtomicInteger(max.intValue()));
          }
        }
      }
    }
  }
View Full Code Here

  @Override
  public Number nextId(Value value) {
    ValueType code = valueOf(value);
    if (!seq.containsKey(code)) {
      seq.putIfAbsent(code, new AtomicInteger(minId(code).intValue()));
    }
    int id = seq.get(code).incrementAndGet();
    return id;
  }
View Full Code Here

       
        CHUNKSZ = (Fact[n] + NCHUNKS - 1) / NCHUNKS;
  NTASKS = (Fact[n] + CHUNKSZ - 1) / CHUNKSZ;
        maxFlips = new int[NTASKS];
        chkSums  = new int[NTASKS];
        taskId = new AtomicInteger(0);

        int nthreads = Runtime.getRuntime().availableProcessors();
        Thread[] threads = new Thread[nthreads];
        for ( int i=0; i<nthreads; ++i ) {
            threads[i] = new Thread( new fannkuchredux() );
View Full Code Here

            final SoftReference reference = get();
            return reference == null ? null : (ThreadCategoryInfo) reference.get();
        }

        public AtomicInteger getUsage (String name) {
            AtomicInteger u = usage.get(name);
            if (u != null) {
                return u;
            }

            final AtomicInteger ai = new AtomicInteger();
            final AtomicInteger prev = usage.putIfAbsent(name, ai);
            return prev == null ? ai : prev;
        }
View Full Code Here

TOP

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

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.