Examples of AtomicLong


Examples of java.util.concurrent.atomic.AtomicLong

    /*final List<FacetAccessible> list2 = new ArrayList<FacetAccessible>(numSegs);
    for (int i=0;i<numSegs;++i){
      list2.add(buildSubAccessible(fname2, i, fspec));
    }   
    */
    final AtomicLong timeCounter = new AtomicLong();
    Thread[] threads = new Thread[nThreads];
    for (int i =0;i<threads.length;++i){
      threads[i]=new Thread(new Runnable(){
       
        public void run() {
         
          for (int i=0;i<numIters;++i){
            long start = System.nanoTime();
            final CombinedFacetAccessible combined1 = new CombinedFacetAccessible(fspec, list1);
           // final CombinedFacetAccessible combined2 = new CombinedFacetAccessible(fspec, list2);
            List<BrowseFacet> facets1 = combined1.getFacets();
            //List<BrowseFacet> facets2 = combined2.getFacets();
            long end= System.nanoTime();
            timeCounter.getAndAdd(end-start);
          }
        }
       
      });
    }

//    System.out.println("press key to start load test... ");
//    {
//      BufferedReader br = new BufferedReader(new InputStreamReader(
//          System.in));
//      int ch = br.read();
//      char c = (char) ch;
//    }
    for (Thread t : threads){
      t.start();
    }
   
    for (Thread t : threads){
      t.join();
    }
   
    System.out.println("average time: "+timeCounter.get()/numIters/nThreads/1000000+" ms");
   
  }
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicLong

        for (int i = 0, n = members.size(); i < n; i++) {
          latch.countDown(); // run down latch
        }
      }
      else {
        final AtomicLong cardinality = new AtomicLong(0l);
        cardinalities.put(key, cardinality);

        for (final RepositoryConnection member : members) {
          final StoreException source = SailUtil.isDebugEnabled() ? new StoreException() : null;
          executor.execute(new Runnable() {

            public void run() {
              try {
                Resource[] contexts = context == null ? new Resource[0] : new Resource[] { context };
                long size = member.sizeMatch(subj, pred, obj, true, contexts);
                if (size > 0) {
                  cardinality.getAndAdd(size);
                }
              }
              catch (RuntimeException e) {
                if (source != null) {
                  source.initCause(e);
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicLong

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

Examples of java.util.concurrent.atomic.AtomicLong

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

Examples of java.util.concurrent.atomic.AtomicLong

            // Store the app context on which this dialog is being shown.
            // Event dispatch thread of this app context will be sleeping until
            // we wake it by any event from hideAndDisposeHandler().
            showAppContext = AppContext.getAppContext();

            AtomicLong time = new AtomicLong();
            Component predictedFocusOwner = null;
            try {
                predictedFocusOwner = getMostRecentFocusOwner();
                if (conditionalShow(predictedFocusOwner, time)) {
                    // We have two mechanisms for blocking: 1. If we're on the
                    // EventDispatchThread, start a new event pump. 2. If we're
                    // on any other thread, call wait() on the treelock.

                    modalFilter = ModalEventFilter.createFilterForDialog(this);

                    final Runnable pumpEventsForFilter = new Runnable() {
                        public void run() {
                            EventDispatchThread dispatchThread =
                                (EventDispatchThread)Thread.currentThread();
                            dispatchThread.pumpEventsForFilter(new Conditional() {
                                public boolean evaluate() {
                                    return keepBlocking && windowClosingException == null;
                                }
                            }, modalFilter);
                        }
                    };

                    // if this dialog is toolkit-modal, the filter should be added
                    // to all EDTs (for all AppContexts)
                    if (modalityType == ModalityType.TOOLKIT_MODAL) {
                        Iterator it = AppContext.getAppContexts().iterator();
                        while (it.hasNext()) {
                            AppContext appContext = (AppContext)it.next();
                            if (appContext == showAppContext) {
                                continue;
                            }
                            EventQueue eventQueue = (EventQueue)appContext.get(AppContext.EVENT_QUEUE_KEY);
                            // it may occur that EDT for appContext hasn't been started yet, so
                            // we post an empty invocation event to trigger EDT initialization
                            Runnable createEDT = new Runnable() {
                                public void run() {};
                            };
                            eventQueue.postEvent(new InvocationEvent(this, createEDT));
                            EventDispatchThread edt = eventQueue.getDispatchThread();
                            edt.addEventFilter(modalFilter);
                        }
                    }

                    modalityPushed();
                    try {
                        if (EventQueue.isDispatchThread()) {
                            /*
                             * dispose SequencedEvent we are dispatching on current
                             * AppContext, to prevent us from hang.
                             *
                             */
                            // BugId 4531693 (son@sparc.spb.su)
                            SequencedEvent currentSequencedEvent = KeyboardFocusManager.
                                getCurrentKeyboardFocusManager().getCurrentSequencedEvent();
                            if (currentSequencedEvent != null) {
                                currentSequencedEvent.dispose();
                            }

                            /*
                             * Event processing is done inside doPrivileged block so that
                             * it wouldn't matter even if user code is on the stack
                             * Fix for BugId 6300270
                             */

                             AccessController.doPrivileged(new PrivilegedAction() {
                                     public Object run() {
                                        pumpEventsForFilter.run();
                                        return null;
                                     }
                             });
                        } else {
                            synchronized (getTreeLock()) {
                                Toolkit.getEventQueue().postEvent(new PeerEvent(this,
                                                                                pumpEventsForFilter,
                                                                                PeerEvent.PRIORITY_EVENT));
                                while (keepBlocking && windowClosingException == null) {
                                    try {
                                        getTreeLock().wait();
                                    } catch (InterruptedException e) {
                                        break;
                                    }
                                }
                            }
                        }
                    } finally {
                        modalityPopped();
                    }

                    // if this dialog is toolkit-modal, its filter must be removed
                    // from all EDTs (for all AppContexts)
                    if (modalityType == ModalityType.TOOLKIT_MODAL) {
                        Iterator it = AppContext.getAppContexts().iterator();
                        while (it.hasNext()) {
                            AppContext appContext = (AppContext)it.next();
                            if (appContext == showAppContext) {
                                continue;
                            }
                            EventQueue eventQueue = (EventQueue)appContext.get(AppContext.EVENT_QUEUE_KEY);
                            EventDispatchThread edt = eventQueue.getDispatchThread();
                            edt.removeEventFilter(modalFilter);
                        }
                    }

                    if (windowClosingException != null) {
                        windowClosingException.fillInStackTrace();
                        throw windowClosingException;
                    }
                }
            } finally {
                if (predictedFocusOwner != null) {
                    // Restore normal key event dispatching
                    KeyboardFocusManager.getCurrentKeyboardFocusManager().
                        dequeueKeyEvents(time.get(), predictedFocusOwner);
                }
            }
        }
    }
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicLong

     *
     * @param seed the initial seed
     * @see   #setSeed(long)
     */
    public Random(long seed) {
        this.seed = new AtomicLong(0L);
        setSeed(seed);
    }
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicLong

     *         generator's sequence
     * @since  1.1
     */
    protected int next(int bits) {
        long oldseed, nextseed;
        AtomicLong seed = this.seed;
        do {
      oldseed = seed.get();
      nextseed = (oldseed * multiplier + addend) & mask;
        } while (!seed.compareAndSet(oldseed, nextseed));
        return (int)(nextseed >>> (48 - bits));
    }
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicLong

            seedOffset = unsafe.objectFieldOffset
                (Random.class.getDeclaredField("seed"));
  } catch (Exception ex) { throw new Error(ex); }
    }
    private void resetSeed(long seedVal) {
        unsafe.putObjectVolatile(this, seedOffset, new AtomicLong(seedVal));
    }
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicLong

        builder.uncaughtExceptionHandler;
    final ThreadFactory backingThreadFactory =
        (builder.backingThreadFactory != null)
        ? builder.backingThreadFactory
        : Executors.defaultThreadFactory();
    final AtomicLong count = (nameFormat != null) ? new AtomicLong(0) : null;
    return new ThreadFactory() {
      @Override public Thread newThread(Runnable runnable) {
        Thread thread = backingThreadFactory.newThread(runnable);
        if (nameFormat != null) {
          thread.setName(String.format(nameFormat, count.getAndIncrement()));
        }
        if (daemon != null) {
          thread.setDaemon(daemon);
        }
        if (priority != null) {
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicLong

    */
   public ScriptingListener()
   {
      queue = new LinkedList();

      notificationsReceived = new AtomicLong(0);
      notificationsProcessed = new AtomicLong(0);
      totalProcessingTime = new AtomicLong(0);
   }
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.