Examples of AtomicInteger


Examples of java.util.concurrent.atomic.AtomicInteger

    @Test(invocationCount=5)
    public void testConcurrentRandomInsertions() throws BrokenBarrierException, InterruptedException {
        Sender[] senders=new RandomSender[NUM_THREADS];
        ConcurrentMap<Long,AtomicInteger> successful_adds=new ConcurrentHashMap<Long,AtomicInteger>();
        for(int i=1; i <= NUM_MSGS; i++)
            successful_adds.put((long)i, new AtomicInteger(0));

        for(int i=0; i < senders.length; i++) {
            senders[i]=new RandomSender(NUM_MSGS, win, sender, barrier, successful_adds);
            senders[i].start();
        }

        Util.sleep(2000);
        System.out.println("Concurrently inserting " + NUM_MSGS + " messages with " + NUM_THREADS + " threads");
        barrier.await();

        for(int i=0; i < senders.length; i++)
            senders[i].join(20000);
        System.out.println("OK: " + NUM_MSGS + " were added to the NakReceiverWindow concurrently by " + NUM_THREADS + " threads");

        Set<Long> keys=successful_adds.keySet();

        System.out.println("checking for missing or duplicate seqnos in " + keys.size() + " seqnos:");
        for(int i=1; i <= NUM_MSGS; i++) {
            AtomicInteger val=successful_adds.get((long)i);
            if(val.get() != 1)
                System.err.println(i + " was not added exactly once (successful insertions=" + val.get() + ")");
        }
        for(int i=1; i <= NUM_MSGS; i++) {
            AtomicInteger val=successful_adds.get((long)i);
            assert val != null : i + " is missing in " + successful_adds.keySet();
            assert val.get() == 1 : i + " was not added exactly once (successful insertions=" + val.get() + ")";
        }

        System.out.println("OK: " + keys.size() + " seqnos were added exactly once");
    }
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicInteger

    @Test(invocationCount=5)
    public void testConcurrentInsertionOfSameSeqno() throws BrokenBarrierException, InterruptedException {
        Sender[] senders=new SameSeqnoSender[NUM_THREADS];
        ConcurrentMap<Long,AtomicInteger> successful_adds=new ConcurrentHashMap<Long,AtomicInteger>();
        for(int i=1; i <= NUM_MSGS; i++)
            successful_adds.put((long)i, new AtomicInteger(0));

        for(int i=0; i < senders.length; i++) {
            senders[i]=new SameSeqnoSender(NUM_MSGS, win, sender, barrier, successful_adds);
            senders[i].start();
        }

        Util.sleep(2000);
        System.out.println("Concurrently inserting 1 message with " + NUM_THREADS + " threads");
        barrier.await();

        for(int i=0; i < senders.length; i++)
            senders[i].join(20000);
        System.out.println("OK: 1 message was added to the NakReceiverWindow concurrently by " + NUM_THREADS + " threads");

        Set<Long> keys=successful_adds.keySet();

        System.out.println("checking for missing or duplicate seqnos in " + keys.size() + " seqnos:");
        AtomicInteger val=successful_adds.get(1L);
        if(val.get() != 1)
            System.err.println("1 was not added exactly once (successful insertions=" + val.get() + ")");
        assert val.get() == 1 : "1 was not added exactly once (successful insertions=" + val.get() + ")";

        System.out.println("OK: 1 seqno was added exactly once");
    }
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicInteger

            Message msg=new Message(null, sender, "hello");
            msg.putHeader(NAKACK_ID, hdr);
            boolean added=win.add(seqno, msg);

            if(added) {
                AtomicInteger val=map.get((long)seqno);
                val.incrementAndGet();
            }
        }
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicInteger

   * @param clientConn ClientConnection
   */
  public void clearAll(){
    this.localCache.clear();
    this.distributedCache.clear();
    this.totalRequests = new AtomicInteger();
    this.cacheHit = new AtomicInteger();
 
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicInteger

        stat.execute("set exclusive false");
        Connection conn2 = getConnection("exclusive");
        final Statement stat2 = conn2.createStatement();
        stat.execute("set exclusive true");
        final AtomicInteger state = new AtomicInteger(0);
        Task task = new Task() {
            public void call() throws SQLException {
                stat2.execute("select * from dual");
                if (state.get() != 1) {
                    new Error("unexpected state: " + state.get()).printStackTrace();
                }
            }
        };
        task.execute();
        state.set(1);
        stat.execute("set exclusive false");
        task.get();
        stat.execute("set exclusive true");
        conn.close();

View Full Code Here

Examples of java.util.concurrent.atomic.AtomicInteger

     */
    private TaskEngine() {
        timer = new Timer("timer-whack", true);
        executor = Executors.newCachedThreadPool(new ThreadFactory() {

            final AtomicInteger threadNumber = new AtomicInteger(1);

            public Thread newThread(Runnable runnable) {
                // Use our own naming scheme for the threads.
                Thread thread = new Thread(Thread.currentThread().getThreadGroup(), runnable,
                                      "pool-whack" + threadNumber.getAndIncrement(), 0);
                // Make workers daemon threads.
                thread.setDaemon(true);
                if (thread.getPriority() != Thread.NORM_PRIORITY) {
                    thread.setPriority(Thread.NORM_PRIORITY);
                }
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicInteger

   {
      Converter converter = new AtomicIntegerConverter();
      assertEquals("", converter.getAsString(null, null, null));
      assertEquals("", converter.getAsString(null, null, ""));
      assertEquals(" ", converter.getAsString(null, null, " "));
      assertEquals("-1", converter.getAsString(null, null, new AtomicInteger(-1)));
      try
      {
         converter.getAsString(null, null, new Integer(0));
         fail("should only take atomic ints");
      }
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicInteger

        }
        int actualCapacity = HashUtils.nextPowerOfTwo(capacity);
        this._capacity = actualCapacity;
        this._capacityMask = actualCapacity - 1;
        this._array = new VolatileArray<NbGClockCacheEntry<K, V>>(actualCapacity);
        this._free = new AtomicInteger(actualCapacity);
        this._clockHand = CounterProvider.createIntCounter();
    }
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicInteger

    public BoundedTransferQueue(int capacity) {
        if(capacity < 1) {
            throw new IllegalArgumentException();
        }
        this._maxCapacity = capacity;
        this._remainingCapacity = new AtomicInteger(capacity);
        this._queue = new LinkedTransferQueue<E>();
    }
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicInteger

    private final AtomicInteger _used, _free; // as barriers

    public ConcurrentBoundedQueue(int capacity) {
        this._capacity = capacity;
        this._array = new AtomicReferenceArray<E>(capacity);
        this._readPtr = new AtomicInteger(0);
        this._writePtr = new AtomicInteger(0);
        this._used = new AtomicInteger(0);
        this._free = new AtomicInteger(capacity);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.