Examples of AtomicInteger


Examples of java.util.concurrent.atomic.AtomicInteger

    }


    private static void start(int num_threads, int num_msgs, int segment_size) {
        final AckReceiverWindow win=new AckReceiverWindow(1, segment_size);
        final AtomicInteger counter=new AtomicInteger(num_msgs);
        final AtomicLong seqno=new AtomicLong(1);
        final AtomicInteger removed_msgs=new AtomicInteger(0);

        final CountDownLatch latch=new CountDownLatch(1);
        Adder[] adders=new Adder[num_threads];
        for(int i=0; i < adders.length; i++) {
            adders[i]=new Adder(win, latch, counter, seqno, removed_msgs);
            adders[i].start();
        }

        long start=System.currentTimeMillis();
        latch.countDown(); // starts all adders

        for(Adder adder: adders) {
            try {
                adder.join();
            }
            catch(InterruptedException e) {
                e.printStackTrace();
            }
        }

        for(int i=0; i < 50; i++) {
            if(removed_msgs.get() >= num_msgs)
                break;
            else {
                System.out.println("removed: " + removed_msgs.get());
                Util.sleep(100);
                List<Message> msgs=win.removeManyAsList(segment_size);
                if(msgs != null && !msgs.isEmpty())
                    removed_msgs.addAndGet(msgs.size());
            }
        }

        long time=System.currentTimeMillis() - start;
        double requests_sec=num_msgs / (time / 1000.0);
        System.out.println("\nTime: " + time + " ms, " + Util.format(requests_sec) + " requests / sec\n");
        System.out.println("Total removed messages: " + removed_msgs);
        assert removed_msgs.get() == num_msgs :
                "removed messages (" + removed_msgs.get() + ") != num_msgs (" + num_msgs + ")";
    }
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicInteger

        testFrequentConnections(false, 1000);
    }

    private void testFrequentConnections(boolean ssl, int count) throws Exception {
        final ServerSocket serverSocket = NetUtils.createServerSocket(PORT, ssl);
        final AtomicInteger counter = new AtomicInteger(count);
        Task serverThread = new Task() {
            public void call() {
                while (!stop) {
                    try {
                        Socket socket = serverSocket.accept();
View Full Code Here

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

Examples of java.util.concurrent.atomic.AtomicInteger

    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

Examples of java.util.concurrent.atomic.AtomicInteger

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

Examples of java.util.concurrent.atomic.AtomicInteger

        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

Examples of java.util.concurrent.atomic.AtomicInteger

    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

Examples of java.util.concurrent.atomic.AtomicInteger

        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

Examples of java.util.concurrent.atomic.AtomicInteger

      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

Examples of java.util.concurrent.atomic.AtomicInteger

    @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
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.