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());
}
}
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<>();
// }
}
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);
}
}
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"));
}
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));
}
Aggregations