Search in sources :

Example 66 with ConcurrentMap

use of java.util.concurrent.ConcurrentMap in project hibernate-orm by hibernate.

the class CorrectnessTestCase method checkForEmptyPendingPuts.

protected void checkForEmptyPendingPuts() throws Exception {
    Field pp = PutFromLoadValidator.class.getDeclaredField("pendingPuts");
    pp.setAccessible(true);
    Method getInvalidators = null;
    List<DelayedInvalidators> delayed = new LinkedList<>();
    for (int i = 0; i < sessionFactories.length; i++) {
        SessionFactoryImplementor sfi = (SessionFactoryImplementor) sessionFactories[i];
        for (Object regionName : sfi.getCache().getSecondLevelCacheRegionNames()) {
            PutFromLoadValidator validator = getPutFromLoadValidator(sfi, (String) regionName);
            if (validator == null) {
                log.warn("No validator for " + regionName);
                continue;
            }
            ConcurrentMap<Object, Object> map = (ConcurrentMap) pp.get(validator);
            for (Iterator<Map.Entry<Object, Object>> iterator = map.entrySet().iterator(); iterator.hasNext(); ) {
                Map.Entry entry = iterator.next();
                if (getInvalidators == null) {
                    getInvalidators = entry.getValue().getClass().getMethod("getInvalidators");
                    getInvalidators.setAccessible(true);
                }
                java.util.Collection invalidators = (java.util.Collection) getInvalidators.invoke(entry.getValue());
                if (invalidators != null && !invalidators.isEmpty()) {
                    delayed.add(new DelayedInvalidators(map, entry.getKey()));
                }
            }
        }
    }
    // poll until all invalidations come
    long deadline = System.currentTimeMillis() + 30000;
    while (System.currentTimeMillis() < deadline) {
        iterateInvalidators(delayed, getInvalidators, (k, i) -> {
        });
        if (delayed.isEmpty()) {
            break;
        }
        Thread.sleep(1000);
    }
    if (!delayed.isEmpty()) {
        iterateInvalidators(delayed, getInvalidators, (k, i) -> log.warnf("Left invalidators on key %s: %s", k, i));
        throw new IllegalStateException("Invalidators were not cleared: " + delayed.size());
    }
}
Also used : PutFromLoadValidator(org.hibernate.cache.infinispan.access.PutFromLoadValidator) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) ConcurrentMap(java.util.concurrent.ConcurrentMap) Method(java.lang.reflect.Method) LinkedList(java.util.LinkedList) Field(java.lang.reflect.Field) Collection(org.hibernate.mapping.Collection) Map(java.util.Map) TreeMap(java.util.TreeMap) NavigableMap(java.util.NavigableMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap)

Example 67 with ConcurrentMap

use of java.util.concurrent.ConcurrentMap in project spring-loaded by spring-projects.

the class JVMPlugin method tidySerialization.

/*  removeBeanInfo(Class<?> type) { */
private void tidySerialization(Class<?> reloadedClass) {
    //		if (true) return;
    try {
        Class<?> clazz = Class.forName("java.io.ObjectStreamClass$Caches");
        Field localDescsField = clazz.getDeclaredField("localDescs");
        localDescsField.setAccessible(true);
        ConcurrentMap cm = (ConcurrentMap) localDescsField.get(null);
        // TODO [serialization] a bit extreme to wipe out everything
        cm.clear();
    // For some reason clearing the reflectors damages serialization - is it not a true cache?
    //			Field reflectorsField = clazz.getDeclaredField("reflectors");
    //			reflectorsField.setAccessible(true);
    //			cm = (ConcurrentMap)reflectorsField.get(null);
    //			cm.clear();
    } catch (ClassNotFoundException e) {
        throw new IllegalStateException(e);
    } catch (NoSuchFieldException e) {
        throw new IllegalStateException(e);
    } catch (SecurityException e) {
        throw new IllegalStateException(e);
    } catch (IllegalArgumentException e) {
        throw new IllegalStateException(e);
    } catch (IllegalAccessException e) {
        throw new IllegalStateException(e);
    }
//		private static class Caches {
//	        /** cache mapping local classes -> descriptors */
//	        static final ConcurrentMap<WeakClassKey,Reference<?>> localDescs =
//	            new ConcurrentHashMap<>();
//
//	        /** cache mapping field group/local desc pairs -> field reflectors */
//	        static final ConcurrentMap<FieldReflectorKey,Reference<?>> reflectors =
//	            new ConcurrentHashMap<>();
//
//	        /** queue for WeakReferences to local classes */
//	        private static final ReferenceQueue<Class<?>> localDescsQueue =
//	            new ReferenceQueue<>();
//	        /** queue for WeakReferences to field reflectors keys */
//	        private static final ReferenceQueue<Class<?>> reflectorsQueue =
//	            new ReferenceQueue<>();
//	    }
}
Also used : Field(java.lang.reflect.Field) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 68 with ConcurrentMap

