Package java.util.concurrent.atomic

Examples of java.util.concurrent.atomic.AtomicLong


        Collection<Thread> processingThreads = new LinkedList<Thread>();

        final AtomicInteger count = new AtomicInteger(0);

        final AtomicLong curSSpaceStartTime = new AtomicLong();
        final Object calendarLock = new Object();
        final DateFormat df = new SimpleDateFormat("yyyy_MM_ww_dd_hh");

        final AtomicLong lastWriteTime = new AtomicLong();
       
        // barrier for setting up the initial time stamp based on the first
        // document processed
        final AtomicBoolean startBarrier = new AtomicBoolean(false);
View Full Code Here


    final CyclicBarrier barrier = new CyclicBarrier(20);
    ExecutorService executorService = Executors.newFixedThreadPool(20);
    ExecutorCompletionService<Void> completionService = new
      ExecutorCompletionService<Void>(executorService);
    final LogFile.Writer writer = logFileWriter;
    final AtomicLong txnId = new AtomicLong(++transactionID);
    for (int i = 0; i < 20; i++) {
      completionService.submit(new Callable<Void>() {
        @Override
        public Void call() {
          try {
            Put put = new Put(txnId.incrementAndGet(),
              WriteOrderOracle.next(), eventIn);
            ByteBuffer bytes = TransactionEventRecord.toByteBuffer(put);
            writer.put(bytes);
            writer.commit(TransactionEventRecord.toByteBuffer(
              new Commit(txnId.get(), WriteOrderOracle.next())));
            barrier.await();
            writer.sync();
          } catch (Exception ex) {
            Throwables.propagate(ex);
          }
View Full Code Here

    this.idleTimeout = idleTimeout;
    this.onCloseCallback = onCloseCallback;
    this.onCloseCallbackPath = onCloseCallbackPath;
    this.callTimeout = callTimeout;
    this.callTimeoutPool = callTimeoutPool;
    fileExtensionCounter = new AtomicLong(clock.currentTimeMillis());

    this.retryInterval = retryInterval;
    this.maxCloseTries = maxCloseTries;
    isOpen = false;
    isUnderReplicated = false;
View Full Code Here

    private final AtomicLong value;

    CachedFSUsableSpace(File fs, long interval) {
      this.fs = fs;
      this.interval = interval;
      this.value = new AtomicLong(fs.getUsableSpace());
      this.lastRefresh = new AtomicLong(System.currentTimeMillis());
    }
View Full Code Here

    }
  }
 
  protected void sendMessages() {
    final AtomicInteger num_msgs_sent = new AtomicInteger(0); // all threads will increment this
    final AtomicLong seqno = new AtomicLong(1); // monotonically increasing seqno, to be used by all threads
    final Sender[] senders = new Sender[num_threads];
    final CyclicBarrier barrier = new CyclicBarrier(num_threads + 1);
    final byte[] payload = new byte[msg_size];

        for(int i=0; i < num_threads; i++) {
View Full Code Here

                } else if (type == BigDecimal.class) {
                    return new BigDecimal(canonicalize(value));
                } else if (type == AtomicInteger.class) {
                    return new AtomicInteger(Integer.parseInt(value));
                } else if (type == AtomicLong.class) {
                    return new AtomicLong(Long.parseLong(value));
                } else {
                    return n;
                }
            } catch (NumberFormatException e) {
                throw new ParameterConvertionFailed(value, e);
View Full Code Here

      // output tasks so that this method can wait until they're
      // all done to return.
      //
      // It's also used as a condition variable signaling on its
      // own state changes.
      final AtomicLong numExecutingOutputs = new AtomicLong(0);

      // keep going until all of the outputs have been invoked
      while (toOutput.size() > 0 && isRunning)
      {
         for (final Iterator<InstanceWrapper> iter = toOutput.iterator(); iter.hasNext();)
         {
            final InstanceWrapper wrapper = iter.next();
            boolean gotLock = false;

            gotLock = wrapper.tryLock();

            if (gotLock)
            {
               // If we've been evicted then we're on our way out
               // so don't do anything else with this.
               if (wrapper.isEvicted())
               {
                  iter.remove();
                  wrapper.releaseLock();
                  continue;
               }

               final Object instance = wrapper.getInstance(); // only called while holding the lock
               final Semaphore taskSepaphore = taskLock;

               // This task will release the wrapper's lock.
               Runnable task = new Runnable()
               {
                  @Override
                  public void run()
                  {
                     try
                     {
                        if (isRunning && !wrapper.isEvicted())
                           invokeOperation(instance, Operation.output, null);
                     }
                     finally
                     {
                        wrapper.releaseLock();

                        // this signals that we're done.
                        synchronized(numExecutingOutputs)
                        {
                           numExecutingOutputs.decrementAndGet();
                           numExecutingOutputs.notifyAll();
                        }
                        if (taskSepaphore != null) taskSepaphore.release();
                     }
                  }
               };

               synchronized(numExecutingOutputs)
               {
                  numExecutingOutputs.incrementAndGet();
               }

               if (executorService != null)
               {
                  try
                  {
                     taskSepaphore.acquire();
                     executorService.execute(task);
                  }
                  catch (RejectedExecutionException e)
                  {
                     // this may happen because of a race condition between the
                     taskSepaphore.release();
                     wrapper.releaseLock(); // we never got into the run so we need to release the lock
                  }
                  catch (InterruptedException e)
                  {
                     // this can happen while blocked in the semaphore.acquire.
                     // if we're no longer running we should just get out
                     // of here.
                     //
                     // Not releasing the taskSepaphore assumes the acquire never executed.
                     // if (since) the acquire never executed we also need to release the
                     //  wrapper lock or that Mp will never be usable again.
                     wrapper.releaseLock(); // we never got into the run so we need to release the lock
                  }
               }
               else
                  task.run();

               iter.remove();
            } // end if we got the lock
         } // end loop over every Mp
      } // end while there are still Mps that haven't had output invoked.

      // =======================================================
      // now make sure all of the running tasks have completed
      synchronized(numExecutingOutputs)
      {
         while (numExecutingOutputs.get() > 0)
         {
            try { numExecutingOutputs.wait(); }
            catch (InterruptedException e)
            {
               // if we were interupted for a shutdown then just stop
               // waiting for all of the threads to finish
               if (!isRunning)
View Full Code Here

      }

      long seq = -1;
      if (mode.isSequential())
      {
         AtomicLong cseq = parent.childSequences.get(path);
         if (cseq == null)
            parent.childSequences.put(path, cseq = new AtomicLong(0));
         seq = cseq.getAndIncrement();
      }

      String pathToUse = seq >= 0 ? (path + seq) : path;
     
      entries.put(pathToUse, new Entry(data));
View Full Code Here

     
      final AtomicBoolean latch = new AtomicBoolean(false);
      try
      {
         final int numThreads = executor.getNumThreads();
         final AtomicLong execCount = new AtomicLong(0);

         Task blockingTask = new Task(latch,execCount);
         Task nonblockingTask = new Task(null,execCount);

         // submit a limited task for every thread.
View Full Code Here

      final int maxQueued = executor.getMaxNumberOfQueuedLimitedTasks();
     
      final AtomicBoolean latch = new AtomicBoolean(false);
      try
      {
         final AtomicLong execCount = new AtomicLong(0);
         int numThreads = executor.getNumThreads();

         Task blockingTask = new Task(latch,execCount);
         Task nonblockingTask = new Task(null,execCount);
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.