use of java.lang.ref.Reference in project openj9 by eclipse.
the class Test_ReferenceQueue method test_remove2.
/**
* @tests java.lang.ref.ReferenceQueue#remove(long)
*/
@Test
public void test_remove2() {
// no matter what x is.
try {
AssertJUnit.assertTrue("Queue is empty.", rq.poll() == null);
AssertJUnit.assertTrue("Queue is empty.", rq.remove((long) 1) == null);
Thread ct = Support_ExtendedTestEnvironment.getInstance().getThread(new ChildThread());
ct.start();
// Thread.currentThread().sleep(100);
Reference ret = rq.remove(0L);
AssertJUnit.assertTrue("Delayed remove failed.", ret != null);
// assertTrue("Delayed remove failed.", ((Integer)rq.remove(1L).get()).intValue()==667);
} catch (InterruptedException e) {
AssertJUnit.assertTrue("InterruptedExeException during test.", false);
} catch (Exception e) {
e.printStackTrace();
AssertJUnit.assertTrue("Exception during test" + e.toString(), false);
}
}
use of java.lang.ref.Reference in project KeePassDX by Kunzisoft.
the class AbstractReferenceMap method purge.
/**
* Purges stale mappings from this map.
* <p>
* Note that this method is not synchronized! Special
* care must be taken if, for instance, you want stale
* mappings to be removed on a periodic basis by some
* background thread.
*/
protected void purge() {
Reference ref = queue.poll();
while (ref != null) {
purge(ref);
ref = queue.poll();
}
}
use of java.lang.ref.Reference in project egit by eclipse.
the class RepositoryCache method prune.
private void prune() {
List<File> toRemove = new ArrayList<>();
synchronized (repositoryCache) {
for (Iterator<Map.Entry<File, Reference<Repository>>> i = repositoryCache.entrySet().iterator(); i.hasNext(); ) {
Map.Entry<File, Reference<Repository>> entry = i.next();
Repository repository = entry.getValue().get();
if (repository == null || !repository.getDirectory().exists()) {
i.remove();
toRemove.add(entry.getKey());
}
}
}
IndexDiffCache cache = Activator.getDefault().getIndexDiffCache();
if (cache != null) {
for (File f : toRemove) {
cache.remove(f);
}
}
}
use of java.lang.ref.Reference in project spring-loaded by spring-projects.
the class JVMPlugin method clearThreadGroupContext.
private boolean clearThreadGroupContext(Class<?> clazz) {
boolean beanInfoCacheCleared = false;
try {
if (threadGroupContextClass == null) {
threadGroupContextClass = Class.forName("java.beans.ThreadGroupContext", true, Introspector.class.getClassLoader());
}
if (threadGroupContextClass != null) {
if (threadGroupContext_contextsField == null) {
threadGroupContext_contextsField = threadGroupContextClass.getDeclaredField("contexts");
threadGroupContext_removeBeanInfoMethod = threadGroupContextClass.getDeclaredMethod("removeBeanInfo", Class.class);
}
if (threadGroupContext_contextsField != null) {
threadGroupContext_contextsField.setAccessible(true);
Object threadGroupContext_contextsField_value = threadGroupContext_contextsField.get(null);
if (threadGroupContext_contextsField_value == null) {
beanInfoCacheCleared = true;
} else {
if (threadGroupContext_contextsField_value instanceof Map) {
// Indicates Java 7 up to rev21
Map<?, ?> m = (Map<?, ?>) threadGroupContext_contextsField_value;
Collection<?> threadGroupContexts = m.values();
for (Object o : threadGroupContexts) {
threadGroupContext_removeBeanInfoMethod.setAccessible(true);
threadGroupContext_removeBeanInfoMethod.invoke(o, clazz);
}
beanInfoCacheCleared = true;
} else {
// At update Java7u21 it changes
Class weakIdentityMapClazz = threadGroupContext_contextsField.getType();
Field tableField = weakIdentityMapClazz.getDeclaredField("table");
tableField.setAccessible(true);
Reference<?>[] refs = (Reference[]) tableField.get(threadGroupContext_contextsField_value);
Field valueField = null;
if (refs != null) {
for (int i = 0; i < refs.length; i++) {
Reference<?> r = refs[i];
Object o = (r == null ? null : r.get());
if (o != null) {
if (valueField == null) {
valueField = r.getClass().getDeclaredField("value");
}
valueField.setAccessible(true);
Object threadGroupContext = valueField.get(r);
threadGroupContext_removeBeanInfoMethod.setAccessible(true);
threadGroupContext_removeBeanInfoMethod.invoke(threadGroupContext, clazz);
}
}
}
beanInfoCacheCleared = true;
}
}
}
}
} catch (Throwable t) {
System.err.println("Unexpected problem clearing ThreadGroupContext beaninfo: ");
t.printStackTrace();
}
return beanInfoCacheCleared;
}
Aggregations