use of java.util.concurrent.ConcurrentMap in project fastjson by alibaba.

the class NotExistsTest method test_0.

public void test_0() throws Exception {
    Field field = TypeUtils.class.getDeclaredField("mappings");
    field.setAccessible(true);
    ConcurrentMap<String, Class<?>> mappings = (ConcurrentMap<String, Class<?>>) field.get(null);
    System.out.println(mappings.size());
    //         ParserConfig.global.setAutoTypeSupport(true);
    for (int i = 0; i < 10; ++i) {
        long start = System.currentTimeMillis();
        perf();
        long millis = System.currentTimeMillis() - start;
        System.out.println("millis : " + millis);
    }
}
Also used : Field(java.lang.reflect.Field) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 69 with ConcurrentMap

use of java.util.concurrent.ConcurrentMap in project caffeine by ben-manes.

the class ConcurrentHashMap8Test method testComputeIfAbsent2.

/**
     * computeIfAbsent does not replace if the key is already present
     */
public void testComputeIfAbsent2() {
    ConcurrentMap map = map5();
    assertEquals("A", map.computeIfAbsent(one, (x) -> "Z"));
}
Also used : NONNULL(java.util.Spliterator.NONNULL) LongAdder(java.util.concurrent.atomic.LongAdder) Arrays(java.util.Arrays) Caffeine(com.github.benmanes.caffeine.cache.Caffeine) Test(junit.framework.Test) Iterator(java.util.Iterator) Collection(java.util.Collection) Set(java.util.Set) ConcurrentMap(java.util.concurrent.ConcurrentMap) TestSuite(junit.framework.TestSuite) DISTINCT(java.util.Spliterator.DISTINCT) NoSuchElementException(java.util.NoSuchElementException) CONCURRENT(java.util.Spliterator.CONCURRENT) Collections(java.util.Collections) Spliterator(java.util.Spliterator) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 70 with ConcurrentMap

use of java.util.concurrent.ConcurrentMap in project caffeine by ben-manes.

the class ConcurrentHashMap8Test method testComputeIfPresent.

/**
     * computeIfPresent does not replace if the key is already present
     */
public void testComputeIfPresent() {
    ConcurrentMap map = map5();
    map.computeIfPresent(six, (x, y) -> "Z");
    assertFalse(map.containsKey(six));
}
Also used : ConcurrentMap(java.util.concurrent.ConcurrentMap)

Aggregations

ConcurrentMap (java.util.concurrent.ConcurrentMap)218 Map (java.util.Map)53 Test (org.junit.Test)47 HashMap (java.util.HashMap)31 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)28 ArrayList (java.util.ArrayList)26 Set (java.util.Set)20 URL (com.alibaba.dubbo.common.URL)17 Iterator (java.util.Iterator)11 IOException (java.io.IOException)10 Collection (java.util.Collection)10 Arrays (java.util.Arrays)9 Collections (java.util.Collections)8 HashSet (java.util.HashSet)7 List (java.util.List)7 AtomicLong (java.util.concurrent.atomic.AtomicLong)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 LongAdder (java.util.concurrent.atomic.LongAdder)6 Caffeine (com.github.benmanes.caffeine.cache.Caffeine)5