Package java.util.concurrent

Examples of java.util.concurrent.CopyOnWriteArraySet


        final List permanentObjects = new ArrayList();
        // a set of objects that will be added and removed at random to the test set to force rehashing
        final List volatileObjects = new ArrayList();
        permanentObjects.addAll(createWithRandomIntegers(80, null));
        volatileObjects.addAll(createWithRandomIntegers(10000, permanentObjects));
        final CopyOnWriteArraySet missing = new CopyOnWriteArraySet();
        final int mutatorThreshold = 1000;

        // Add elements that will not be touched by the constantly running mutating thread
        for (Object permanent : permanentObjects) {
            testSet.add(permanent);
        }

        // Adds and removes items
        // thus forcing constant rehashing of the backing hashtable
        Runnable rehasher = new Runnable() {
            public void run() {
                Random rand = new Random();
                for(int times = 0; times < 1000 ; times++){
                    HashSet elements = new HashSet(mutatorThreshold);

                    for (int i = 0; i < mutatorThreshold; i++) {
                        Object volatileObject = volatileObjects.get(Math.abs(rand.nextInt()) % volatileObjects.size());
                        testSet.add(volatileObject);
                        elements.add(volatileObject);
                    }
                    for (Object volObj : elements) {
                        testSet.remove(volObj);
                    }
                }
            };
        };

        Runnable lookup = new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 10000; i++) {
                    for (Object permanent : permanentObjects) {
                        // permanent items are never touched,
                        // --> set.contains(j) should always return true
                        if(!testSet.contains(permanent))
                            missing.add(permanent);
                    }
                }
            }
        };

        ConcurrentExecutor.runConcurrent(rehasher, lookup, lookup, lookup);
        assertTrue("There where items temporarily unavailable: " + missing.size(), missing.size() == 0);

    }
View Full Code Here


   public void addPerInstanceJoinpointAspect(Joinpoint joinpoint, AspectDefinition def)
   {
      Set joinpoints = (Set) perInstanceJoinpointAspectDefinitions.get(def);
      if (joinpoints == null)
      {
         joinpoints = new CopyOnWriteArraySet();
         initPerInstanceJoinpointAspectDefinitionsMap();
         perInstanceJoinpointAspectDefinitions.put(def, joinpoints);
         def.registerAdvisor(this);
      }
      joinpoints.add(joinpoint);
View Full Code Here

   {
      initPerInstanceJoinpointAspectDefinitionsMap();
      Set setJoinpoints = (Set) perInstanceJoinpointAspectDefinitions.get(def);
      if (setJoinpoints == null)
      {
         setJoinpoints = new CopyOnWriteArraySet();
         perInstanceJoinpointAspectDefinitions.put(def, setJoinpoints);
         def.registerAdvisor(this);
      }
      setJoinpoints.addAll(joinpoints);
   }
View Full Code Here

         lockWrite();
         try
         {
            if (perInstanceAspectDefinitions == UnmodifiableEmptyCollections.EMPTY_COPYONWRITE_ARRAYSET)
            {
               perInstanceAspectDefinitions = new CopyOnWriteArraySet();
            }
         }
         finally
         {
            unlockWrite();
View Full Code Here

/* 107 */       this.resourceCache = new ConcurrentHashMap();
/*     */     }
/*     */
/* 110 */     if (canBlackList)
/*     */     {
/* 112 */       this.classBlackList = new CopyOnWriteArraySet();
/* 113 */       this.resourceBlackList = new CopyOnWriteArraySet();
/*     */     }
/*     */   }
View Full Code Here

/*     */
/*  97 */     if (basePolicy.isCachable()) {
/*  98 */       this.resourceCache = new ConcurrentHashMap();
/*     */     }
/* 100 */     if (basePolicy.isBlackListable()) {
/* 101 */       this.blackList = new CopyOnWriteArraySet();
/*     */     }
/* 103 */     log.debug("Created " + this + " with policy " + policy.toLongString());
/*     */   }
View Full Code Here

/*  200 */         if (index == -1)
/*  201 */           throw new IllegalStateException(before + " is not a state in the controller.");
/*  202 */         this.states.add(index, state);
/*      */       }
/*      */
/*  205 */       Set contexts = new CopyOnWriteArraySet();
/*  206 */       this.contextsByState.put(state, contexts);
/*      */     }
/*      */     finally
/*      */     {
/*  210 */       unlockWrite();
View Full Code Here

/*  97 */     return new CopyOnWriteArrayList();
/*     */   }
/*     */
/*     */   public static final <T> Set<T> createCopyOnWriteSet()
/*     */   {
/* 108 */     return new CopyOnWriteArraySet();
/*     */   }
View Full Code Here

/*      */   public void addPerInstanceJoinpointAspect(Joinpoint joinpoint, AspectDefinition def)
/*      */   {
/*  781 */     Set joinpoints = (Set)this.perInstanceJoinpointAspectDefinitions.get(def);
/*  782 */     if (joinpoints == null)
/*      */     {
/*  784 */       joinpoints = new CopyOnWriteArraySet();
/*  785 */       initPerInstanceJoinpointAspectDefinitionsMap();
/*  786 */       this.perInstanceJoinpointAspectDefinitions.put(def, joinpoints);
/*  787 */       def.registerAdvisor(this);
/*      */     }
/*  789 */     joinpoints.add(joinpoint);
View Full Code Here

/*      */   {
/*  794 */     initPerInstanceJoinpointAspectDefinitionsMap();
/*  795 */     Set setJoinpoints = (Set)this.perInstanceJoinpointAspectDefinitions.get(def);
/*  796 */     if (setJoinpoints == null)
/*      */     {
/*  798 */       setJoinpoints = new CopyOnWriteArraySet();
/*  799 */       this.perInstanceJoinpointAspectDefinitions.put(def, setJoinpoints);
/*  800 */       def.registerAdvisor(this);
/*      */     }
/*  802 */     setJoinpoints.addAll(joinpoints);
/*      */   }
View Full Code Here

TOP

Related Classes of java.util.concurrent.CopyOnWriteArraySet

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.