本文整理汇总了Java中java.lang.ref.ReferenceQueue类的典型用法代码示例。如果您正苦于以下问题:Java ReferenceQueue类的具体用法?Java ReferenceQueue怎么用?Java ReferenceQueue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ReferenceQueue类属于java.lang.ref包,在下文中一共展示了ReferenceQueue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: FinalizableReferenceQueue
import java.lang.ref.ReferenceQueue; //导入依赖的package包/类
/**
* Constructs a new queue.
*/
public FinalizableReferenceQueue() {
// We could start the finalizer lazily, but I'd rather it blow up early.
queue = new ReferenceQueue<Object>();
frqRef = new PhantomReference<Object>(this, queue);
boolean threadStarted = false;
try {
startFinalizer.invoke(null, FinalizableReference.class, queue, frqRef);
threadStarted = true;
} catch (IllegalAccessException impossible) {
throw new AssertionError(impossible); // startFinalizer() is public
} catch (Throwable t) {
logger.log(Level.INFO, "Failed to start reference finalizer thread."
+ " Reference cleanup will only occur when new references are created.", t);
}
this.threadStarted = threadStarted;
}
示例2: Segment
import java.lang.ref.ReferenceQueue; //导入依赖的package包/类
Segment(MapMakerInternalMap<K, V> map, int initialCapacity, int maxSegmentSize) {
this.map = map;
this.maxSegmentSize = maxSegmentSize;
initTable(newEntryArray(initialCapacity));
keyReferenceQueue = map.usesKeyReferences()
? new ReferenceQueue<K>() : null;
valueReferenceQueue = map.usesValueReferences()
? new ReferenceQueue<V>() : null;
recencyQueue = (map.evictsBySize() || map.expiresAfterAccess())
? new ConcurrentLinkedQueue<ReferenceEntry<K, V>>()
: MapMakerInternalMap.<ReferenceEntry<K, V>>discardingQueue();
evictionQueue = map.evictsBySize()
? new EvictionQueue<K, V>()
: MapMakerInternalMap.<ReferenceEntry<K, V>>discardingQueue();
expirationQueue = map.expires()
? new ExpirationQueue<K, V>()
: MapMakerInternalMap.<ReferenceEntry<K, V>>discardingQueue();
}
示例3: main
import java.lang.ref.ReferenceQueue; //导入依赖的package包/类
public static void main(String[] args) throws InterruptedException{
Thread t=new CheckRefQueue();
t.setDaemon(true);
t.start();
User u=new User(1,"geym");
softQueue=new ReferenceQueue<User>();
UserSoftReference userSoftRef=new UserSoftReference(u,softQueue);
u=null;
System.out.println(userSoftRef.get());
System.gc();
System.out.println("After GC:");
System.out.println(userSoftRef.get());
System.out.println("try to create byte array and GC");
byte[] b=new byte[1024*925*7];
System.gc();
System.out.println(userSoftRef.get());
Thread.sleep(1000);
}
示例4: getReferenceQueue
import java.lang.ref.ReferenceQueue; //导入依赖的package包/类
private ReferenceQueue<EngineResource<?>> getReferenceQueue() {
if (resourceReferenceQueue == null) {
resourceReferenceQueue = new ReferenceQueue<>();
MessageQueue queue = Looper.myQueue();
queue.addIdleHandler(new RefQueueIdleHandler(activeResources, resourceReferenceQueue));
}
return resourceReferenceQueue;
}
示例5: ResourceWeakReference
import java.lang.ref.ReferenceQueue; //导入依赖的package包/类
@Synthetic
@SuppressWarnings("WeakerAccess")
ResourceWeakReference(
Key key, EngineResource<?> r, ReferenceQueue<? super EngineResource<?>> q) {
super(r, q);
this.key = Preconditions.checkNotNull(key);
this.resource = Preconditions.checkNotNull(r.getResource());
isCacheable = r.isCacheable();
}
示例6: AbstractChangeHandler
import java.lang.ref.ReferenceQueue; //导入依赖的package包/类
AbstractChangeHandler(DefaultStyledDocument d) {
Class<?> c = getClass();
ReferenceQueue<DefaultStyledDocument> q;
synchronized (queueMap) {
q = queueMap.get(c);
if (q == null) {
q = new ReferenceQueue<DefaultStyledDocument>();
queueMap.put(c, q);
}
}
doc = new DocReference(d, q);
}
示例7: processQueue
import java.lang.ref.ReferenceQueue; //导入依赖的package包/类
/**
* Removes from the specified map any keys that have been enqueued
* on the specified reference queue.
*/
static void processQueue(ReferenceQueue<Class<?>> queue,
ConcurrentMap<? extends
WeakReference<Class<?>>, ?> map)
{
Reference<? extends Class<?>> ref;
while((ref = queue.poll()) != null) {
map.remove(ref);
}
}
示例8: init
import java.lang.ref.ReferenceQueue; //导入依赖的package包/类
/** Initialize the variables to the default values. */
protected void init() {
queue = new ReferenceQueue<PositionRef>();
// A stable mark used to simplify operations with the list
head = new ChainItem(null, queue, null);
}
示例9: FieldReflectorKey
import java.lang.ref.ReferenceQueue; //导入依赖的package包/类
FieldReflectorKey(Class<?> cl, ObjectStreamField[] fields,
ReferenceQueue<Class<?>> queue)
{
super(cl, queue);
nullClass = (cl == null);
StringBuilder sbuf = new StringBuilder();
for (int i = 0; i < fields.length; i++) {
ObjectStreamField f = fields[i];
sbuf.append(f.getName()).append(f.getSignature());
}
sigs = sbuf.toString();
hash = System.identityHashCode(cl) + sigs.hashCode();
}
示例10: main
import java.lang.ref.ReferenceQueue; //导入依赖的package包/类
public static final void main(String[] args) throws Exception {
System.err.println("\n Regression test for bug 6232010\n");
if (System.getSecurityManager() == null) {
System.setSecurityManager(new SecurityManager());
}
ClassLoader systemLoader = ClassLoader.getSystemClassLoader();
ClassLoader loader = new URLClassLoader(((URLClassLoader) systemLoader).getURLs(),
systemLoader.getParent());
Class<? extends ObjectOutputStream> cl =
Class.forName(SubclassOfOOS.class.getName(), false,
loader).asSubclass(ObjectOutputStream.class);
Constructor<? extends ObjectOutputStream> cons =
cl.getConstructor(OutputStream.class);
OutputStream os = new ByteArrayOutputStream();
ObjectOutputStream obj = cons.newInstance(os);
final ReferenceQueue<Class<?>> queue = new ReferenceQueue<Class<?>>();
WeakReference<Class<?>> ref = new WeakReference<Class<?>>(cl, queue);
cl = null;
obj = null;
loader = null;
cons = null;
systemLoader = null;
System.err.println("\nStart Garbage Collection right now");
System.gc();
Reference<? extends Class<?>> dequeued = queue.remove(TIMEOUT);
if (dequeued == ref) {
System.err.println("\nTEST PASSED");
} else {
throw new Error();
}
}
示例11: ExceptionNode
import java.lang.ref.ReferenceQueue; //导入依赖的package包/类
ExceptionNode(ForkJoinTask<?> task, Throwable ex, ExceptionNode next,
ReferenceQueue<ForkJoinTask<?>> exceptionTableRefQueue) {
super(task, exceptionTableRefQueue);
this.ex = ex;
this.next = next;
this.thrower = Thread.currentThread().getId();
this.hashCode = System.identityHashCode(task);
}
示例12: valueOf
import java.lang.ref.ReferenceQueue; //导入依赖的package包/类
static <K> Object valueOf(K key, ReferenceQueue<K> refQueue) {
return key == null
// null key means we can't weakly reference it,
// so we use a NULL_KEY singleton as cache key
? NULL_KEY
// non-null key requires wrapping with a WeakReference
: new CacheKey<>(key, refQueue);
}
示例13: newValueReference
import java.lang.ref.ReferenceQueue; //导入依赖的package包/类
final Object newValueReference(V value, ReferenceType valueType,
ReferenceQueue<Object> refQueue) {
if (valueType == ReferenceType.WEAK)
return new WeakValueReference<V>(value, keyRef, hash, refQueue);
if (valueType == ReferenceType.SOFT)
return new SoftValueReference<V>(value, keyRef, hash, refQueue);
return value;
}
示例14: getStartFinalizer
import java.lang.ref.ReferenceQueue; //导入依赖的package包/类
/**
* Looks up Finalizer.startFinalizer().
*/
static Method getStartFinalizer(Class<?> finalizer) {
try {
return finalizer.getMethod(
"startFinalizer",
Class.class,
ReferenceQueue.class,
PhantomReference.class);
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
}
}
示例15: ConnectionPhantomReference
import java.lang.ref.ReferenceQueue; //导入依赖的package包/类
ConnectionPhantomReference(ConnectionImpl connectionImpl, ReferenceQueue<ConnectionImpl> q) {
super(connectionImpl, q);
try {
this.io = connectionImpl.getIO().getNetworkResources();
} catch (SQLException e) {
// if we somehow got here and there's really no i/o, we deal with it later
}
}