当前位置: 首页>>代码示例>>Java>>正文


Java ReferenceQueue类代码示例

本文整理汇总了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;
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:21,代码来源:FinalizableReferenceQueue.java

示例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();
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:24,代码来源:MapMakerInternalMap.java

示例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);
}
 
开发者ID:sean417,项目名称:LearningOfThinkInJava,代码行数:24,代码来源:SoftRefQ.java

示例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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:Engine.java

示例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();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:ActiveResources.java

示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:DefaultStyledDocument.java

示例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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:ObjectStreamClass.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:PositionRef.java

示例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();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:14,代码来源:ObjectStreamClass.java

示例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();
        }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:39,代码来源:SubclassGC.java

示例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);
}
 
开发者ID:retrostreams,项目名称:android-retrostreams,代码行数:9,代码来源:ForkJoinTask.java

示例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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:9,代码来源:WeakCache.java

示例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;
}
 
开发者ID:devefx,项目名称:validator-web,代码行数:10,代码来源:ConcurrentReferenceHashMap.java

示例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);
  }
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:15,代码来源:FinalizableReferenceQueue.java

示例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
    }
}
 
开发者ID:JuanJoseFJ,项目名称:ProyectoPacientes,代码行数:10,代码来源:NonRegisteringDriver.java


注:本文中的java.lang.ref.ReferenceQueue类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。