Package java.util.concurrent.atomic

Examples of java.util.concurrent.atomic.AtomicInteger


    }
    this.name = name;
    this.handler = handler;
    this.connectionProperties = connectionProperties;
    this.context = context;
    this.counter = new AtomicInteger();
  }
View Full Code Here


    if (name == null) {
      throw new IllegalArgumentException("Name can not be null");
    }
    this.name = name;
    this.handler = handler;
    this.counter = new AtomicInteger();
  }
View Full Code Here

        if (name == null) {
            throw new IllegalArgumentException("Name can not be null");
        }
        this.name = name;
        this.handler = handler;
        counter = new AtomicInteger();
    }
View Full Code Here

        c3.setName("C");
        c3.connect(GROUP);
        r3=new MyReceiver("C");
        c3.setReceiver(r3);

        AtomicInteger num=new AtomicInteger(1);

        for(int i=0; i < senders.length; i++) {
            senders[i]=new Sender(NUM_MSGS, num, c1, c2, c3);
        }
    }
View Full Code Here

    if (primaryKeyLength == 0) {
      startIndex = 1;
            ElementSymbol id = new ElementSymbol("rowId"); //$NON-NLS-1$
        id.setType(DataTypeManager.DefaultDataClasses.INTEGER);
        columns.add(0, id);
        rowId = new AtomicInteger();
          tree = bm.createSTree(columns, sessionID, 1);
        } else {
          this.uniqueColIndex = primaryKeyLength;
          tree = bm.createSTree(columns, sessionID, primaryKeyLength);
        }
    this.columnMap = RelationalNode.createLookupMap(columns);
    this.columns = columns;
    if (!tid.getElements().isEmpty()) {
      //not relevant for indexes
      for (int i = startIndex; i < columns.size(); i++) {
        TempMetadataID col = tid.getElements().get(i - startIndex);
        if (col.isAutoIncrement()) {
          if (this.sequences == null) {
            this.sequences = new HashMap<Integer, AtomicInteger>();
          }
          sequences.put(i, new AtomicInteger(1));
        }
        if (col.isNotNull()) {
          notNull.add(i);
        }
      }
View Full Code Here

        if (addRowId) {
          newTuple.add(rowId.getAndIncrement());
        }
        for (int i = 0; i < indexes.length; i++) {
          if (indexes[i] == -1) {
            AtomicInteger sequence = sequences.get(i);
            if (sequence != null) {
              newTuple.add(sequence.getAndIncrement());
            } else {
              newTuple.add(null);
            }
          } else {
            newTuple.add(tuple.get(indexes[i]));
View Full Code Here

      assertTrue(result.size() < 3);
    }
   
    @Test public void testFailingWork() throws Exception {
      ThreadReuseExecutor pool = new ThreadReuseExecutor("test", 5); //$NON-NLS-1$
      final AtomicInteger count = new AtomicInteger();
      pool.execute(new Work() {
        @Override
        public void run() {
          count.getAndIncrement();
          throw new RuntimeException();
        }
       
        @Override
        public void release() {
         
        }
      });
      Thread.sleep(100);
      assertEquals(1, count.get());
    }
View Full Code Here

    @Test(invocationCount=10)
    public void testConcurrentInsertions() throws BrokenBarrierException, InterruptedException {
        Sender[] senders=new Sender[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 Sender(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

    @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

    @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

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.