當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。